Skip to main content

Rocky Solver SDK 2025 R2

rocky_api_contact_functions

Last update: 16.07.2025
1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
2#pragma once
3
4#define FORCE_KERNEL_PARAMETERS \
5 IRockyContact &contact_api, IRockyContactIntermediateData &contact_idata, \
6 IRockyContactOutputData &contact_output, void *plugin_data
7#define FORCE_KERNEL_ARGUMENTS contact_api, contact_idata, contact_output, plugin_data
8
9#define CAMEL_CASE_compute_normal_force fpfComputeNormalForce
10#define CAMEL_CASE_compute_tangential_force fpfComputeTangentialForce
11#define CAMEL_CASE_compute_impact_energy fpfComputeImpactEnergy
12#define CAMEL_CASE_compute_rolling_resistance fpfComputeRollingResistance
13#define CAMEL_CASE_ENUM(entry) CAMEL_CASE_##entry
14
15// forward declarations
18struct RockyContact;
19
20// function prototypes
21typedef void(__stdcall* contact_model_f_type)(FORCE_KERNEL_PARAMETERS);
22typedef void(__stdcall* cuda_contact_model_kernels_f_type)(
23 IRockyModel& model, void** plugin_devices_data);
24typedef void(__stdcall* omp_contact_model_kernels_f_type)(
25 IRockyModel& model, void* plugin_data);
26
27namespace device {
28__host__ __device__ void builtin_contact_normal_forces(FORCE_KERNEL_PARAMETERS);
29__host__ __device__ void builtin_contact_tangential_forces(FORCE_KERNEL_PARAMETERS);
30__host__ __device__ void builtin_impact_energies(FORCE_KERNEL_PARAMETERS);
31__host__ __device__ void standard_compute_rolling_resistance(FORCE_KERNEL_PARAMETERS);
32template <bool has_deformable>
33__host__ __device__ void get_frictional_contact_general_parameters(
34 RockyContact& rocky_contact,
35 contact_output_data& output,
36 cuda_contact_intermediate_data& idata,
37 const double current_time);
38}
39
40enum EForcePipelineFunctions
41{
42 fpfComputeNormalForce = 0,
43 fpfComputeTangentialForce = 1,
44 fpfComputeImpactEnergy = 2,
45 fpfComputeRollingResistance = 3
46};
47
48struct ForcePipelineFunctions
49{
60 template <EForcePipelineFunctions function>
61 inline __host__ __device__ void run(FORCE_KERNEL_PARAMETERS) const
62 {
63 if constexpr (function == fpfComputeNormalForce)
64 {
65 device::builtin_contact_normal_forces(FORCE_KERNEL_ARGUMENTS);
66 }
67 else if constexpr (function == fpfComputeTangentialForce)
68 {
69 device::builtin_contact_tangential_forces(FORCE_KERNEL_ARGUMENTS);
70 }
71 else if constexpr (function == fpfComputeImpactEnergy)
72 {
73 device::builtin_impact_energies(FORCE_KERNEL_ARGUMENTS);
74 }
75 else if constexpr (function == fpfComputeRollingResistance)
76 {
77 device::standard_compute_rolling_resistance(FORCE_KERNEL_ARGUMENTS);
78 }
79 }
80
81 inline __host__ __device__ void get_frictional_parameters(
82 RockyContact& rocky_contact,
83 contact_output_data& output,
84 cuda_contact_intermediate_data& idata,
85 const double current_time) const
86 {
87 device::get_frictional_contact_general_parameters<false>(
88 rocky_contact, output, idata, current_time);
89 }
90};
91
92// Specialization for deformable particles
93struct DeformablePipelineFunctions : ForcePipelineFunctions
94{
95 inline __host__ __device__ void get_frictional_parameters(
96 RockyContact& rocky_contact,
97 contact_output_data& output,
98 cuda_contact_intermediate_data& idata,
99 const double current_time) const
100 {
101 device::get_frictional_contact_general_parameters<true>(
102 rocky_contact, output, idata, current_time);
103 }
104};
105
106#define SPECIALIZE_RUN_TO_FORCE_KERNEL(func_name) \
107 } /* force kernel */ \
108 } /* extern C */ \
109 template <> \
110 inline __host__ __device__ void ForcePipelineFunctions::run<CAMEL_CASE_ENUM(func_name)>(\
111 FORCE_KERNEL_PARAMETERS) const \
112 { \
113 func_name(FORCE_KERNEL_ARGUMENTS); \
114 } \
115 extern "C" {
116
117// Contact frictional forces, energy function, and rolling resistance head macros ==================
118#define FORCE_KERNEL_DEFINITION_HEADER(name, contact, intermediate_data, output_data, data) \
119 extern "C" ROCKYAPI_EXPORT ROCKY_FUNCTIONS void name( \
120 IRockyContact&(contact), \
121 IRockyContactIntermediateData&(intermediate_data), \
122 IRockyContactOutputData&(output_data), \
123 void*(data)) \
124 {
125#define ROCKY_PLUGIN_NORMAL_FORCE_ON_CONTACTS(contact, intermediate_data, output_data, data) \
126 FORCE_KERNEL_DEFINITION_HEADER( \
127 compute_normal_force, contact, intermediate_data, output_data, data)
128#define ROCKY_PLUGIN_TANGENTIAL_FORCE_ON_CONTACTS(contact, intermediate_data, output_data, data) \
129 FORCE_KERNEL_DEFINITION_HEADER( \
130 compute_tangential_force, contact, intermediate_data, output_data, data)
131#define ROCKY_PLUGIN_IMPACT_ENERGY_ON_CONTACTS(contact, intermediate_data, output_data, data) \
132 FORCE_KERNEL_DEFINITION_HEADER( \
133 compute_impact_energy, contact, intermediate_data, output_data, data)
134#define ROCKY_PLUGIN_ROLLING_RESISTANCE_ON_CONTACTS(contact, intermediate_data, output_data, data) \
135 FORCE_KERNEL_DEFINITION_HEADER( \
136 compute_rolling_resistance, contact, intermediate_data, output_data, data)
137
138// Contact frictional forces and energy function tail macros =======================================
139#define ROCKY_PLUGIN_NORMAL_FORCE_ON_CONTACTS_END() \
140 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_normal_force)
141#define ROCKY_PLUGIN_TANGENTIAL_FORCE_ON_CONTACTS_END() \
142 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_tangential_force)
143#define ROCKY_PLUGIN_IMPACT_ENERGY_ON_CONTACTS_END() \
144 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_impact_energy)
145#define ROCKY_PLUGIN_ROLLING_RESISTANCE_ON_CONTACTS_END() \
146 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_rolling_resistance)
147
148// CUDA Dispatcher function ========================================================================
149#define ROCKY_PLUGIN_OMP_CONTACT_MODEL_FUNCTIONS_SETUP() \
150 extern "C" ROCKYAPI_EXPORT void dispatch_omp_frictional_contact_forces_kernels( \
151 IRockyModel& model, void* plugin_device_data) \
152 { \
153 if (model._impl->gen.has_deformable_particles()) \
154 { \
155 rocky::omp::dispatch_frictional_contact_forces_kernel( \
156 model, DeformablePipelineFunctions {}, plugin_device_data); \
157 } \
158 else \
159 { \
160 rocky::omp::dispatch_frictional_contact_forces_kernel( \
161 model, ForcePipelineFunctions {}, plugin_device_data); \
162 } \
163 }
164
165#ifdef ROCKY_CUDA_API
166 #define ROCKY_PLUGIN_FINISH_CONTACT_MODEL_FUNCTIONS_SETUP() \
167 ROCKY_PLUGIN_OMP_CONTACT_MODEL_FUNCTIONS_SETUP() \
168 \
169 extern "C" ROCKYAPI_EXPORT void dispatch_cuda_frictional_contact_forces_kernels( \
170 IRockyModel& model, void** plugin_device_data) \
171 { \
172 if (model._impl->gen.has_deformable_particles()) \
173 { \
174 rocky::cuda::dispatch_frictional_contact_forces_kernel( \
175 model, DeformablePipelineFunctions {}, plugin_device_data); \
176 } \
177 else \
178 { \
179 rocky::cuda::dispatch_frictional_contact_forces_kernel( \
180 model, ForcePipelineFunctions {}, plugin_device_data); \
181 } \
182 }
183#else
184 #define ROCKY_PLUGIN_FINISH_CONTACT_MODEL_FUNCTIONS_SETUP() \
185 ROCKY_PLUGIN_OMP_CONTACT_MODEL_FUNCTIONS_SETUP()
186#endif
Definition rocky_contact_intermediate_data_api.hpp:18
Definition rocky_contact_output_data_api.hpp:38
Definition rocky_api.h:58

Connect with Ansys