Skip to main content

Rocky Solver SDK 2025 R2

rocky_boundary

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

Connect with Ansys