Skip to main content

Rocky Solver SDK 2025 R2

rocky_boundary_api

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/core/utils/rocky_math.hpp>
6#include <rocky20/device/device_model.hpp>
7#include <rocky20/device/device_triangles.hpp>
8
9#include "rocky_boundary.hpp"
10
11// ================================================================================================
12// IRockyGeometryTriangleImpl
13// ================================================================================================
14
17template <typename Model>
18struct IRockyGeometryTriangleImpl
19{
20 ROCKY_FUNCTIONS IRockyMaterial get_material() const
21 {
22 return IRockyMaterial(this->_impl.get_material());
23 }
24
25 ROCKY_FUNCTIONS double3 get_normal_unit_vector() const
26 {
27 return this->_impl.get_normal();
28 }
29
30 ROCKY_FUNCTIONS double get_area() const
31 {
32 return this->_impl.get_area();
33 }
34
35 ROCKY_FUNCTIONS double3 get_centroid() const
36 {
37 return this->_impl.get_centroid();
38 }
39
40 ROCKY_FUNCTIONS int get_geometry_index() const
41 {
42 return this->_impl.get_boundary_index();
43 }
44
45 ROCKY_FUNCTIONS int get_material_index() const
46 {
47 return this->_impl.get_material_index();
48 }
49
50 ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const
51 {
52 return this->_impl.get_translational_velocity(current_time);
53 }
54
55 ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const
56 {
57 return this->_impl.get_geometry_rotational_velocity();
58 }
59
60 ROCKY_FUNCTIONS double3 get_triangle_center_velocity(const double current_time) const
61 {
62 return device::get_boundary_velocity_at_contact(
63 this->_impl.get_boundary(),
64 this->_impl.get_boundary_matrix(),
65 this->_impl.get_translational_velocity(current_time),
66 this->_impl.get_centroid(),
67 current_time);
68 }
69
70 ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const
71 {
72 return this->_impl.get_geometry_rotation_center();
73 }
74
75 ROCKY_FUNCTIONS double get_temperature() const
76 {
77 return this->_impl.get_temperature();
78 }
79
80 ROCKY_FUNCTIONS void set_temperature(double value)
81 {
82 this->_impl.set_temperature(value);
83 }
84
85 ROCKY_FUNCTIONS bool is_adiabatic() const
86 {
87 return this->_impl.is_adiabatic();
88 }
89
90 ROCKY_FUNCTIONS double get_thermal_conductivity() const
91 {
92 return this->_impl.get_thermal_conductivity();
93 }
94
95 ROCKY_FUNCTIONS void set_thermal_conductivity(double value)
96 {
97 this->_impl.set_thermal_conductivity(value);
98 }
99
100 ROCKY_FUNCTIONS double get_poisson_ratio() const
101 {
102 return this->_impl.get_poisson_ratio();
103 }
104
105 ROCKY_FUNCTIONS void set_poisson_ratio(double value)
106 {
107 this->_impl.set_poisson_ratio(value);
108 }
109
110 ROCKY_FUNCTIONS IRockyTriangleScalars get_scalars() const
111 {
112 return this->_impl.get_scalars();
113 }
114
115 ROCKY_FUNCTIONS IRockyGeometryTriangleImpl(int _index, Model* _model, bool _current = true)
116 : _impl(_model, _index, _current)
117 {
118 }
119
120 RockyBoundaryTriangle<Model> _impl;
121};
122
126// ================================================================================================
127// IRockyGeometryTriangle
128// ================================================================================================
129
145struct IRockyGeometryTriangle : public IRockyGeometryTriangleImpl<SDeviceModel>
146{
149 ROCKY_FUNCTIONS IRockyGeometryTriangle(int _index, SDeviceModel* _model)
150 : IRockyGeometryTriangleImpl(_index, _model, true)
151 {}
152
155#ifdef ONLY_FOR_DOXYGEN
156
162 ROCKY_FUNCTIONS IRockyMaterial get_material() const;
163
170 ROCKY_FUNCTIONS double3 get_normal_unit_vector() const;
171
175 ROCKY_FUNCTIONS double get_area() const;
176
180 ROCKY_FUNCTIONS double3 get_centroid() const;
181
186 ROCKY_FUNCTIONS int get_geometry_index() const;
187
192 ROCKY_FUNCTIONS int get_material_index() const;
193
201 ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const;
202
207 ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const;
208
213 ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const;
214
223 ROCKY_FUNCTIONS double get_temperature() const;
224
234 ROCKY_FUNCTIONS void set_temperature(double value);
235
240 ROCKY_FUNCTIONS bool is_adiabatic() const;
241
248 ROCKY_FUNCTIONS double get_thermal_conductivity() const;
249
257 ROCKY_FUNCTIONS void set_thermal_conductivity(double value);
258
265 ROCKY_FUNCTIONS double get_poisson_ratio() const;
266
274 ROCKY_FUNCTIONS void set_poisson_ratio(double value);
275
281
282#endif
283
284};
285
286
287// ================================================================================================
288// IRockyGeometryTriangleHost
289// ================================================================================================
290
296struct IRockyGeometryTriangleHost : public IRockyGeometryTriangleImpl<RockyModel>
297{
300 IRockyGeometryTriangleHost(int _index, RockyModel* _model)
301 : IRockyGeometryTriangleImpl(_index, _model, true)
302 {}
303
307#ifdef ONLY_FOR_DOXYGEN
308
310 ROCKY_FUNCTIONS IRockyMaterial get_material() const;
311
313 ROCKY_FUNCTIONS double3 get_normal_unit_vector() const;
314
316 ROCKY_FUNCTIONS double get_area() const;
317
319 ROCKY_FUNCTIONS double3 get_centroid() const;
320
322 ROCKY_FUNCTIONS int get_geometry_index() const;
323
325 ROCKY_FUNCTIONS int get_material_index() const;
326
328 ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const;
329
331 ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const;
332
334 ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const;
335
337 ROCKY_FUNCTIONS double get_temperature() const;
338
340 ROCKY_FUNCTIONS void set_temperature(double value);
341
343 ROCKY_FUNCTIONS bool is_adiabatic() const;
344
346 ROCKY_FUNCTIONS double get_thermal_conductivity() const;
347
349 ROCKY_FUNCTIONS void set_thermal_conductivity(double value);
350
352 ROCKY_FUNCTIONS double get_poisson_ratio() const;
353
355 ROCKY_FUNCTIONS void set_poisson_ratio(double value);
356
359
360#endif
361
362};
363
364// Legacy structs
365
367
369
370
371// ================================================================================================
372// IRockyGeometryMotionData
373// ================================================================================================
374
397{
401 int get_id() const;
402
406 std::string get_name() const;
407
411 double3 get_force() const;
412
416 double3 get_moment() const;
417
421 double3 get_position() const;
422
426 double3 get_translational_velocity() const;
427
431 double4 get_orientation_quaternion() const;
432
438 double3 get_orientation_euler_angles() const;
439
443 double3 get_rotational_velocity() const;
444
456 void set_position(double3 position);
457
466 void set_translational_velocity(double3 v);
467
476 void set_orientation(double4 quat);
477
488 void set_orientation_angles(double3 angles);
489
498 void set_rotational_velocity(double3 w);
499
504 bool has_linked_motion_frame() const;
505
506
509 IRockyGeometryMotionData(unsigned int _index, RockyModel& _model);
510
511 unsigned int geometry_index;
512 RockyModel& model;
513
515};
516
518{
519 return this->geometry_index;
520}
521
522inline std::string IRockyGeometryMotionData::get_name() const
523{
524 return this->model.bnd_h[this->geometry_index].name;
525}
526
528{
529 const cuda_boundary& boundary = this->model.bnd[this->geometry_index];
530 return double3{ boundary.fx_inst, boundary.fy_inst, boundary.fz_inst };
531}
532
534{
535 const cuda_boundary& boundary = this->model.bnd[this->geometry_index];
536 return double3{ boundary.mx_inst, boundary.my_inst, boundary.mz_inst };
537}
538
540{
541 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
542 return double3{ boundary.dx, boundary.dy, boundary.dz };
543}
544
546{
547 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
548 return double3{ boundary.ux, boundary.uy, boundary.uz };
549}
550
552{
553 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
554 return double4{ boundary.quat[0], boundary.quat[1], boundary.quat[2], boundary.quat[3] };
555}
556
558{
559 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
560 const auto& quat = boundary.quat;
561 double3 euler_angles;
562 // roll (x-axis rotation)
563 double sinr_cosp = 2.0 * (quat[0] * quat[1] + quat[2] * quat[3]);
564 double cosr_cosp = 1.0 - 2.0 * (quat[1] * quat[1] + quat[2] * quat[2]);
565 euler_angles.x = std::atan2(sinr_cosp, cosr_cosp);
566
567 // pitch (y-axis rotation)
568 double sinp = 2 * (quat[0] * quat[2] - quat[3] * quat[1]);
569 if (std::abs(sinp) >= 1.0)
570 euler_angles.y = std::copysign(M_PI / 2, sinp); // use 90 degrees if out of range
571 else
572 euler_angles.y = std::asin(sinp);
573
574 // yaw (z-axis rotation)
575 double siny_cosp = 2.0 * (quat[0] * quat[3] + quat[1] * quat[2]);
576 double cosy_cosp = 1.0 - 2.0 * (quat[2] * quat[2] + quat[3] * quat[3]);
577 euler_angles.z = std::atan2(siny_cosp, cosy_cosp);
578
579 return euler_angles;
580}
581
583{
584 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
585 return double3{ boundary.wx, boundary.wy, boundary.wz };
586}
587
592inline void check_write(const IRockyGeometryMotionData* motionData)
593{
594 if (motionData->has_linked_motion_frame())
595 {
596
597 ROCKY_RUNTIME_ERROR(
598 "Cannot overwrite motion data in geometry " << motionData->get_name()
599 << " because it is already linked to a motion frame.\nPlease review your setup.")
600 }
601}
602
604{
605 check_write(this);
606 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
607 boundary.previous_frame_center = boundary.get_current_frame_center();
608 boundary.dx = p.x;
609 boundary.dy = p.y;
610 boundary.dz = p.z;
611}
612
614{
615 check_write(this);
616 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
617 boundary.previous_linear_velocity = boundary.get_linear_velocity();
618 boundary.ux = v.x;
619 boundary.uy = v.y;
620 boundary.uz = v.z;
621}
622
624{
625 check_write(this);
626 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
627 rocky::transform::quaternion_conjugation(boundary.quat);
628 boundary.rotation_delta = rocky::transform::quaternion_product<true>(
629 quat, rocky::transform::cast_quaternion(boundary.quat));
630 boundary.quat[0] = quat.w;
631 boundary.quat[1] = quat.x;
632 boundary.quat[2] = quat.y;
633 boundary.quat[3] = quat.z;
634 SRotationMatrixD::wrap(boundary.a).set_quaternion(boundary.quat);
635}
636
638{
639 check_write(this);
640 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
641 double cos_roll = cos(angles.x / 2.0);
642 double sin_roll = sin(angles.x / 2.0);
643 double cos_pitch = cos(angles.y / 2.0);
644 double sin_pitch = sin(angles.y / 2.0);
645 double cos_yaw = cos(angles.z / 2.0);
646 double sin_yaw = sin(angles.z / 2.0);
647
648 double previous_quat[4] {
649 boundary.quat[0], boundary.quat[1], boundary.quat[2], boundary.quat[3]
650 };
651 rocky::transform::quaternion_conjugation(previous_quat);
652 boundary.quat[0] = cos_roll * cos_pitch * cos_yaw + sin_roll * sin_pitch * sin_yaw;
653 boundary.quat[1] = sin_roll * cos_pitch * cos_yaw - cos_roll * sin_pitch * sin_yaw;
654 boundary.quat[2] = cos_roll * sin_pitch * cos_yaw + sin_roll * cos_pitch * sin_yaw;
655 boundary.quat[3] = cos_roll * cos_pitch * sin_yaw - sin_roll * sin_pitch * cos_yaw;
656 SRotationMatrixD::wrap(boundary.a).set_quaternion(boundary.quat);
657 boundary.rotation_delta = rocky::transform::quaternion_product<true>(
658 rocky::transform::cast_quaternion(boundary.quat),
659 rocky::transform::cast_quaternion(previous_quat));
660}
661
663{
664 check_write(this);
665 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
666 boundary.previous_angular_velocity = boundary.get_angular_velocity();
667 boundary.wx = w.x;
668 boundary.wy = w.y;
669 boundary.wz = w.z;
670}
671
673{
674 return this->model.boundary_has_linked_frame(this->geometry_index);
675}
676
677inline IRockyGeometryMotionData::IRockyGeometryMotionData(unsigned int _index, RockyModel& _model)
678 : model(_model)
679 , geometry_index(_index)
680{
681}
682
683// ================================================================================================
684// IRockyGeometriesMotionData
685// ================================================================================================
686
696{
700 unsigned int get_number_of_geometries() const;
701
710 IRockyGeometryMotionData get_geometry(unsigned int id) const;
711
720 IRockyGeometryMotionData get_geometry(const std::string& name) const;
721
727 bool has_linked_motion_frame(unsigned int id) const;
728
731 IRockyGeometriesMotionData(RockyModel& _model);
732
733 RockyModel& model;
734
736};
737
739{
740 return this->model.gen.nbnd;
741}
742
744{
745 if (id >= (unsigned int)this->model.gen.nbnd)
746 {
747 ROCKY_RUNTIME_ERROR(
748 "IRockyGeometriesMotionData: Not a valid geometry ID, must be less than "
749 << this->model.gen.nbnd << ".")
750 }
751 return IRockyGeometryMotionData(id, this->model);
752}
753
755 const std::string& name) const
756{
757 const auto &begin = this->model.bnd_h.begin();
758 const auto &end = this->model.bnd_h.end();
759 auto it = std::find_if(
760 begin, end, [name](cuda_boundary_host& boundary) {
761 return boundary.name == name;
762 });
763 if (it == end)
764 {
765 ROCKY_RUNTIME_ERROR("IRockyGeometriesMotionData: Not a valid geometry name.")
766 }
767 return IRockyGeometryMotionData((unsigned int)std::distance(begin, it), this->model);
768}
769
771{
772 return this->model.boundary_has_linked_frame(id);
773}
774
775
776inline IRockyGeometriesMotionData::IRockyGeometriesMotionData(RockyModel& _model)
777 : model(_model)
778{
779}
Definition rocky_boundary_api.hpp:696
unsigned int get_number_of_geometries() const
Definition rocky_boundary_api.hpp:738
bool has_linked_motion_frame(unsigned int id) const
Definition rocky_boundary_api.hpp:770
IRockyGeometryMotionData get_geometry(unsigned int id) const
Definition rocky_boundary_api.hpp:743
Definition rocky_boundary_api.hpp:397
bool has_linked_motion_frame() const
Definition rocky_boundary_api.hpp:672
void set_orientation_angles(double3 angles)
Definition rocky_boundary_api.hpp:637
double3 get_translational_velocity() const
Definition rocky_boundary_api.hpp:545
double3 get_orientation_euler_angles() const
Definition rocky_boundary_api.hpp:557
double4 get_orientation_quaternion() const
Definition rocky_boundary_api.hpp:551
int get_id() const
Definition rocky_boundary_api.hpp:517
void set_translational_velocity(double3 v)
Definition rocky_boundary_api.hpp:613
double3 get_force() const
Definition rocky_boundary_api.hpp:527
void set_orientation(double4 quat)
Definition rocky_boundary_api.hpp:623
void set_rotational_velocity(double3 w)
Definition rocky_boundary_api.hpp:662
void set_position(double3 position)
Definition rocky_boundary_api.hpp:603
double3 get_position() const
Definition rocky_boundary_api.hpp:539
double3 get_rotational_velocity() const
Definition rocky_boundary_api.hpp:582
std::string get_name() const
Definition rocky_boundary_api.hpp:522
double3 get_moment() const
Definition rocky_boundary_api.hpp:533
Definition rocky_boundary_api.hpp:297
ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const
ROCKY_FUNCTIONS bool is_adiabatic() const
ROCKY_FUNCTIONS void set_temperature(double value)
ROCKY_FUNCTIONS IRockyTriangleScalars get_scalars()
ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const
ROCKY_FUNCTIONS double get_poisson_ratio() const
ROCKY_FUNCTIONS void set_thermal_conductivity(double value)
ROCKY_FUNCTIONS IRockyMaterial get_material() const
ROCKY_FUNCTIONS void set_poisson_ratio(double value)
ROCKY_FUNCTIONS int get_geometry_index() const
ROCKY_FUNCTIONS int get_material_index() const
ROCKY_FUNCTIONS double get_area() const
ROCKY_FUNCTIONS double get_thermal_conductivity() const
ROCKY_FUNCTIONS double3 get_normal_unit_vector() const
ROCKY_FUNCTIONS double get_temperature() const
ROCKY_FUNCTIONS double3 get_centroid() const
ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const
Definition rocky_boundary_api.hpp:146
ROCKY_FUNCTIONS double get_poisson_ratio() const
ROCKY_FUNCTIONS double3 get_normal_unit_vector() const
ROCKY_FUNCTIONS void set_temperature(double value)
ROCKY_FUNCTIONS double get_temperature() const
ROCKY_FUNCTIONS double3 get_centroid() const
ROCKY_FUNCTIONS IRockyTriangleScalars get_scalars()
ROCKY_FUNCTIONS double get_thermal_conductivity() const
ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const
ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const
ROCKY_FUNCTIONS int get_geometry_index() const
ROCKY_FUNCTIONS double get_area() const
ROCKY_FUNCTIONS int get_material_index() const
ROCKY_FUNCTIONS void set_thermal_conductivity(double value)
ROCKY_FUNCTIONS bool is_adiabatic() const
ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const
ROCKY_FUNCTIONS IRockyMaterial get_material() const
ROCKY_FUNCTIONS void set_poisson_ratio(double value)
Definition rocky_material_api.hpp:21
Definition rocky_triangle_scalars.hpp:161

Connect with Ansys