Skip to main content

Rocky Solver SDK 2024 R2

rocky_boundary_api

Last update: 17.07.2025
1#pragma once
2
3// Includes =======================================================================================
4#include <rocky20/core/utils/rocky_math.hpp>
5#include <rocky20/device/device_model.hpp>
6
7#include "rocky_boundary.hpp"
8
9// ================================================================================================
10// IRockyGeometryTriangleImpl
11// ================================================================================================
12
15template <typename Model>
16struct IRockyGeometryTriangleImpl
17{
18 ROCKY_FUNCTIONS IRockyMaterial get_material() const
19 {
20 return IRockyMaterial(this->_impl.get_material());
21 }
22
23 ROCKY_FUNCTIONS double3 get_normal_unit_vector() const
24 {
25 return this->_impl.get_normal();
26 }
27
28 ROCKY_FUNCTIONS double get_area() const
29 {
30 return this->_impl.get_area();
31 }
32
33 ROCKY_FUNCTIONS double3 get_centroid() const
34 {
35 return this->_impl.get_centroid();
36 }
37
38 ROCKY_FUNCTIONS int get_geometry_index() const
39 {
40 return this->_impl.get_boundary_index();
41 }
42
43 ROCKY_FUNCTIONS int get_material_index() const
44 {
45 return this->_impl.get_material_index();
46 }
47
48 ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const
49 {
50 return this->_impl.get_translational_velocity(current_time);
51 }
52
53 ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const
54 {
55 return this->_impl.get_geometry_rotational_velocity();
56 }
57
58 ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const
59 {
60 return this->_impl.get_geometry_rotation_center();
61 }
62
63 ROCKY_FUNCTIONS double get_temperature() const
64 {
65 return this->_impl.get_temperature();
66 }
67
68 ROCKY_FUNCTIONS void set_temperature(double value)
69 {
70 this->_impl.set_temperature(value);
71 }
72
73 ROCKY_FUNCTIONS bool is_adiabatic() const
74 {
75 return this->_impl.is_adiabatic();
76 }
77
78 ROCKY_FUNCTIONS double get_thermal_conductivity() const
79 {
80 return this->_impl.get_thermal_conductivity();
81 }
82
83 ROCKY_FUNCTIONS void set_thermal_conductivity(double value)
84 {
85 this->_impl.set_thermal_conductivity(value);
86 }
87
88 ROCKY_FUNCTIONS double get_poisson_ratio() const
89 {
90 return this->_impl.get_poisson_ratio();
91 }
92
93 ROCKY_FUNCTIONS void set_poisson_ratio(double value)
94 {
95 this->_impl.set_poisson_ratio(value);
96 }
97
98 ROCKY_FUNCTIONS IRockyTriangleScalars get_scalars()
99 {
100 return this->_impl.get_scalars();
101 }
102
103 ROCKY_FUNCTIONS IRockyGeometryTriangleImpl(int _index, Model* _model, bool _current = true)
104 : _impl(_model, _index, _current)
105 {
106 }
107
108 RockyBoundaryTriangle<Model> _impl;
109};
110
114// ================================================================================================
115// IRockyGeometryTriangle
116// ================================================================================================
117
133struct IRockyGeometryTriangle : public IRockyGeometryTriangleImpl<SDeviceModel>
134{
137 ROCKY_FUNCTIONS IRockyGeometryTriangle(int _index, SDeviceModel* _model)
138 : IRockyGeometryTriangleImpl(_index, _model, true)
139 {}
140
143#ifdef ONLY_FOR_DOXYGEN
144
150 ROCKY_FUNCTIONS IRockyMaterial get_material() const;
151
158 ROCKY_FUNCTIONS double3 get_normal_unit_vector() const;
159
163 ROCKY_FUNCTIONS double get_area() const;
164
168 ROCKY_FUNCTIONS double3 get_centroid() const;
169
174 ROCKY_FUNCTIONS int get_geometry_index() const;
175
180 ROCKY_FUNCTIONS int get_material_index() const;
181
189 ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const;
190
195 ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const;
196
201 ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const;
202
211 ROCKY_FUNCTIONS double get_temperature() const;
212
222 ROCKY_FUNCTIONS void set_temperature(double value);
223
228 ROCKY_FUNCTIONS bool is_adiabatic() const;
229
236 ROCKY_FUNCTIONS double get_thermal_conductivity() const;
237
245 ROCKY_FUNCTIONS void set_thermal_conductivity(double value);
246
253 ROCKY_FUNCTIONS double get_poisson_ratio() const;
254
262 ROCKY_FUNCTIONS void set_poisson_ratio(double value);
263
269
270#endif
271
272};
273
274
275// ================================================================================================
276// IRockyGeometryTriangleHost
277// ================================================================================================
278
284struct IRockyGeometryTriangleHost : public IRockyGeometryTriangleImpl<RockyModel>
285{
288 IRockyGeometryTriangleHost(int _index, RockyModel* _model)
289 : IRockyGeometryTriangleImpl(_index, _model, true)
290 {}
291
295#ifdef ONLY_FOR_DOXYGEN
296
298 ROCKY_FUNCTIONS IRockyMaterial get_material() const;
299
301 ROCKY_FUNCTIONS double3 get_normal_unit_vector() const;
302
304 ROCKY_FUNCTIONS double get_area() const;
305
307 ROCKY_FUNCTIONS double3 get_centroid() const;
308
310 ROCKY_FUNCTIONS int get_geometry_index() const;
311
313 ROCKY_FUNCTIONS int get_material_index() const;
314
316 ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const;
317
319 ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const;
320
322 ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const;
323
325 ROCKY_FUNCTIONS double get_temperature() const;
326
328 ROCKY_FUNCTIONS void set_temperature(double value);
329
331 ROCKY_FUNCTIONS bool is_adiabatic() const;
332
334 ROCKY_FUNCTIONS double get_thermal_conductivity() const;
335
337 ROCKY_FUNCTIONS void set_thermal_conductivity(double value);
338
340 ROCKY_FUNCTIONS double get_poisson_ratio() const;
341
343 ROCKY_FUNCTIONS void set_poisson_ratio(double value);
344
347
348#endif
349
350};
351
352// Legacy structs
353
355
357
358
359// ================================================================================================
360// IRockyGeometryMotionData
361// ================================================================================================
362
385{
389 int get_id() const;
390
394 std::string get_name() const;
395
399 double3 get_force() const;
400
404 double3 get_moment() const;
405
409 double3 get_position() const;
410
414 double3 get_translational_velocity() const;
415
419 double4 get_orientation_quaternion() const;
420
426 double3 get_orientation_euler_angles() const;
427
431 double3 get_rotational_velocity() const;
432
444 void set_position(double3 position);
445
454 void set_translational_velocity(double3 v);
455
464 void set_orientation(double4 quat);
465
476 void set_orientation_angles(double3 angles);
477
486 void set_rotational_velocity(double3 w);
487
492 bool has_linked_motion_frame() const;
493
494
497 IRockyGeometryMotionData(unsigned int _index, RockyModel& _model);
498
499 unsigned int geometry_index;
500 RockyModel& model;
501
503};
504
506{
507 return this->geometry_index;
508}
509
510inline std::string IRockyGeometryMotionData::get_name() const
511{
512 return this->model.bnd_h[this->geometry_index].name;
513}
514
516{
517 const cuda_boundary& boundary = this->model.bnd[this->geometry_index];
518 return double3{ boundary.fx_inst, boundary.fy_inst, boundary.fz_inst };
519}
520
522{
523 const cuda_boundary& boundary = this->model.bnd[this->geometry_index];
524 return double3{ boundary.mx_inst, boundary.my_inst, boundary.mz_inst };
525}
526
528{
529 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
530 return double3{ boundary.dx, boundary.dy, boundary.dz };
531}
532
534{
535 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
536 return double3{ boundary.ux, boundary.uy, boundary.uz };
537}
538
540{
541 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
542 return double4{ boundary.quat[0], boundary.quat[1], boundary.quat[2], boundary.quat[3] };
543}
544
546{
547 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
548 const auto& quat = boundary.quat;
549 double3 euler_angles;
550 // roll (x-axis rotation)
551 double sinr_cosp = 2.0 * (quat[0] * quat[1] + quat[2] * quat[3]);
552 double cosr_cosp = 1.0 - 2.0 * (quat[1] * quat[1] + quat[2] * quat[2]);
553 euler_angles.x = std::atan2(sinr_cosp, cosr_cosp);
554
555 // pitch (y-axis rotation)
556 double sinp = 2 * (quat[0] * quat[2] - quat[3] * quat[1]);
557 if (std::abs(sinp) >= 1.0)
558 euler_angles.y = std::copysign(M_PI / 2, sinp); // use 90 degrees if out of range
559 else
560 euler_angles.y = std::asin(sinp);
561
562 // yaw (z-axis rotation)
563 double siny_cosp = 2.0 * (quat[0] * quat[3] + quat[1] * quat[2]);
564 double cosy_cosp = 1.0 - 2.0 * (quat[2] * quat[2] + quat[3] * quat[3]);
565 euler_angles.z = std::atan2(siny_cosp, cosy_cosp);
566
567 return euler_angles;
568}
569
571{
572 const cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
573 return double3{ boundary.wx, boundary.wy, boundary.wz };
574}
575
580inline void check_write(const IRockyGeometryMotionData* motionData)
581{
582 if (motionData->has_linked_motion_frame())
583 {
584
585 ROCKY_RUNTIME_ERROR(
586 "Cannot overwrite motion data in geometry " << motionData->get_name()
587 << " because it is already linked to a motion frame.\nPlease review your setup.")
588 }
589}
590
592{
593 check_write(this);
594 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
595 boundary.previous_frame_center = boundary.get_current_frame_center();
596 boundary.dx = p.x;
597 boundary.dy = p.y;
598 boundary.dz = p.z;
599}
600
602{
603 check_write(this);
604 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
605 boundary.previous_linear_velocity = boundary.get_linear_velocity();
606 boundary.ux = v.x;
607 boundary.uy = v.y;
608 boundary.uz = v.z;
609}
610
612{
613 check_write(this);
614 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
615 rocky::transform::quaternion_conjugation(boundary.quat);
616 boundary.rotation_delta = rocky::transform::quaternion_product<double4, true>(
617 quat, rocky::transform::cast_quaternion(boundary.quat));
618 boundary.quat[0] = quat.w;
619 boundary.quat[1] = quat.x;
620 boundary.quat[2] = quat.y;
621 boundary.quat[3] = quat.z;
622 SRotationMatrixD::wrap(boundary.a).set_quaternion(boundary.quat);
623}
624
626{
627 check_write(this);
628 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
629 double cos_roll = cos(angles.x / 2.0);
630 double sin_roll = sin(angles.x / 2.0);
631 double cos_pitch = cos(angles.y / 2.0);
632 double sin_pitch = sin(angles.y / 2.0);
633 double cos_yaw = cos(angles.z / 2.0);
634 double sin_yaw = sin(angles.z / 2.0);
635
636 double previous_quat[4] {
637 boundary.quat[0], boundary.quat[1], boundary.quat[2], boundary.quat[3]
638 };
639 rocky::transform::quaternion_conjugation(previous_quat);
640 boundary.quat[0] = cos_roll * cos_pitch * cos_yaw + sin_roll * sin_pitch * sin_yaw;
641 boundary.quat[1] = sin_roll * cos_pitch * cos_yaw - cos_roll * sin_pitch * sin_yaw;
642 boundary.quat[2] = cos_roll * sin_pitch * cos_yaw + sin_roll * cos_pitch * sin_yaw;
643 boundary.quat[3] = cos_roll * cos_pitch * sin_yaw - sin_roll * sin_pitch * cos_yaw;
644 SRotationMatrixD::wrap(boundary.a).set_quaternion(boundary.quat);
645 boundary.rotation_delta = rocky::transform::quaternion_product<double4, true>(
646 rocky::transform::cast_quaternion(boundary.quat),
647 rocky::transform::cast_quaternion(previous_quat));
648}
649
651{
652 check_write(this);
653 cuda_boundary_host& boundary = this->model.bnd_h[this->geometry_index];
654 boundary.previous_angular_velocity = boundary.get_angular_velocity();
655 boundary.wx = w.x;
656 boundary.wy = w.y;
657 boundary.wz = w.z;
658}
659
661{
662 return this->model.boundary_has_linked_frame(this->geometry_index);
663}
664
665inline IRockyGeometryMotionData::IRockyGeometryMotionData(unsigned int _index, RockyModel& _model)
666 : model(_model)
667 , geometry_index(_index)
668{
669}
670
671// ================================================================================================
672// IRockyGeometriesMotionData
673// ================================================================================================
674
684{
688 unsigned int get_number_of_geometries() const;
689
698 IRockyGeometryMotionData get_geometry(unsigned int id) const;
699
708 IRockyGeometryMotionData get_geometry(const std::string& name) const;
709
715 bool has_linked_motion_frame(unsigned int id) const;
716
719 IRockyGeometriesMotionData(RockyModel& _model);
720
721 RockyModel& model;
722
724};
725
727{
728 return this->model.gen.nbnd;
729}
730
732{
733 if (id >= (unsigned int)this->model.gen.nbnd)
734 {
735 ROCKY_RUNTIME_ERROR(
736 "IRockyGeometriesMotionData: Not a valid geometry ID, must be less than "
737 << this->model.gen.nbnd << ".")
738 }
739 return IRockyGeometryMotionData(id, this->model);
740}
741
743 const std::string& name) const
744{
745 const auto &begin = this->model.bnd_h.begin();
746 const auto &end = this->model.bnd_h.end();
747 auto it = std::find_if(
748 begin, end, [name](cuda_boundary_host& boundary) {
749 return boundary.name == name;
750 });
751 if (it == end)
752 {
753 ROCKY_RUNTIME_ERROR("IRockyGeometriesMotionData: Not a valid geometry name.")
754 }
755 return IRockyGeometryMotionData((unsigned int)std::distance(begin, it), this->model);
756}
757
759{
760 return this->model.boundary_has_linked_frame(id);
761}
762
763
764inline IRockyGeometriesMotionData::IRockyGeometriesMotionData(RockyModel& _model)
765 : model(_model)
766{
767}
Definition rocky_boundary_api.hpp:684
unsigned int get_number_of_geometries() const
Definition rocky_boundary_api.hpp:726
bool has_linked_motion_frame(unsigned int id) const
Definition rocky_boundary_api.hpp:758
IRockyGeometryMotionData get_geometry(unsigned int id) const
Definition rocky_boundary_api.hpp:731
Definition rocky_boundary_api.hpp:385
bool has_linked_motion_frame() const
Definition rocky_boundary_api.hpp:660
void set_orientation_angles(double3 angles)
Definition rocky_boundary_api.hpp:625
double3 get_translational_velocity() const
Definition rocky_boundary_api.hpp:533
double3 get_orientation_euler_angles() const
Definition rocky_boundary_api.hpp:545
double4 get_orientation_quaternion() const
Definition rocky_boundary_api.hpp:539
int get_id() const
Definition rocky_boundary_api.hpp:505
void set_translational_velocity(double3 v)
Definition rocky_boundary_api.hpp:601
double3 get_force() const
Definition rocky_boundary_api.hpp:515
void set_orientation(double4 quat)
Definition rocky_boundary_api.hpp:611
void set_rotational_velocity(double3 w)
Definition rocky_boundary_api.hpp:650
void set_position(double3 position)
Definition rocky_boundary_api.hpp:591
double3 get_position() const
Definition rocky_boundary_api.hpp:527
double3 get_rotational_velocity() const
Definition rocky_boundary_api.hpp:570
std::string get_name() const
Definition rocky_boundary_api.hpp:510
double3 get_moment() const
Definition rocky_boundary_api.hpp:521
Definition rocky_boundary_api.hpp:285
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:134
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:20
Definition rocky_triangle_scalars.hpp:160

Connect with Ansys