Skip to main content

Rocky Solver SDK 2025 R2

api_device_joints

Last update: 16.07.2025
1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
2#pragma once
3
4#include <rocky20/device/device_model.hpp>
5
6namespace device
7{
8
9template <class backend, typename Callable>
10__global__ void execute_joints_function(
11 SDeviceModel *device_data, int device_id, cu_real current_time,
12 Callable process_joint_ptr, void *udf_data
13)
14{
15 IRockyDeviceModel device_model_api;
16 device_model_api._impl.model = device_data;
17 device_model_api._impl.current_time = current_time;
18
19 IRockyJoint joint_api(device_data, device_id);
20
21 // Thread
22 const cuda_general &general = device_data->get_general();
23 int thread_start, thread_step, thread_stop;
24 backend::ThreadIteration(thread_start, thread_step, thread_stop, general.njn_prt_active);
25 for (int joint_index = thread_start; joint_index < thread_stop; joint_index += thread_step)
26 {
27 joint_api._impl.reset(joint_index);
28 if (joint_api._impl.is_enabled())
29 {
30 //Process joint forces
31 process_joint_ptr(device_model_api, joint_api, udf_data);
32 }
33 }
34}
35
36template <class backend, typename Callable>
37__host__ __device__ void compute_joint_forces(
38 SDeviceModel *device_data, int device_id,
39 Callable process_joint_ptr, void *udf_data
40)
41{
42 //General data
43 const cuda_general &general = device_data->get_general();
44 const auto &periodic = device_data->gen->periodic_domain;
45 bool is_cylindrical = periodic.is_cylindrical();
46
47 IRockyJoint joint_api(device_data, device_id);
48 auto* data_recorder = device_data->joint_data_recorder;
49
50 // Thread
51 int thread_start, thread_step, thread_stop;
52 backend::ThreadIteration(thread_start, thread_step, thread_stop, general.njn_prt_active);
53 for (int joint_index = thread_start; joint_index < thread_stop; joint_index += thread_step)
54 {
55 if (joint_api._impl.get_joint_model(joint_index) == jmCustom)
56 {
57 joint_api._impl.reset(joint_index);
58 if (joint_api._impl.is_enabled())
59 {
60 //Process joint forces
61
62 IRockyJointOutputData output_data{};
63 process_joint_ptr(joint_api, output_data, udf_data);
64
65 auto &joint = device_data->jnt_prt[joint_index];
66
67 //Add joint forces and moments - home particle
68 cuda_particle_force &h_particle_forces = device_data->frc[joint.nh];
69
70 const auto& force = output_data._force;
71 const auto& home_moment = output_data._home_moment;
72 cu_real fxh = force.x;
73 cu_real fyh = force.y;
74 cu_real fzh = force.z;
75 cu_real mxh = home_moment.x;
76 cu_real myh = home_moment.y;
77 cu_real mzh = home_moment.z;
78
79 if (is_cylindrical)
80 {
81 periodic.get_cylindric_periodic_position(
82 fxh, fyh, fzh, joint_api._impl.state.periodic_position, {}, {}, true);
83 periodic.get_cylindric_periodic_position(
84 mxh, myh, mzh, joint_api._impl.state.periodic_position, {}, {}, true);
85 }
86
87 backend::AtomicAdd(&h_particle_forces.fx, fxh);
88 backend::AtomicAdd(&h_particle_forces.fy, fyh);
89 backend::AtomicAdd(&h_particle_forces.fz, fzh);
90 backend::AtomicAdd(&h_particle_forces.mx, mxh);
91 backend::AtomicAdd(&h_particle_forces.my, myh);
92 backend::AtomicAdd(&h_particle_forces.mz, mzh);
93
94 //Add joint forces and moments - near particle
95 auto& n_particle_force = device_data->frc[joint.nn];
96
97 backend::AtomicAdd(&(n_particle_force.fx), -force.x);
98 backend::AtomicAdd(&(n_particle_force.fy), -force.y);
99 backend::AtomicAdd(&(n_particle_force.fz), -force.z);
100
101 const auto &near_moment = output_data._near_moment;
102 backend::AtomicAdd(&(n_particle_force.mx), near_moment.x);
103 backend::AtomicAdd(&(n_particle_force.my), near_moment.y);
104 backend::AtomicAdd(&(n_particle_force.mz), near_moment.z);
105
106 if (data_recorder && data_recorder->enabled)
107 {
108 const cu_real dt = device_data->gen->dt;
109
110 // register forces
111 const cu_real3& normal = joint_api._impl.state.normal_vector;
112 const cu_real normal_force = rocky::vector::dot(force, normal);
113 const cu_real tangential_force = rocky::vector::get_norm(force - normal_force * normal);
114 data_recorder->register_joint_forces(
115 device_data->joint_scalars,
116 normal_force, tangential_force,
117 joint_index, dt
118 );
119
120 // register moments
121 const cu_real3 avg_moment = 0.5 * (home_moment + near_moment);
122 for (int i = 0; i < 3; i++)
123 {
124 const cu_real3& axis = joint_api._impl.state.ax[i];
125 const cu_real m_component = rocky::vector::dot(avg_moment, axis);
126 data_recorder->register_joint_moment(
127 device_data->joint_scalars,
128 static_cast<JointDataRecorder::JointMomentType>(i),
129 m_component,
130 joint_index, dt
131 );
132 }
133
134 // register stresses
135 if (data_recorder->stresses_enabled)
136 {
137 const cu_real area = joint_api._impl.state.area;
138 const cu_real tensile_stress = rocky::dmax(0.0, normal_force) / area;
139 const cu_real shear_stress = tangential_force / area;
140 const cu_real von_mises_stress = sqrt(tensile_stress * tensile_stress + 3.0 * shear_stress * shear_stress);
141 data_recorder->register_joint_stresses(
142 device_data->joint_scalars,
143 tensile_stress, shear_stress, von_mises_stress,
144 joint_index, dt
145 );
146 }
147 }
148 }
149 }
150 }
151}
152
153template <class backend, typename Callable>
154__host__ __device__ void compute_joint_breakage(
155 SDeviceModel* device_data, int device_id,
156 Callable process_joint_breakage_ptr, void* udf_data,
157 typename backend::atomic_int_ptr nbreak_joints_a, cu_real time_curr
158)
159{
160 const cuda_general& general = device_data->get_general();
161
162 int njb_old = 0;
163 IRockyJoint joint_api(device_data, device_id);
164 auto& rocky_joint = joint_api._impl;
165
166 int thread_start, thread_step, thread_stop;
167 backend::ThreadIteration(thread_start, thread_step, thread_stop, general.njn_prt_brk_active);
168 for (int brjnt_index = thread_start; brjnt_index < thread_stop; brjnt_index += thread_step)
169 {
170 int joint_index = device_data->breakable_joints[brjnt_index] - general.njn_prt_active_start;
171
172 if (rocky_joint.get_breakage_model(joint_index) == pbmDiscreteCustom)
173 {
174 rocky_joint.reset(joint_index);
175 bool broken = false;
176
177 if (rocky_joint.is_enabled())
178 {
179 if (time_curr - rocky_joint.get_particle_release_time() < general.breakage_start_release_time)
180 return;
181
182 process_joint_breakage_ptr(joint_api, broken, udf_data);
183
184 if (broken)
185 {
186 backend::AtomicAdd(nbreak_joints_a, 1, njb_old);
187 device_data->broken_joints[njb_old] = joint_index;
188 device_data->joint_scalars->get_breakage_state(joint_index) = dbsFullyBroken;
189 }
190 }
191 }
192 }
193}
194
195} // namespace device
Definition rocky_model_api.hpp:20
Definition rocky_joint_api.hpp:33

Connect with Ansys