Skip to main content

Rocky Solver SDK 2025 R2

rocky_contact

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/device/device_model.hpp>
6
7#include <rocky20/api/rocky_boundary.hpp>
8#include <rocky20/api/rocky_boundary_api.hpp>
9#include <rocky20/api/rocky_contact_scalars.hpp>
10#include <rocky20/api/rocky_particle_api.hpp>
11#include <rocky20/device/element_properties.hpp>
12
13#define RC_I_INVALID_INDEX UINT32_MAX // Invalid index for 32-bit unsigned integers
14#define RC_S_INVALID_INDEX UINT16_MAX // Invalid index for 16-bit unsigned integers
15
16// =================================================================================================
17// RockyContact
18// =================================================================================================
19struct RockyContact
20{
21 inline ROCKY_FUNCTIONS double get_timestep() const
22 {
23 return this->model->gen->dt;
24 }
25
26 inline ROCKY_FUNCTIONS double3 get_gravity_vector(double current_time) const
27 {
28 return this->model->gen->get_gravity(current_time);
29 }
30
31 inline ROCKY_FUNCTIONS bool is_particle_particle() const
32 {
33 return this->is_particle_contact;
34 }
35
36 inline ROCKY_FUNCTIONS bool is_particle_triangle() const
37 {
38 return !this->is_particle_contact;
39 }
40
41 inline ROCKY_FUNCTIONS bool is_frictional() const
42 {
43 return this->get_state().is_frictional();
44 }
45
46 inline ROCKY_FUNCTIONS bool is_adhesive() const
47 {
48 return this->get_state().is_adhesive();
49 }
50
51 inline ROCKY_FUNCTIONS int get_home_particle_index() const
52 {
53 if (this->home_particle_index == RC_I_INVALID_INDEX)
54 this->home_particle_index = this->get_scalars().get_home_index(this->contact_index);
55 return this->home_particle_index;
56 }
57
58 inline ROCKY_FUNCTIONS const cuda_particle& get_home_particle() const
59 {
60 return this->model->get_particle(this->get_home_particle_index());
61 }
62
63 inline ROCKY_FUNCTIONS cuda_particle_force& get_home_particle_force() const
64 {
65 return this->model->get_particle_force(this->get_home_particle_index());
66 }
67
68 inline ROCKY_FUNCTIONS int get_home_particle_base_group_index() const
69 {
70 if (this->home_group_index == RC_S_INVALID_INDEX)
71 this->home_group_index = short(this->get_home_particle().get_group_index());
72 return this->home_group_index;
73 }
74
75 // Return base group. This is an assembly group in the case of assembly, it is different from
76 // assembly element group. Base group is to be used for per-assembly values (density, CGM scale
77 // etc.) while element group is to be used for interactions. For non-assembly particle base
78 // group and element group are the same.
79 inline ROCKY_FUNCTIONS const cuda_particle_group& get_home_particle_base_group() const
80 {
81 return this->model->get_particle_group(this->get_home_particle_base_group_index());
82 }
83
84 inline ROCKY_FUNCTIONS const cuda_particle_group& get_home_particle_group() const
85 {
86 const int base_group_index = this->get_home_particle_base_group_index();
87 const auto& base_group = this->model->get_particle_group(base_group_index);
88 if (base_group.is_assembly()) [[unlikely]]
89 {
90 const int elm_id = this->get_scalars().get_home_part_index(this->contact_index);
91 return this->model->get_particle_group(base_group_index, elm_id);
92 }
93 else
94 {
95 return base_group;
96 }
97 }
98
99 inline ROCKY_FUNCTIONS const cuda_particle_velocity& get_home_particle_velocity() const
100 {
101 return this->model->get_particle_velocity(this->get_home_particle_index());
102 }
103
104 inline ROCKY_FUNCTIONS int get_near_particle_index() const
105 {
106 if (this->near_element_index == RC_I_INVALID_INDEX)
107 this->near_element_index = this->get_scalars().get_near_index(this->contact_index);
108 return this->near_element_index;
109 }
110
111 // Near contact particle, group and velocity can be null in contact with triangles
112 inline ROCKY_FUNCTIONS const cuda_particle& get_near_particle() const
113 {
114 return this->model->get_particle(this->get_near_particle_index());
115 }
116
117 inline ROCKY_FUNCTIONS cuda_particle_force& get_near_particle_force() const
118 {
119 return this->model->get_particle_force(this->get_near_particle_index());
120 }
121
122 inline ROCKY_FUNCTIONS int get_near_particle_base_group_index() const
123 {
124 return this->get_near_particle().get_group_index();
125 }
126
127 inline ROCKY_FUNCTIONS const cuda_particle_group& get_near_particle_base_group() const
128 {
129 return this->model->get_particle_group(this->get_near_particle_base_group_index());
130 }
131
132 inline ROCKY_FUNCTIONS const cuda_particle_group& get_near_particle_group() const
133 {
134 const int base_group_index = this->get_near_particle_base_group_index();
135 const auto& base_group = this->model->get_particle_group(base_group_index);
136 if (base_group.is_assembly()) [[unlikely]]
137 {
138 const int elm_id = this->get_scalars().get_near_part_index(this->contact_index);
139 return this->model->get_particle_group(base_group_index, elm_id);
140 }
141 else
142 {
143 return base_group;
144 }
145 }
146
147 inline ROCKY_FUNCTIONS const cuda_particle_velocity& get_near_particle_velocity() const
148 {
149 return this->model->get_particle_velocity(this->get_near_particle_index());
150 }
151
152 // Boundary ------------------------------------------------------------------------------------
153
154 inline ROCKY_FUNCTIONS int get_near_triangle_index() const
155 {
156 if (this->near_element_index == RC_I_INVALID_INDEX)
157 this->near_element_index = this->get_scalars().get_near_index(this->contact_index);
158 return this->near_element_index;
159 }
160
161 // Near contact triangle and boundary can be null in contact with particles
162 inline ROCKY_FUNCTIONS RockyTriangle get_near_triangle() const
163 {
164 return { this->model, this->get_near_triangle_index() };
165 }
166
167 inline ROCKY_FUNCTIONS const cuda_boundary& get_near_boundary() const
168 {
169 return this->get_near_triangle().get_boundary();
170 }
171
172 inline ROCKY_FUNCTIONS int get_near_boundary_index() const
173 {
174 return this->get_near_triangle().get_boundary_index();
175 }
176
177 // Materials -----------------------------------------------------------------------------------
178
184 inline ROCKY_FUNCTIONS const cuda_material& get_home_material() const
185 {
186 return this->model->get_material(this->get_home_material_index());
187 }
188
194 inline ROCKY_FUNCTIONS const cuda_material& get_near_material() const
195 {
196 return this->model->get_material(this->get_near_material_index());
197 }
198
199 inline ROCKY_FUNCTIONS int get_home_material_index() const
200 {
201 if (this->home_material_index == RC_S_INVALID_INDEX)
202 this->home_material_index = short(this->get_home_particle_group().get_material_index());
203 return this->home_material_index;
204 }
205
206 inline ROCKY_FUNCTIONS int get_near_material_index() const
207 {
208 if (this->near_material_index == RC_S_INVALID_INDEX)
209 {
210 this->near_material_index = short(
211 this->is_particle_contact ? this->get_near_particle_group().get_material_index()
212 : this->get_near_triangle().get_material_index());
213 }
214 return this->near_material_index;
215 }
216
217 inline ROCKY_FUNCTIONS const MaterialInteraction& get_material_interaction() const
218 {
219 return this->model->material_interactions[this->get_material_interaction_index()];
220 }
221
222 inline ROCKY_FUNCTIONS int get_material_interaction_index() const
223 {
224 if (this->material_interaction_index == RC_S_INVALID_INDEX)
225 {
226 this->material_interaction_index = short(MaterialInteraction::GetMaterialInteractionIndex(
227 this->get_home_material_index(), this->get_near_material_index()));
228 }
229 return this->material_interaction_index;
230 }
231
232 // Contact geometry ----------------------------------------------------------------------------
233
234 inline ROCKY_FUNCTIONS double get_previous_overlap() const
235 {
236 return this->get_scalars().get_previous_overlap(this->contact_index);
237 }
238
239 inline ROCKY_FUNCTIONS double get_overlap() const
240 {
241 return this->get_scalars().get_overlap(this->contact_index);
242 }
243
244 inline ROCKY_FUNCTIONS double3 get_normal_unit_vector() const
245 {
246 return rocky::vector::cast<double3>(this->get_normal());
247 }
248
249 inline ROCKY_FUNCTIONS double3 get_contact_position() const
250 {
251 return this->get_scalars().get_position(this->contact_index);
252 }
253
254 inline ROCKY_FUNCTIONS double get_scale_factor() const
255 {
256 return this->get_scalars().get_scale(this->contact_index);
257 }
258
259 inline ROCKY_FUNCTIONS float3 get_normal() const
260 {
261 return this->get_scalars().get_normal(this->contact_index);
262 }
263
264 inline ROCKY_FUNCTIONS float get_scale() const
265 {
266 return this->get_scalars().get_scale(this->contact_index);
267 }
268
269 inline ROCKY_FUNCTIONS PeriodicPosition get_periodic_position() const
270 {
271 return this->get_periodic_domain().enabled()
272 ? this->get_scalars().get_periodic_position(this->contact_index)
273 : PeriodicPosition {};
274 }
275
276 inline ROCKY_FUNCTIONS const cuda_periodic& get_periodic_domain() const
277 {
278 return this->model->gen->periodic_domain;
279 }
280
281 // State ---------------------------------------------------------------------------------------
282
283 inline ROCKY_FUNCTIONS SContactState get_state() const
284 {
285 return this->state;
286 }
287
288 inline ROCKY_FUNCTIONS bool just_started_frictional() const
289 {
290 return this->get_state().just_started_frictional();
291 }
292
293 inline ROCKY_FUNCTIONS bool just_started_adhesive() const
294 {
295 return this->get_state().just_started_adhesive();
296 }
297
298 inline ROCKY_FUNCTIONS bool just_finished_frictional() const
299 {
300 return this->get_state().just_finished_frictional();
301 }
302
303 inline ROCKY_FUNCTIONS bool just_finished_adhesive() const
304 {
305 return this->get_state().just_finished_adhesive();
306 }
307
308 inline ROCKY_FUNCTIONS bool is_loading() const
309 {
310 return this->get_state().is_loading();
311 }
312
313 inline ROCKY_FUNCTIONS bool is_unloading() const
314 {
315 return this->get_state().is_unloading();
316 }
317
318 inline ROCKY_FUNCTIONS bool is_positive_oriented() const
319 {
320 if (this->is_particle_contact)
321 return this->get_home_particle().id_g > this->get_near_particle().id_g;
322 else
323 return true;
324 }
325
326 inline ROCKY_FUNCTIONS SContactLocation get_home_location() const
327 {
328 return this->get_scalars().has_home_location()
329 ? this->get_scalars().get_home_location(this->contact_index)
330 : SContactLocation {};
331 }
332
333 inline ROCKY_FUNCTIONS SContactLocation get_near_location() const
334 {
335 return (!this->is_particle_contact || this->get_scalars().has_near_location())
336 ? this->get_scalars().get_near_location(this->contact_index)
337 : SContactLocation {};
338 }
339
340 // Scalars -------------------------------------------------------------------------------------
341
342 inline ROCKY_FUNCTIONS rocky20::ContactScalars& get_scalars()
343 {
344 return this->is_particle_contact ? *this->model->current_particle_contact_scalars
345 : *this->model->current_triangle_contact_scalars;
346 }
347
348 inline ROCKY_FUNCTIONS const rocky20::ContactScalars& get_scalars() const
349 {
350 return this->is_particle_contact ? *this->model->current_particle_contact_scalars
351 : *this->model->current_triangle_contact_scalars;
352 }
353
354 inline ROCKY_FUNCTIONS IRockyContactScalars get_particle_contact_scalars() const
355 {
356 return { *this->model->current_particle_contact_scalars, this->contact_index };
357 }
358
359 inline ROCKY_FUNCTIONS IRockyContactScalars get_triangle_contact_scalars() const
360 {
361 return { *this->model->current_triangle_contact_scalars, this->contact_index };
362 }
363
364 // Home or near properties ---------------------------------------------------------------------
365
366 inline ROCKY_FUNCTIONS double get_home_poisson_ratio() const
367 {
368 return ParticleProperties::get_poisson_ratio(
369 this->model->particle_scalars,
370 this->get_home_particle(),
371 this->get_home_particle_index(),
372 this->get_home_material());
373 }
374
375 inline ROCKY_FUNCTIONS double get_near_particle_poisson_ratio() const
376 {
377 return ParticleProperties::get_poisson_ratio(
378 this->model->particle_scalars,
379 this->get_near_particle(),
380 this->get_near_particle_index(),
381 this->get_near_material());
382 }
383
384 inline ROCKY_FUNCTIONS double get_near_triangle_poisson_ratio() const
385 {
386 return TriangleProperties::get_poisson_ratio(
387 this->model->triangle_scalars,
388 this->get_near_triangle_index(),
389 this->get_near_material());
390 }
391
392 inline ROCKY_FUNCTIONS double get_near_poisson_ratio() const
393 {
394 return this->is_particle_contact ? this->get_near_particle_poisson_ratio()
395 : this->get_near_triangle_poisson_ratio();
396 }
397
398 inline ROCKY_FUNCTIONS double get_home_stiffness() const
399 {
400 return this->get_home_particle().get_original_size() * this->get_home_material().kn_load;
401 }
402
403 inline ROCKY_FUNCTIONS double get_near_stiffness() const
404 {
405 const double near_size = this->is_particle_contact
406 ? this->get_near_particle().get_original_size()
407 : this->get_home_particle().get_original_size();
408 return near_size * this->get_near_material().kn_load;
409 }
410
411 inline ROCKY_FUNCTIONS double get_home_stiffness_fraction() const
412 {
413 const double home_stiffness = this->get_home_stiffness();
414 const double near_stiffness = this->get_near_stiffness();
415 return near_stiffness / (home_stiffness + near_stiffness);
416 }
417
418 inline ROCKY_FUNCTIONS double get_home_reduced_young_modulus() const
419 {
420 const double home_poisson = get_home_poisson_ratio();
421 return this->get_home_material().kn_load / (1.0 - home_poisson * home_poisson);
422 }
423
424 inline ROCKY_FUNCTIONS double get_near_reduced_young_modulus() const
425 {
426 const double near_poisson = this->is_particle_contact ? get_near_particle_poisson_ratio()
427 : get_near_triangle_poisson_ratio();
428 return this->get_near_material().kn_load / (1.0 - near_poisson * near_poisson);
429 }
430
431 inline ROCKY_FUNCTIONS double get_home_mass() const
432 {
433 return ParticleProperties::get_mass(
434 this->model, this->get_home_particle(), this->get_home_particle_index());
435 }
436
437 inline ROCKY_FUNCTIONS double get_near_mass() const
438 {
439 return ParticleProperties::get_mass(
440 this->model, this->get_near_particle(), this->get_near_particle_index());
441 }
442
443 inline ROCKY_FUNCTIONS double get_home_rebound_coefficient() const
444 {
445 // At discrete breakage when a joint is fully broken there could be significant overlap
446 // of the fragments initially if they are at high stress. The force on this overlap is
447 // supposed to be zero, but it can jump to quite high value if coeff_r is large.
448 // Then, we reduce the rebound coefficient to a value near zero to avoid these fluctuations.
449 if (this->get_home_particle_group().is_breakage_discrete() && this->is_particle_contact
450 && this->model->get_particle_geometry(this->get_home_particle_index()).dgb_parent_index
451 == this->model->get_particle_geometry(this->get_near_particle_index())
452 .dgb_parent_index)
453 {
454 return ROCKY_SMALL_VALUE;
455 }
456 return this->get_home_particle_group().coeff_r;
457 }
458
459 inline ROCKY_FUNCTIONS double get_near_rebound_coefficient() const
460 {
461 // At discrete breakage when a joint is fully broken there could be significant overlap
462 // of the fragments initially if they are at high stress. The force on this overlap is
463 // supposed to be zero, but it can jump to quite high value if coeff_r is large.
464 // Then, we reduce the rebound coefficient to a value near zero to avoid these fluctuations.
465 if (this->is_particle_contact)
466 {
467 if (this->get_near_particle_group().is_breakage_discrete()
468 && this->model->get_particle_geometry(this->get_home_particle_index())
469 .dgb_parent_index
470 == this->model->get_particle_geometry(this->get_near_particle_index())
471 .dgb_parent_index)
472 {
473 return ROCKY_SMALL_VALUE;
474 }
475 return this->get_near_particle_group().coeff_r;
476 }
477 return this->get_near_particle_group().coeff_r;
478 }
479
480 // Composite properties ------------------------------------------------------------------------
481
482 inline ROCKY_FUNCTIONS double get_equivalent_stiffness() const
483 {
484 if (this->get_normal_force_model() != nfmHertzViscous)
485 {
486 double home_stiffness = this->get_home_stiffness();
487 double near_stiffness = this->get_near_stiffness();
488 return (home_stiffness * near_stiffness) / (home_stiffness + near_stiffness);
489 }
490 else // TODO remove this ROCKY-13106
491 {
492 const double sqrt_overlap = sqrt(max(0.0, this->get_overlap()));
493 const double home_size = this->get_home_particle().get_original_size();
494 if (this->is_particle_contact)
495 {
496 const double near_size = this->get_near_particle().get_original_size();
497 return (4.0 / 3.0) * this->get_reduced_young_modulus()
498 * sqrt(0.5 * home_size * near_size / (home_size + near_size)) * sqrt_overlap;
499 }
500 else
501 return (4.0 / 3.0) * this->get_reduced_young_modulus() * sqrt(0.5 * home_size)
502 * sqrt_overlap;
503 }
504 }
505
506 inline ROCKY_FUNCTIONS double get_reduced_young_modulus() const
507 {
508 const double home_reduced_ym = this->get_home_reduced_young_modulus();
509 const double near_reduced_ym = this->get_near_reduced_young_modulus();
510 return (home_reduced_ym * near_reduced_ym) / (home_reduced_ym + near_reduced_ym);
511 }
512
513 inline ROCKY_FUNCTIONS double get_equivalent_mass() const
514 {
515 const double home_mass = this->get_home_mass();
516
517 if (!this->is_particle_contact)
518 return home_mass;
519
520 const double near_mass = this->get_near_mass();
521
522 return (home_mass * near_mass) / (home_mass + near_mass);
523 }
524
525 inline ROCKY_FUNCTIONS double get_equivalent_radius() const
526 {
527 const double home_radius = 0.5 * this->get_home_particle().get_original_size();
528
529 if (!this->is_particle_contact)
530 return home_radius;
531
532 const double near_radius = 0.5 * this->get_near_particle().get_original_size();
533
534 return (home_radius * near_radius) / (home_radius + near_radius);
535 }
536
537 /*
538 This method calculates the damping ratio corresponding to a given coefficient of
539 restitution, by inverting the Schwager & Poschel expression.
540 For more details, please refer to the DEM Technical Manual. The value of this damping ratio
541 is applied within Rocky to the Linear Spring Dashpot and, with some alterations
542 described in the referred manual, to the Hertzian Spring Dashpot normal force
543 contact models.
544 */
545 inline ROCKY_FUNCTIONS double get_damping_ratio(double restitution_coefficient) const
546 {
547 return this->model->poschel_relation->get_damping_ratio(restitution_coefficient);
548 }
549
550 /*
551 Overlap time derivative for models that include viscous damping. Because of stability reasons,
552 for concave particles the time derivative is approximated using the normal relative velocity.
553 */
554 inline ROCKY_FUNCTIONS double get_overlap_time_derivative(
555 const double normal_relative_velocity) const
556 {
557 double previous_overlap = this->get_previous_overlap();
558 const double overlap = this->get_overlap();
559 const double timestep = this->get_timestep();
560 if (this->model->gen->flags.has_concave_particles()
561 && (this->get_state().is_home_simple_composite()
562 || (this->is_particle_contact && this->get_state().is_near_simple_composite())))
563 {
564 previous_overlap = overlap + normal_relative_velocity * timestep;
565 }
566 return (overlap - rocky::dmax(previous_overlap, 0.0)) / timestep;
567 }
568
569 inline ROCKY_FUNCTIONS double get_tangential_stiffness(
570 cuda_contact_intermediate_data& idata) const
571 {
572 const auto mi = this->get_material_interaction();
573 const auto normal_model = this->get_normal_force_model();
574
575 if (normal_model == nfmLinearHysteresis || normal_model == nfmLinearElasticViscous)
576 {
577 return idata.stiffness * mi.kt_kn;
578 }
579 else if (normal_model == ENormalForceModel::nfmHertzViscous)
580 {
581 return 1.5 * idata.stiffness * mi.kt_kn;
582 }
583 else if (this->get_normal_force_model() == nfmCustom)
584 {
585 return this->get_equivalent_stiffness() * mi.kt_kn;
586 }
587 else
588 {
589 assert(0);
590 return 0;
591 }
592 }
593
594 inline ROCKY_FUNCTIONS double get_cgm_average_factor() const
595 {
596 const double home_factor = this->get_home_particle_base_group().cgm_scale_factor;
597
598 if (!this->is_particle_contact)
599 return home_factor;
600
601 const double near_factor = this->get_near_particle_base_group().cgm_scale_factor;
602
603 return (2.0 * home_factor * near_factor) / (home_factor + near_factor);
604 }
605
606 // Normal force model --------------------------------------------------------------------------
607
608 inline ROCKY_FUNCTIONS ENormalForceModel get_normal_force_model() const
609 {
610 return this->model->gen->force_model_norm;
611 }
612
613 inline ROCKY_FUNCTIONS double get_normal_force() const
614 {
615 return this->get_scalars().get_normal_force(this->contact_index);
616 }
617
618 inline ROCKY_FUNCTIONS double get_scaled_normal_force() const
619 {
620 return this->get_normal_force() * this->get_scale();
621 }
622
623 // Tangential force model ----------------------------------------------------------------------
624
625 inline ROCKY_FUNCTIONS ETangentialForceModel get_tangential_force_model() const
626 {
627 return this->model->gen->force_model_tang;
628 }
629
630 inline ROCKY_FUNCTIONS double3 get_tangential_force() const
631 {
632 return this->get_scalars().get_tangential_force_vector(this->contact_index);
633 }
634
635 inline ROCKY_FUNCTIONS double3 get_scaled_tangential_force() const
636 {
637 return this->get_scale() * this->get_tangential_force();
638 }
639
640 // Adhesion force model ------------------------------------------------------------------------
641
642 inline ROCKY_FUNCTIONS EAdhesionModels get_adhesion_model() const
643 {
644 return this->model->gen->adh_model;
645 }
646
647 // Rolling resistance model -------------------------------------------------------------------
648
649 inline ROCKY_FUNCTIONS double3 get_previous_normal_vector() const
650 {
651 return make_double3(this->get_scalars().get_previous_normal_vector(this->contact_index));
652 }
653
654 inline ROCKY_FUNCTIONS double3 get_previous_moment_vector() const
655 {
656 return this->get_scalars().get_previous_moment_vector(this->contact_index);
657 }
658
659 inline ROCKY_FUNCTIONS void set_previous_moment_vector(double3 value)
660 {
661 this->get_scalars().get_previous_moment_vector(this->contact_index) = value;
662 }
663
664 // Basic properties (possibly variables) -------------------------------------------------------
665
666 inline ROCKY_FUNCTIONS double get_restitution_coefficient() const
667 {
668 if (this->get_scalars().has_restitution_coefficient_enabled())
669 {
670 return this->get_scalars().get_restitution_coefficient(this->contact_index);
671 }
672 else
673 {
674 return this->get_material_interaction().rest;
675 }
676 }
677
678 inline ROCKY_FUNCTIONS void set_restitution_coefficient(double value)
679 {
680 this->get_scalars().get_restitution_coefficient(this->contact_index) = value;
681 }
682
683 inline ROCKY_FUNCTIONS double get_dynamic_friction_coefficient() const
684 {
685 if (this->get_scalars().has_dynamic_friction_coefficient())
686 return this->get_scalars().get_dynamic_friction_coefficient(this->contact_index);
687 else
688 return this->get_material_interaction().mu_dn;
689 }
690
691 inline ROCKY_FUNCTIONS void set_dynamic_friction_coefficient(double value)
692 {
693 this->get_scalars().get_dynamic_friction_coefficient(this->contact_index) = value;
694 }
695
696 inline ROCKY_FUNCTIONS double get_static_friction_coefficient() const
697 {
698 if (this->get_scalars().has_static_friction_coefficient())
699 return this->get_scalars().get_static_friction_coefficient(this->contact_index);
700 else
701 return this->get_material_interaction().mu_st;
702 }
703
704 inline ROCKY_FUNCTIONS void set_static_friction_coefficient(double value)
705 {
706 this->get_scalars().get_static_friction_coefficient(this->contact_index) = value;
707 }
708
709 inline ROCKY_FUNCTIONS double get_friction_coefficient(bool is_sliding) const
710 {
711 if (is_sliding)
712 return this->get_dynamic_friction_coefficient();
713 else
714 return this->get_static_friction_coefficient();
715 }
716
717 // Some internal variables exposed as scalars --------------------------------------------------
718
719 inline ROCKY_FUNCTIONS double get_sliding_distance() const
720 {
721 return this->get_scalars().get_known_scalar<double>(
722 KnownContactScalars::SlidingDistance, this->contact_index);
723 }
724
725 inline ROCKY_FUNCTIONS bool get_is_sliding_marker() const
726 {
727 return this->get_scalars().get_known_scalar<bool>(
728 KnownContactScalars::IsSliding, this->contact_index);
729 }
730
731 inline ROCKY_FUNCTIONS double get_normal_relative_velocity() const
732 {
733 return this->get_scalars().get_known_scalar<double>(
734 KnownContactScalars::NormalRelativeVelocity, this->contact_index);
735 }
736
737 inline ROCKY_FUNCTIONS double3 get_tangential_relative_velocity() const
738 {
739 return this->get_scalars().get_known_scalar<double3>(
740 KnownContactScalars::TangentialRelativeVelocity, this->contact_index);
741 }
742
743 inline ROCKY_FUNCTIONS double get_normal_adhesion_force() const
744 {
745 return this->get_scalars().get_known_scalar<double>(
746 KnownContactScalars::NormalAdhesionForce, this->contact_index);
747 }
748
749 inline ROCKY_FUNCTIONS double3 get_tangential_adhesion_force() const
750 {
751 return this->get_scalars().get_known_scalar<double3>(
752 KnownContactScalars::TangentialAdhesionForce, this->contact_index);
753 }
754
755 SDeviceModel* model;
756 int contact_index;
757 mutable int home_particle_index, near_element_index;
758 mutable unsigned short home_material_index, near_material_index, material_interaction_index;
759 mutable unsigned short home_group_index;
760 SContactState state;
761 const bool is_particle_contact;
762
763 ROCKY_FUNCTIONS RockyContact(
764 SDeviceModel* model, const bool is_particle_contact, const int contact_index = -1)
765 : model(model)
766 , is_particle_contact(is_particle_contact)
767 {
768 this->reset(contact_index);
769 }
770
771 ROCKY_FUNCTIONS void reset(const int _contact_index)
772 {
773 this->contact_index = _contact_index;
774 this->home_particle_index = RC_I_INVALID_INDEX;
775 this->near_element_index = RC_I_INVALID_INDEX;
776 this->home_material_index = RC_S_INVALID_INDEX;
777 this->near_material_index = RC_S_INVALID_INDEX;
778 this->material_interaction_index = RC_S_INVALID_INDEX;
779 this->home_group_index = RC_S_INVALID_INDEX;
780 if (this->contact_index > -1)
781 this->state = this->get_scalars().get_state(this->contact_index);
782 else
783 this->state = {};
784 }
785
786 //Deformable values
787 inline ROCKY_FUNCTIONS int get_deformable_particle_vertex_storage_index(int np) const
788 {
789 return this->model->deformable_particle_vertex_storage_index[np];
790 }
791
792 inline ROCKY_FUNCTIONS double3* get_deformable_particle_vertices_velocities(int n_vrt_stor) const
793 {
794 return this->model->deformable_particle_vertex_scalars->get_deformable_vertex_velocity(n_vrt_stor);
795 }
796};
797
798// Keep it small!
799static_assert(sizeof(RockyContact) == 32);
Definition rocky_contact_scalars.hpp:279

Connect with Ansys