Skip to main content

Rocky Solver SDK 2024 R2

rocky_api_contact_functions

Last update: 17.07.2025
1#pragma once
2
3#define FORCE_KERNEL_PARAMETERS \
4 IRockyContact &contact_api, IRockyContactIntermediateData &contact_idata, \
5 IRockyContactOutputData &contact_output, void *plugin_data
6#define FORCE_KERNEL_ARGUMENTS contact_api, contact_idata, contact_output, plugin_data
7
8#define CAMEL_CASE_compute_normal_force fpfComputeNormalForce
9#define CAMEL_CASE_compute_tangential_force fpfComputeTangentialForce
10#define CAMEL_CASE_compute_impact_energy fpfComputeImpactEnergy
11#define CAMEL_CASE_compute_rolling_resistance fpfComputeRollingResistance
12#define CAMEL_CASE_ENUM(entry) CAMEL_CASE_##entry
13
14// forward declarations
17
18// function prototypes
19typedef void(__stdcall* contact_model_f_type)(FORCE_KERNEL_PARAMETERS);
20typedef void(__stdcall* cuda_contact_model_kernels_f_type)(
21 IRockyModel& model, void** plugin_devices_data);
22typedef void(__stdcall* omp_contact_model_kernels_f_type)(
23 IRockyModel& model, void* plugin_data);
24
25namespace device {
26__host__ __device__ void builtin_contact_normal_forces(FORCE_KERNEL_PARAMETERS);
27__host__ __device__ void builtin_contact_tangential_forces(FORCE_KERNEL_PARAMETERS);
28__host__ __device__ void builtin_impact_energies(FORCE_KERNEL_PARAMETERS);
29__host__ __device__ void standard_compute_rolling_resistance(FORCE_KERNEL_PARAMETERS);
30}
31
32enum EForcePipelineFunctions
33{
34 fpfComputeNormalForce = 0,
35 fpfComputeTangentialForce = 1,
36 fpfComputeImpactEnergy = 2,
37 fpfComputeRollingResistance = 3
38};
39
40struct ForcePipelineFunctions
41{
52 template <EForcePipelineFunctions function>
53 inline __host__ __device__ void run(FORCE_KERNEL_PARAMETERS) const
54 {
55 if constexpr (function == fpfComputeNormalForce)
56 {
57 device::builtin_contact_normal_forces(FORCE_KERNEL_ARGUMENTS);
58 }
59 else if constexpr (function == fpfComputeTangentialForce)
60 {
61 device::builtin_contact_tangential_forces(FORCE_KERNEL_ARGUMENTS);
62 }
63 else if constexpr (function == fpfComputeImpactEnergy)
64 {
65 device::builtin_impact_energies(FORCE_KERNEL_ARGUMENTS);
66 }
67 else if constexpr (function == fpfComputeRollingResistance)
68 {
69 device::standard_compute_rolling_resistance(FORCE_KERNEL_ARGUMENTS);
70 }
71 }
72};
73
74#define SPECIALIZE_RUN_TO_FORCE_KERNEL(func_name) \
75 } /* force kernel */ \
76 } /* extern C */ \
77 template <> \
78 inline __host__ __device__ void ForcePipelineFunctions::run<CAMEL_CASE_ENUM(func_name)>(\
79 FORCE_KERNEL_PARAMETERS) const \
80 { \
81 func_name(FORCE_KERNEL_ARGUMENTS); \
82 } \
83 extern "C" {
84
85// Contact frictional forces, energy function, and rolling resistance head macros ==================
86#define FORCE_KERNEL_DEFINITION_HEADER(name, contact, intermediate_data, output_data, data) \
87 extern "C" ROCKYAPI_EXPORT ROCKY_FUNCTIONS void name( \
88 IRockyContact&(contact), \
89 IRockyContactIntermediateData&(intermediate_data), \
90 IRockyContactOutputData&(output_data), \
91 void*(data)) \
92 {
93#define ROCKY_PLUGIN_NORMAL_FORCE_ON_CONTACTS(contact, intermediate_data, output_data, data) \
94 FORCE_KERNEL_DEFINITION_HEADER( \
95 compute_normal_force, contact, intermediate_data, output_data, data)
96#define ROCKY_PLUGIN_TANGENTIAL_FORCE_ON_CONTACTS(contact, intermediate_data, output_data, data) \
97 FORCE_KERNEL_DEFINITION_HEADER( \
98 compute_tangential_force, contact, intermediate_data, output_data, data)
99#define ROCKY_PLUGIN_IMPACT_ENERGY_ON_CONTACTS(contact, intermediate_data, output_data, data) \
100 FORCE_KERNEL_DEFINITION_HEADER( \
101 compute_impact_energy, contact, intermediate_data, output_data, data)
102#define ROCKY_PLUGIN_ROLLING_RESISTANCE_ON_CONTACTS(contact, intermediate_data, output_data, data) \
103 FORCE_KERNEL_DEFINITION_HEADER( \
104 compute_rolling_resistance, contact, intermediate_data, output_data, data)
105
106// Contact frictional forces and energy function tail macros =======================================
107#define ROCKY_PLUGIN_NORMAL_FORCE_ON_CONTACTS_END() \
108 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_normal_force)
109#define ROCKY_PLUGIN_TANGENTIAL_FORCE_ON_CONTACTS_END() \
110 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_tangential_force)
111#define ROCKY_PLUGIN_IMPACT_ENERGY_ON_CONTACTS_END() \
112 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_impact_energy)
113#define ROCKY_PLUGIN_ROLLING_RESISTANCE_ON_CONTACTS_END() \
114 SPECIALIZE_RUN_TO_FORCE_KERNEL(compute_rolling_resistance)
115
116// CUDA Dispatcher function ========================================================================
117#define ROCKY_PLUGIN_OMP_CONTACT_MODEL_FUNCTIONS_SETUP() \
118 extern "C" ROCKYAPI_EXPORT void dispatch_omp_frictional_contact_forces_kernels( \
119 IRockyModel& model, void* plugin_device_data) \
120 { \
121 ForcePipelineFunctions functions {}; \
122 rocky::omp::dispatch_frictional_contact_forces_kernel(model, functions, plugin_device_data); \
123 }
124
125#ifdef ROCKY_CUDA_API
126 #define ROCKY_PLUGIN_FINISH_CONTACT_MODEL_FUNCTIONS_SETUP() \
127 ROCKY_PLUGIN_OMP_CONTACT_MODEL_FUNCTIONS_SETUP() \
128 \
129 extern "C" ROCKYAPI_EXPORT void dispatch_cuda_frictional_contact_forces_kernels( \
130 IRockyModel& model, void** plugin_device_data) \
131 { \
132 ForcePipelineFunctions functions {}; \
133 rocky::cuda::dispatch_frictional_contact_forces_kernel(model, functions, plugin_device_data); \
134 } \
135
136#else
137 #define ROCKY_PLUGIN_FINISH_CONTACT_MODEL_FUNCTIONS_SETUP() \
138 ROCKY_PLUGIN_OMP_CONTACT_MODEL_FUNCTIONS_SETUP()
139#endif
Definition rocky_contact_intermediate_data_api.hpp:17
Definition rocky_contact_output_data_api.hpp:37
Definition rocky_api.h:60

Connect with Ansys