Skip to main content

Rocky Solver SDK 2024 R2

rocky_boundary

Last update: 17.07.2025
1#pragma once
2
3// Includes =======================================================================================
4#include <rocky20/device/device_model.hpp>
5#include <rocky20/api/device/api_backend.hpp>
6#include <rocky20/api/rocky_material_api.hpp>
7
8#include "rocky_triangle_scalars.hpp"
9
10namespace device {
11
12__host__ __device__ cu_real3 get_boundary_rotational_velocity(
13 const cuda_boundary& boundary, const cuda_boundary_matrix& bnd_matrix);
14
15__host__ __device__ double3 get_conveyor_triangle_translational_velocity(
16 const rocky20::TriangleScalars* triangle_scalars,
17 const cuda_boundary& boundary,
18 int triangle_index,
19 double time_curr);
20}
21
22// ================================================================================================
23// RockyBoundaryTriangle
24// ================================================================================================
25template <typename Model = SDeviceModel>
26struct RockyBoundaryTriangle
27{
28 inline ROCKY_FUNCTIONS int get_global_index() const
29 {
30 return this->triangle->id_g;
31 }
32
36 inline ROCKY_FUNCTIONS int get_local_index() const
37 {
38 return this->triangle->id_g - this->get_boundary().tria_lower_index;
39 }
40
41 inline ROCKY_FUNCTIONS int get_boundary_index() const
42 {
43 int output = this->triangle->ngr - ((this->triangle->ngr < 1000) ? 1 : 1001);
44 return output;
45 }
46
47 inline ROCKY_FUNCTIONS int get_global_vertex_index(const int vertex_idx) const
48 {
49 return (*this->triangle_topology)[vertex_idx];
50 }
51
52 inline ROCKY_FUNCTIONS int get_local_vertex_index(const int vertex_idx) const
53 {
54 return this->get_global_vertex_index(vertex_idx) - this->get_boundary().point_lower_index;
55 }
56
57 inline ROCKY_FUNCTIONS cuda_boundary& get_boundary()
58 {
59 if constexpr (std::is_same_v<Model, RockyModel>)
60 {
61#ifndef __CUDA_ARCH__
62 return this->model->get_boundary(this->get_boundary_index());
63#endif
64 }
65 else
66 {
67 return this->model->get_boundary(this->get_boundary_index());
68 }
69 }
70
71 inline ROCKY_FUNCTIONS const cuda_boundary& get_boundary() const
72 {
73 if constexpr (std::is_same_v<Model, RockyModel>)
74 {
75#ifndef __CUDA_ARCH__
76 return this->model->get_boundary(this->get_boundary_index());
77#endif
78 }
79 else
80 {
81 return this->model->get_boundary(this->get_boundary_index());
82 }
83 }
84
85 inline ROCKY_FUNCTIONS cuda_boundary_matrix& get_boundary_matrix()
86 {
87 return this->model->get_boundary_matrix(this->triangle->nb_mat);
88 }
89
90 inline ROCKY_FUNCTIONS const cuda_boundary_matrix& get_boundary_matrix() const
91 {
92 return this->model->get_boundary_matrix(this->triangle->nb_mat);
93 }
94
95 inline ROCKY_FUNCTIONS cuda_extreme_values get_extremes() const
96 {
97 return this->get_boundary_matrix().get_triangle_extremes(
98 *this->triangle_topology, this->walls_geometry);
99 }
100
101 inline ROCKY_FUNCTIONS void copy_current_coordinates(RockyBoundaryTriangle<Model>& other) const
102 {
103 if (other.model != nullptr)
104 {
105#ifndef __CUDA_ARCH__
106 ROCKY_RUNTIME_ERROR("copy_current_coordinates is designed to work by copying the "
107 "transformed values to a temporary triangle object")
108#else
109 assert(false);
110#endif
111 }
112
113 this->get_boundary_matrix().get_triangle_coordinates(
114 *this->triangle_topology,
115 this->walls_geometry,
116 *other.triangle_topology,
117 other.walls_geometry);
118 }
119
120 // Material ------------------------------------------------------------------------------------
121 inline ROCKY_FUNCTIONS int get_material_index() const
122 {
123 auto& boundary = this->get_boundary();
124 if (this->triangle->ngr <= 1000)
125 return boundary.nmat - 1;
126 else
127 return boundary.nmat_sc - 1;
128 }
129
130 inline ROCKY_FUNCTIONS const cuda_material& get_material() const
131 {
132 int material_index = this->get_material_index();
133 if constexpr (std::is_same_v<Model, RockyModel>)
134 {
135#ifndef __CUDA_ARCH__
136 return this->model->materials[material_index];
137#endif
138 }
139 else
140 {
141 return this->model->materials[material_index];
142 }
143 }
144
145 inline ROCKY_FUNCTIONS double3 get_normal() const
146 {
147 return rocky::vector::get_normal(
148 this->get_vertex(0), this->get_vertex(1), this->get_vertex(2));
149 }
150
151 inline ROCKY_FUNCTIONS const double3& get_vertex(const int index) const
152 {
153 return this->walls_geometry[this->get_global_vertex_index(index)];
154 }
155
156 inline ROCKY_FUNCTIONS void set_vertex(const int index, const double3& vertex)
157 {
158 this->walls_geometry[this->get_global_vertex_index(index)] = vertex;
159 }
160
161 inline ROCKY_FUNCTIONS const Triplet<double>& get_edge_lengths() const
162 {
163 auto scalars = this->get_triangle_scalars();
164 return scalars->get_edge_lengths(this->triangle_index);
165 }
166
167 inline ROCKY_FUNCTIONS Triplet<double>& get_edge_lengths()
168 {
169 auto scalars = this->get_triangle_scalars();
170 return scalars->get_edge_lengths(this->triangle_index);
171 }
172
173 inline ROCKY_FUNCTIONS Triplet<double> compute_edge_lengths() const
174 {
175 return { rocky::vector::get_norm(this->get_edge(1, 0)),
176 rocky::vector::get_norm(this->get_edge(2, 1)),
177 rocky::vector::get_norm(this->get_edge(0, 2)) };
178 }
179
180 inline ROCKY_FUNCTIONS void set_edge_lengths(const Triplet<double>& value)
181 {
182 if (this->model != nullptr)
183 {
184 auto scalars = this->get_triangle_scalars();
185 scalars->get_edge_lengths(this->triangle_index) = value;
186 }
187 }
188
189 inline ROCKY_FUNCTIONS double3 get_edge(const int i0, const int i1) const
190 {
191 return this->get_vertex(i1) - this->get_vertex(i0);
192 }
193
194 inline ROCKY_FUNCTIONS double get_area() const
195 {
196 return 0.5 * rocky::vector::get_norm(cross(this->get_edge(0, 1), this->get_edge(0, 2)));
197 }
198
199 inline ROCKY_FUNCTIONS double3 get_centroid() const
200 {
201 return (this->get_vertex(0) + this->get_vertex(1) + this->get_vertex(2)) / 3.0;
202 }
203
204 inline ROCKY_FUNCTIONS double get_temperature() const
205 {
206 const rocky20::TriangleScalars* scalars = this->get_triangle_scalars();
207 if (scalars != nullptr && scalars->is_temperature_enabled())
208 {
209 return scalars->get_temperature(this->triangle_index);
210 }
211 else
212 {
213 return this->get_boundary().temperature;
214 }
215 }
216
217 inline ROCKY_FUNCTIONS void set_temperature(double value)
218 {
219 this->get_triangle_scalars()->get_temperature(this->triangle_index) = value;
220 }
221
222 inline ROCKY_FUNCTIONS bool is_adiabatic() const
223 {
224 const auto& boundary = this->get_boundary();
225 return boundary.thermal_boundary_condition_type == adiabatic;
226 }
227
228 inline ROCKY_FUNCTIONS double3 get_translational_velocity(double current_time) const
229 {
230 const auto& boundary = this->get_boundary();
231 if (boundary.type == btCustom)
232 {
233 const auto& bnd_matrix = this->get_boundary_matrix();
234 return double3 { bnd_matrix.ux, bnd_matrix.uy, bnd_matrix.uz };
235 }
236 else if (boundary.is_conveyor())
237 return device::get_conveyor_triangle_translational_velocity(
238 this->get_triangle_scalars(), boundary, this->triangle_index, current_time);
239 else
240 return double3 {};
241 }
242
243 inline ROCKY_FUNCTIONS double3 get_geometry_rotational_velocity() const
244 {
245 const auto& boundary = this->get_boundary();
246 const auto& bnd_matrix = this->get_boundary_matrix();
247 return device::get_boundary_rotational_velocity(boundary, bnd_matrix);
248 }
249
250 inline ROCKY_FUNCTIONS double3 get_geometry_rotation_center() const
251 {
252 const auto& boundary = this->get_boundary();
253 if (boundary.type == btCustom)
254 {
255 const auto& bnd_matrix = this->get_boundary_matrix();
256 return double3 { bnd_matrix.dx, bnd_matrix.dy, bnd_matrix.dz };
257 }
258 else
259 return double3 {};
260 }
261
262 inline ROCKY_FUNCTIONS double get_thermal_conductivity() const
263 {
264 const rocky20::TriangleScalars* scalars = this->get_triangle_scalars();
265 if (scalars != nullptr && scalars->is_thermal_conductivity_enabled())
266 return scalars->get_thermal_conductivity(this->triangle_index);
267 else
268 return this->get_material().thermal_conductivity;
269 }
270
271 inline ROCKY_FUNCTIONS void set_thermal_conductivity(double value)
272 {
273 this->get_triangle_scalars()->get_thermal_conductivity(this->triangle_index) = value;
274 }
275
276 inline ROCKY_FUNCTIONS double get_specific_heat() const
277 {
278 const rocky20::TriangleScalars* scalars = this->get_triangle_scalars();
279 if (scalars != nullptr && scalars->is_specific_heat_enabled())
280 return scalars->get_specific_heat(this->triangle_index);
281 else
282 return this->get_material().specific_heat;
283 }
284
285 inline ROCKY_FUNCTIONS void set_specific_heat(double value)
286 {
287 this->get_triangle_scalars()->get_specific_heat(this->triangle_index) = value;
288 }
289
290 inline ROCKY_FUNCTIONS double get_poisson_ratio() const
291 {
292 const rocky20::TriangleScalars* scalars = this->get_triangle_scalars();
293 if (scalars != nullptr && scalars->is_poisson_ratio_enabled())
294 return scalars->get_poisson_ratio(this->triangle_index);
295 else
296 return this->get_material().poisson_ratio;
297 }
298
299 inline ROCKY_FUNCTIONS void set_poisson_ratio(double value)
300 {
301 this->get_triangle_scalars()->get_poisson_ratio(this->triangle_index) = value;
302 }
303
304 inline ROCKY_FUNCTIONS double get_boundary_fraction(
305 const EHandleLocation _location, const unsigned short _handle) const
306 {
307 switch (_location)
308 {
309 case hlVertex:
310 return 1.0 / this->triangle->v_fr[_handle];
311 case hlEdge:
312 return 1.0 / this->triangle->e_fr[_handle];
313 default:
314 return 1.0;
315 }
316 }
317
318 inline ROCKY_FUNCTIONS short get_edge_fraction(const int edge_index) const
319 {
320 return this->triangle->e_fr[edge_index];
321 }
322
323 inline ROCKY_FUNCTIONS short get_vertex_fraction(const int vertex_index) const
324 {
325 return this->triangle->v_fr[vertex_index];
326 }
327
328 inline ROCKY_FUNCTIONS void set_edge_fraction(const int edge_index, const short fraction)
329 {
330 this->triangle->e_fr[edge_index] = fraction;
331 }
332
333 inline ROCKY_FUNCTIONS void set_vertex_fraction(const int vertex_index, const short fraction)
334 {
335 this->triangle->v_fr[vertex_index] = fraction;
336 }
337
338 inline ROCKY_FUNCTIONS void set_all_periodic(const bool allper)
339 {
340 this->triangle->set_all_periodic(allper);
341 }
342
343 inline ROCKY_FUNCTIONS void set_boundary_flat(
344 const EHandleLocation _location, const int _handle, const bool flat)
345 {
346 if (_location == hlVertex)
347 this->triangle->set_vertex_flat(_handle, flat);
348 else if (_location == hlEdge)
349 this->triangle->set_edge_flat(_handle, flat);
350 }
351
352 inline ROCKY_FUNCTIONS bool get_boundary_flat(
353 const EHandleLocation _location, const unsigned short _handle) const
354 {
355 switch (_location)
356 {
357 case hlVertex:
358 return this->triangle->is_vertex_flat(_handle);
359 case hlEdge:
360 return this->triangle->is_edge_flat(_handle);
361 default:
362 return false;
363 }
364 }
365
366 inline ROCKY_FUNCTIONS bool is_all_periodic() const
367 {
368 return this->triangle->all_periodic();
369 }
370
371 inline ROCKY_FUNCTIONS bool active() const
372 {
373 return this->triangle->active();
374 }
375
376 inline ROCKY_FUNCTIONS void set_active(bool active)
377 {
378 this->triangle->set_active(active);
379 }
380
381 inline ROCKY_FUNCTIONS bool is_system_coupling_triangle() const
382 {
383 return this->get_boundary().is_system_coupling_wall();
384 }
385
386 // Scalars ------------------------------------------------------------------------------------
387 inline ROCKY_FUNCTIONS const rocky20::TriangleScalars* get_triangle_scalars() const
388 {
389 if constexpr (std::is_same<Model, RockyModel>::value)
390 return &this->model->triangle_scalars_controller.host_data;
391 else
392 return this->model->triangle_scalars;
393 }
394
395 inline ROCKY_FUNCTIONS rocky20::TriangleScalars* get_triangle_scalars()
396 {
397 if constexpr (std::is_same<Model, RockyModel>::value)
398 return &this->model->triangle_scalars_controller.host_data;
399 else
400 return this->model->triangle_scalars;
401 }
402
403 inline ROCKY_FUNCTIONS IRockyTriangleScalars get_scalars()
404 {
405 return IRockyTriangleScalars(*this->get_triangle_scalars(), this->triangle_index);
406 }
407
408 inline ROCKY_FUNCTIONS RockyBoundaryTriangle(Model* model, int index, bool current = true)
409 : model(model)
410 , triangle_index(index)
411 , triangle(nullptr)
412 , triangle_topology(nullptr)
413 , walls_geometry(nullptr)
414 {
415 if constexpr (std::is_same<Model, RockyModel>::value)
416 {
417#ifndef __CUDA_ARCH__
418 this->triangle = model->triangles.data() + index;
419 this->triangle_topology = model->walls_topology.data() + index;
420 if (current && !model->walls_geometry_current.empty())
421 this->walls_geometry = model->walls_geometry_current.data();
422 else
423 this->walls_geometry = model->walls_geometry_initial.data();
424#endif
425 }
426 else
427 {
428 this->triangle = model->triangles + index;
429 this->triangle_topology = model->walls_topology + index;
430 if (current && model->walls_geometry_current != nullptr)
431 this->walls_geometry = model->walls_geometry_current;
432 else
433 this->walls_geometry = model->walls_geometry_initial;
434 }
435 }
436
437 inline ROCKY_FUNCTIONS RockyBoundaryTriangle(Model& model, int index, bool current = true)
438 : RockyBoundaryTriangle(&model, index, current)
439 {
440 }
441
442 inline ROCKY_FUNCTIONS RockyBoundaryTriangle(
443 const Triplet<uint32_t>* triangle_topology, double3* triangle_geometry)
444 : model(nullptr)
445 , triangle_index(-1)
446 , triangle(nullptr)
447 , triangle_topology(triangle_topology)
448 , walls_geometry(triangle_geometry)
449 {
450 }
451
452 int triangle_index;
453 cuda_triangle_old* triangle;
454 const Triplet<uint32_t>* __restrict__ triangle_topology;
455 double3* walls_geometry;
456
457 Model *model;
458};
459
460using RockyTriangle = RockyBoundaryTriangle<SDeviceModel>;
461using RockyHostTriangle = RockyBoundaryTriangle<RockyModel>;
Definition rocky_triangle_scalars.hpp:160

Connect with Ansys