Skip to main content

Rocky Solver SDK 2025 R2

rocky_particle

Last update: 16.07.2025
1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
2#pragma once
3
4// Includes =======================================================================================
5#include <rocky20/api/device/api_backend.hpp>
6#include <rocky20/api/rocky_particle_scalars.hpp>
7#include <rocky20/device/device_model.hpp>
8#include <rocky20/device/element_properties.hpp>
9
10class cuda_host;
11typedef cuda_host RockyModel;
12
13// ================================================================================================
14// RockyParticle
15// ================================================================================================
16struct RockyParticle
17{
18 // States --------------------------------------------------------------------------------------
19
20 inline ROCKY_FUNCTIONS bool is_active() const
21 {
22 return this->particle->active();
23 }
24
25 inline ROCKY_FUNCTIONS void set_active(const bool active = true) const
26 {
27 this->particle->set_active(active);
28 }
29
30 inline ROCKY_FUNCTIONS bool is_released() const
31 {
32 return this->particle->released();
33 }
34
35 inline ROCKY_FUNCTIONS bool is_enabled() const
36 {
37 return this->particle->enabled();
38 }
39
40 inline ROCKY_FUNCTIONS void set_enabled(const bool enabled = true) const
41 {
42 this->particle->set_enabled(enabled);
43 }
44
45 inline ROCKY_FUNCTIONS bool is_frozen() const
46 {
47 return this->particle->frozen();
48 }
49
50 inline ROCKY_FUNCTIONS void set_frozen(const bool frozen = true) const
51 {
52 this->particle->set_frozen(frozen);
53 }
54
55 inline ROCKY_FUNCTIONS bool is_new_release() const
56 {
57 return this->particle->new_release();
58 }
59
60 inline ROCKY_FUNCTIONS bool has_linked_motion() const
61 {
62 return this->particle->has_linked_motion();
63 }
64
65 inline ROCKY_FUNCTIONS void set_particle_contact_disabled(const bool disabled = true)
66 {
67 this->particle->set_particle_contact_disabled(disabled);
68 }
69
70 inline ROCKY_FUNCTIONS void set_triangle_contact_disabled(const bool disabled = true)
71 {
72 this->particle->set_triangle_contact_disabled(disabled);
73 }
74
75 inline ROCKY_FUNCTIONS void set_remove_from_contacts_search(const bool remove = true)
76 {
77 this->particle->set_remove_from_contacts_search(remove);
78 }
79
80 inline ROCKY_FUNCTIONS void remove()
81 {
82 this->particle->set_active(false);
83 this->particle->set_enabled(false);
84 }
85
86 inline ROCKY_FUNCTIONS bool is_element() const
87 {
88 if (this->model->prt_geo != nullptr)
89 return this->model->prt_geo[this->particle_index].is_particle_element();
90 return false;
91 }
92
93 inline ROCKY_FUNCTIONS bool is_meshed_parent() const
94 {
95 if (this->model->prt_geo != nullptr)
96 return this->model->prt_geo[this->particle_index].is_meshed_parent_particle();
97 return false;
98 }
99
100 inline ROCKY_FUNCTIONS bool is_assembly() const
101 {
102 return this->get_group().is_assembly();
103 }
104
105 inline ROCKY_FUNCTIONS bool is_non_round() const
106 {
107 return this->get_group().is_non_round();
108 }
109
110 inline ROCKY_FUNCTIONS void set_as_unbreakable() const
111 {
112 this->model->particle_scalars->get_breakage_state(this->particle_index)
113 .set_as_unbreakable();
114 }
115
116 // Indices -------------------------------------------------------------------------------------
117
118 inline ROCKY_FUNCTIONS int get_particle_group_index() const
119 {
120 if (this->group_index < 0)
121 const_cast<int&>(this->group_index) = this->particle->get_group_index();
122 return this->group_index;
123 }
124
125 inline ROCKY_FUNCTIONS int get_global_index() const
126 {
127 return this->particle->id_g;
128 }
129
130 inline ROCKY_FUNCTIONS int get_inlet_index() const
131 {
132 return this->particle->ninl;
133 }
134
135 inline ROCKY_FUNCTIONS int get_gpu_index() const
136 {
137 return int(this->particle->gpu_id);
138 }
139
140 inline ROCKY_FUNCTIONS void set_gpu_index(const int index)
141 {
142 this->particle->gpu_id = char(index);
143 }
144
145 inline ROCKY_FUNCTIONS int get_dgb_tetra_index() const
146 {
147 if (this->model->prt_geo != nullptr)
148 return this->model->prt_geo[this->particle_index].dgb_tetra_index;
149 return -2;
150 }
151
152 inline ROCKY_FUNCTIONS int get_dgb_parent_index() const
153 {
154 if (this->model->prt_geo != nullptr)
155 return this->model->prt_geo[this->particle_index].dgb_parent_index;
156 return -2;
157 }
158
159 inline ROCKY_FUNCTIONS int get_dgb_fragment_index() const
160 {
161 if (this->model->prt_geo != nullptr)
162 return this->model->prt_geo[this->particle_index].dgb_fragment_index;
163 return -2;
164 }
165
166 inline ROCKY_FUNCTIONS int get_tag() const
167 {
168 const auto& group = this->get_group();
169 if (group.meshing_type == pmt1DRegular)
170 {
171 const int element_index = group.elements_storage_start + this->get_dgb_tetra_index();
172 return this->model->flexible_element_data[element_index].tag;
173 }
174 else
175 {
176 return -1;
177 }
178 }
179
180 // Related Entities ----------------------------------------------------------------------------
181
182 inline ROCKY_FUNCTIONS ParticleType get_type() const
183 {
184 return static_cast<ParticleType>(this->get_group().tpe);
185 }
186
187 inline ROCKY_FUNCTIONS const cuda_particle_group& get_group() const
188 {
189 return this->model->get_particle_group(this->get_particle_group_index());
190 }
191
192 inline ROCKY_FUNCTIONS const cuda_material& get_material() const
193 {
194 return this->model->get_material(this->get_group().get_material_index());
195 }
196
197 inline ROCKY_FUNCTIONS size_t get_number_of_assembly_parts() const
198 {
199 return this->get_group().n_elements;
200 }
201
202 inline ROCKY_FUNCTIONS const cuda_material& get_assembly_part_material(size_t part_id) const
203 {
204 const cuda_particle_group& group = this->get_group();
205 const auto& part = this->model->assembly_data[group.elements_storage_start + part_id];
206 const cuda_particle_group& part_group = this->model->get_particle_group(part.igr);
207 const auto& part_material = this->model->get_material(part_group.get_material_index());
208 return part_material;
209 }
210
211 inline ROCKY_FUNCTIONS const cuda_vertice_stor* get_vertices_array() const
212 {
213 return this->model->prt_vrt + this->model->prt_geo[this->particle_index].nv_str;
214 }
215
216 inline ROCKY_FUNCTIONS int get_number_of_vertices() const
217 {
218 if (this->get_global_index() < this->model->gen->nprt_nb)
219 return this->get_group().nvr;
220 else
221 return this->model->prt_geo[this->particle_index].nvr;
222 }
223
224 // Material and Group Properties ---------------------------------------------------------------
225
226 inline ROCKY_FUNCTIONS double get_density() const
227 {
228 const cuda_material& material = this->get_material();
229 return material.dens;
230 }
231
232 inline ROCKY_FUNCTIONS double get_original_mass() const
233 {
234 return this->particle->get_original_mass(this->model->inr_prp);
235 }
236
237 inline ROCKY_FUNCTIONS double get_area() const
238 {
239 return this->particle->get_current_area(this->model->inr_prp);
240 }
241
242 inline ROCKY_FUNCTIONS double get_size() const
243 {
244 return this->particle->get_current_size();
245 }
246
247 inline ROCKY_FUNCTIONS double get_cgm_scale_factor() const
248 {
249 return this->get_group().cgm_scale_factor;
250 }
251
252 inline ROCKY_FUNCTIONS double get_mass() const
253 {
254 return ParticleProperties::get_mass(
255 *this->particle,
256 this->particle_index,
257 this->model->inr_prp,
258 this->model->particle_scalars);
259 }
260
261 inline ROCKY_FUNCTIONS double get_sphericity() const
262 {
263 if (this->get_type() != ptSpherical)
264 {
265 const double diameter = this->get_equivalent_diameter();
266 return M_PI * diameter * diameter / this->get_area();
267 }
268 return 1.0;
269 }
270
271 inline ROCKY_FUNCTIONS double get_bulk_volume() const
272 {
273 return ParticleProperties::get_bulk_volume(
274 *this->particle,
275 this->particle_index,
276 this->model->inr_prp,
277 this->model->particle_scalars);
278 }
279
280 inline ROCKY_FUNCTIONS double get_solid_volume() const
281 {
282 return ParticleProperties::get_solid_volume(
283 *this->particle,
284 this->particle_index,
285 this->model->inr_prp,
286 this->get_group(),
287 this->model->particle_scalars);
288 }
289
290 inline ROCKY_FUNCTIONS double get_thermal_conductivity() const
291 {
292 return ParticleProperties::get_thermal_conductivity(
293 this->model->particle_scalars,
294 *this->particle,
295 this->particle_index,
296 this->get_material());
297 }
298
299 inline ROCKY_FUNCTIONS void set_thermal_conductivity(double value)
300 {
301 this->model->particle_scalars->get_thermal_conductivity(this->particle_index) = value;
302 }
303
304 inline ROCKY_FUNCTIONS double get_poisson_ratio() const
305 {
306 return ParticleProperties::get_poisson_ratio(
307 this->model->particle_scalars,
308 *this->particle,
309 this->particle_index,
310 this->get_material());
311 }
312
313 inline ROCKY_FUNCTIONS void set_poisson_ratio(double value)
314 {
315 this->model->particle_scalars->get_poisson_ratio(this->particle_index) = value;
316 }
317
318 inline ROCKY_FUNCTIONS double get_specific_heat() const
319 {
320 return ParticleProperties::get_specific_heat(
321 this->model->particle_scalars,
322 *this->particle,
323 this->particle_index,
324 this->get_material());
325 }
326
327 inline ROCKY_FUNCTIONS void set_specific_heat(double value)
328 {
329 this->model->particle_scalars->get_specific_heat(this->particle_index) = value;
330 }
331
332 inline ROCKY_FUNCTIONS double get_equivalent_diameter() const
333 {
334 return cbrt(6.0 * this->get_bulk_volume() / M_PI);
335 }
336
337 inline ROCKY_FUNCTIONS double3 get_moment_of_inertia() const
338 {
339 return ParticleProperties::get_inertia_moment(
340 *this->particle,
341 this->particle_index,
342 this->model->inr_prp,
343 this->model->particle_scalars);
344 }
345
346 inline ROCKY_FUNCTIONS double get_original_bulk_volume() const
347 {
348 return ParticleProperties::get_original_bulk_volume(*this->particle, this->model->inr_prp);
349 }
350
351 inline ROCKY_FUNCTIONS double get_original_solid_volume() const
352 {
353 return ParticleProperties::get_original_solid_volume(
354 *this->particle, this->model->inr_prp, this->get_group());
355 }
356
357 inline ROCKY_FUNCTIONS double get_original_size() const
358 {
359 return this->particle->get_original_size();
360 }
361
362 inline ROCKY_FUNCTIONS double get_size_scale() const
363 {
364 return this->particle->get_size_scale();
365 }
366
367 inline ROCKY_FUNCTIONS double get_minimum_fragment_size() const
368 {
369 return rocky::dmax(
370 this->get_group().br_inst_params.szmin,
371 this->get_group().br_inst_params.fr_szmin * this->get_original_size());
372 }
373
374 inline ROCKY_FUNCTIONS SVectorAngleD get_orientation_axis_angle() const
375 {
376 return rocky::transform::quaternion_to_angle(this->get_orientation_quaternion());
377 }
378
379 // Scalar Properties ---------------------------------------------------------------------------
380
381 inline ROCKY_FUNCTIONS double get_strength() const
382 {
383 return this->model->particle_scalars->get_strength(this->particle_index);
384 }
385
386 inline ROCKY_FUNCTIONS double get_release_time() const
387 {
388 return this->model->particle_scalars->get_release_time(this->particle_index);
389 }
390
391 inline ROCKY_FUNCTIONS double3 get_centroid() const
392 {
393 return this->particle->get_centroid();
394 }
395
396 inline ROCKY_FUNCTIONS void set_centroid(const double3& centroid) const
397 {
398 this->particle->x = centroid.x;
399 this->particle->y = centroid.y;
400 this->particle->z = centroid.z;
401 }
402
403 inline ROCKY_FUNCTIONS double3 get_translational_velocity() const
404 {
405 return this->model->prt_vel[this->particle_index].get_translational();
406 }
407
408 inline ROCKY_FUNCTIONS void set_translational_velocity(const double3& velocity) const
409 {
410 this->model->prt_vel[this->particle_index].ux = velocity.x;
411 this->model->prt_vel[this->particle_index].uy = velocity.y;
412 this->model->prt_vel[this->particle_index].uz = velocity.z;
413 }
414
415 inline ROCKY_FUNCTIONS double3 get_rotational_velocity() const
416 {
417 return this->model->prt_vel[this->particle_index].get_rotational();
418 }
419
420 inline ROCKY_FUNCTIONS void set_rotational_velocity(const double3& velocity) const
421 {
422 this->model->prt_vel[this->particle_index].wx = velocity.x;
423 this->model->prt_vel[this->particle_index].wy = velocity.y;
424 this->model->prt_vel[this->particle_index].wz = velocity.z;
425 }
426
427 inline ROCKY_FUNCTIONS double4 get_orientation_quaternion() const
428 {
429 if (this->model->gen->flags.has_non_round_particles())
430 {
431 return this->model->prt_geo[this->particle_index].get_quaternion();
432 }
433 else if (this->model->particle_scalars->is_round_quaternion_enabled())
434 {
435 return this->model->particle_scalars->get_round_quaternion(this->particle_index);
436 }
437 else
438 {
439 return { 0, 0, 0, 1 }; // Identity quaternion
440 }
441 }
442
443 inline ROCKY_FUNCTIONS void set_orientation_quaternion(const double4& quaternion) const
444 {
445 if (this->model->gen->flags.has_non_round_particles())
446 {
447 rocky::transform::copy_quaternion(
448 this->model->prt_geo[this->particle_index].quat, quaternion);
449 }
450 else if (this->model->particle_scalars->is_round_quaternion_enabled())
451 {
452 this->model->particle_scalars->get_round_quaternion(this->particle_index) = quaternion;
453 }
454 }
455
456 inline ROCKY_FUNCTIONS double get_temperature() const
457 {
458 return this->model->particle_scalars->get_temperature(this->particle_index);
459 }
460
461 inline ROCKY_FUNCTIONS void set_temperature(const double temperature)
462 {
463 this->model->particle_scalars->get_temperature(this->particle_index) = temperature;
464 }
465
466 // Transfer Scalar Properties ------------------------------------------------------------------
467
468 inline ROCKY_FUNCTIONS double get_impact_energy() const
469 {
470 return this->model->particle_transfer_scalars->get_particle_impact_energy(particle_index);
471 }
472
473 inline ROCKY_FUNCTIONS double3 get_forces() const
474 {
475 const cuda_particle_force& prt_forces = this->model->frc[this->particle_index];
476 return double3 { prt_forces.fx, prt_forces.fy, prt_forces.fz };
477 }
478
479 inline ROCKY_FUNCTIONS void set_forces(const double3& forces)
480 {
481 cuda_particle_force& prt_forces = this->model->frc[this->particle_index];
482 prt_forces.fx = forces.x;
483 prt_forces.fy = forces.y;
484 prt_forces.fz = forces.z;
485 }
486
487 inline ROCKY_FUNCTIONS void add_forces(const double3& forces)
488 {
489 cuda_particle_force& prt_forces = this->model->frc[this->particle_index];
490 backend::atomic_add(&prt_forces.fx, forces.x);
491 backend::atomic_add(&prt_forces.fy, forces.y);
492 backend::atomic_add(&prt_forces.fz, forces.z);
493 }
494
495 inline ROCKY_FUNCTIONS double3 get_moments() const
496 {
497 const cuda_particle_force& prt_forces = this->model->frc[this->particle_index];
498 return double3 { prt_forces.mx, prt_forces.my, prt_forces.mz };
499 }
500
501 inline ROCKY_FUNCTIONS void add_moments(const double3& moments)
502 {
503 cuda_particle_force& prt_forces = this->model->frc[this->particle_index];
504 backend::atomic_add(&prt_forces.mx, moments.x);
505 backend::atomic_add(&prt_forces.my, moments.y);
506 backend::atomic_add(&prt_forces.mz, moments.z);
507 }
508
509 inline ROCKY_FUNCTIONS double get_heat_transfer_rate() const
510 {
511 return this->model->particle_transfer_scalars->get_heat_transfer(this->particle_index);
512 }
513
514 // Scalar Management ---------------------------------------------------------------------------
515
516 ROCKY_FUNCTIONS IRockyParticleScalars get_scalars() const
517 {
518 return { *this->model->particle_scalars, this->particle_index };
519 }
520
521 ROCKY_FUNCTIONS IRockyParticleTransferScalars get_transfer_scalars() const
522 {
523 return { *this->model->particle_transfer_scalars, this->particle_index };
524 }
525
526 ROCKY_FUNCTIONS IRockyParticleBreakageScalars get_breakage_scalars() const
527 {
528 return { *this->model->particle_breakage_scalars, this->particle_index };
529 }
530
531 // Constructors --------------------------------------------------------------------------------
532
533 inline ROCKY_FUNCTIONS void reset(int index)
534 {
535 this->particle = this->model->prt + index;
536 const_cast<int&>(this->particle_index) = index;
537 const_cast<int&>(this->group_index) = -1;
538 }
539
540 inline ROCKY_FUNCTIONS RockyParticle(SDeviceModel* model, const int index)
541 : particle_index(index)
542 , group_index(-1)
543 , particle((*model).prt + index)
544 , model(model)
545 {
546 }
547
548 inline RockyParticle(cuda_host& model, const int index)
549 : particle_index(index)
550 , group_index(-1)
551 , particle(model.prt.data() + index)
552 , model(model.GetHostData())
553 {
554 }
555
556 const int particle_index;
557 const int group_index; // cached index
558 cuda_particle* particle;
559 SDeviceModel* model;
560};
561
562// ================================================================================================
563// RockyParticleHost
564// ================================================================================================
565struct RockyParticleHost : RockyParticle
566{
567 bool is_released() const
568 {
569 if (this->particle->released())
570 {
571 /* volumetric fill or custom input particles with release time 0 begins released */
572 if (this->solver_model->iteration.current_time == 0 && this->get_release_time() == 0)
573 return false;
574 return true;
575 }
576 /* unreleased particles are always disabled */
577 return false;
578 }
579
580 RockyParticleHost(RockyModel* _model, const int _index)
581 : RockyParticle(_model->GetHostData(), _index)
582 , solver_model(_model)
583 {
584 }
585
586 RockyModel* solver_model;
587};
Definition rocky_particle_scalars.hpp:544
Definition rocky_particle_scalars.hpp:105
Definition rocky_particle_scalars.hpp:407

Connect with Ansys