Skip to main content

Rocky Solver SDK 2025 R2

rocky_sph_element

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/api/device/api_backend.hpp>
6#include <rocky20/api/rocky_particle.hpp>
7#include <rocky20/device/device_model.hpp>
8#include <rocky20/sph/sph_model.h>
9
10// ================================================================================================
11// RockySPHElement
12// ================================================================================================
13
14struct RockySPHElement
15{
16 inline ROCKY_FUNCTIONS bool is_dem_coupled() const
17 {
18 return this->get_linked_dem_index() >= 0;
19 }
20
21 inline ROCKY_FUNCTIONS int get_linked_dem_index() const
22 {
23 if (this->get_scalars()->is_dem_index_enabled())
24 return this->get_scalars()->get_dem_index(this->element_index);
25 return -1;
26 }
27
28 inline ROCKY_FUNCTIONS void set_linked_dem_index(const int index)
29 {
30 this->get_scalars()->get_dem_index(this->element_index) = index;
31 }
32
33 inline ROCKY_FUNCTIONS RockyParticle get_linked_dem_particle(SDeviceModel* model) const
34 {
35 return { model, this->get_linked_dem_index() };
36 }
37
38 inline RockyParticle get_linked_dem_particle(cuda_host& model) const
39 {
40 return { model, this->get_linked_dem_index() };
41 }
42
43 inline ROCKY_FUNCTIONS int get_inlet_index() const
44 {
45 if (this->get_scalars()->is_inlet_index_enabled())
46 return this->get_scalars()->get_inlet_index(this->element_index);
47 return 0;
48 }
49
50 inline ROCKY_FUNCTIONS void set_inlet_index(const int index)
51 {
52 this->get_scalars()->get_inlet_index(this->element_index) = short(index);
53 }
54
55 inline ROCKY_FUNCTIONS float get_density() const
56 {
57 return this->get_scalars()->get_density(this->element_index);
58 }
59
60 inline ROCKY_FUNCTIONS void set_density(const float density)
61 {
62 this->get_scalars()->get_density(this->element_index) = density;
63 }
64
65 inline ROCKY_FUNCTIONS float get_pressure() const
66 {
67 const cuda_general_sph& gen = *this->sph_model->gen_sph;
68 if (gen.is_solver_incompressible())
69 return this->get_scalars()->get_pressure(this->element_index);
70 else
71 return gen.get_pressure(this->get_density());
72 }
73
77 inline ROCKY_FUNCTIONS void set_pressure(const float pressure)
78 {
79 this->get_scalars()->get_pressure(this->element_index) = pressure;
80 }
81
82 inline ROCKY_FUNCTIONS float get_release_time() const
83 {
84 return this->get_scalars()->get_release_time(this->element_index);
85 }
86
87 inline ROCKY_FUNCTIONS void set_release_time(float release_time)
88 {
89 this->get_scalars()->get_release_time(this->element_index) = release_time;
90 }
91
92 inline ROCKY_FUNCTIONS float3 get_adjusted_coordinates(const double current_time) const
93 {
94 real_sph3 crd = this->get_coordinates();
95 if (!this->is_released())
96 crd = crd + this->get_velocity() * (float(current_time) - this->get_release_time());
97 return crd;
98 }
99
100 inline ROCKY_FUNCTIONS const float3& get_coordinates() const
101 {
102 return this->get_scalars()->get_coordinates(this->element_index);
103 }
104
105 inline ROCKY_FUNCTIONS void set_coordinates(const float3& coordinates)
106 {
107 this->get_scalars()->get_coordinates(this->element_index) = coordinates;
108 }
109
110 inline ROCKY_FUNCTIONS const float3& get_velocity() const
111 {
112 return this->get_scalars()->get_velocity(this->element_index);
113 }
114
115 inline ROCKY_FUNCTIONS void set_velocity(const float3& velocity)
116 {
117 this->get_scalars()->get_velocity(this->element_index) = velocity;
118 }
119
133 inline ROCKY_FUNCTIONS const float3& get_normal() const
134 {
135 return this->sph_model->nrm_sph[this->element_index];
136 }
137
138 inline ROCKY_FUNCTIONS void set_normal(const float3& normal)
139 {
140 this->sph_model->nrm_sph[this->element_index] = normal;
141 }
142
143 inline ROCKY_FUNCTIONS void add_normal(const float3& normal)
144 {
145 float3& prt_normal = this->sph_model->nrm_sph[this->element_index];
146 backend::atomic_add(&prt_normal, normal);
147 }
148
149 inline ROCKY_FUNCTIONS float get_divergence() const
150 {
151 return this->sph_model->div_sph[this->element_index];
152 }
153
154 inline ROCKY_FUNCTIONS void set_divergence(const float divergence)
155 {
156 this->sph_model->div_sph[this->element_index] = divergence;
157 }
158
159 inline ROCKY_FUNCTIONS void add_divergence(const float divergence)
160 {
161 float& prt_divergence = this->sph_model->div_sph[this->element_index];
162 backend::atomic_add(&prt_divergence, divergence);
163 }
164
165 inline ROCKY_FUNCTIONS const float3& get_boundary_normal() const
166 {
167 return this->sph_model->nrb_sph[this->element_index];
168 }
169
170 inline ROCKY_FUNCTIONS void set_boundary_normal(const float3& boundary_normal)
171 {
172 this->sph_model->nrb_sph[this->element_index] = boundary_normal;
173 }
174
175 inline ROCKY_FUNCTIONS void add_boundary_normal(const float3& boundary_normal)
176 {
177 float3& prt_boundary_normal = this->sph_model->nrb_sph[this->element_index];
178 backend::atomic_add(&prt_boundary_normal, boundary_normal);
179 }
180
181 inline ROCKY_FUNCTIONS float get_boundary_proximity() const
182 {
183 return this->sph_model->fbd_sph[this->element_index];
184 }
185
186 inline ROCKY_FUNCTIONS void set_boundary_proximity(const float boundary_proximity)
187 {
188 this->sph_model->fbd_sph[this->element_index] = boundary_proximity;
189 }
190
191 inline ROCKY_FUNCTIONS void add_boundary_proximity(const float boundary_proximity)
192 {
193 float& prt_boundary_proximity = this->sph_model->fbd_sph[this->element_index];
194 backend::atomic_add(&prt_boundary_proximity, boundary_proximity);
195 }
196
197 inline ROCKY_FUNCTIONS float get_kernel_density() const
198 {
199 return this->sph_model->kernel_density[this->element_index];
200 }
201
202 inline ROCKY_FUNCTIONS void set_kernel_density(const float kernel_density)
203 {
204 this->sph_model->kernel_density[this->element_index] = kernel_density;
205 }
206
207 inline ROCKY_FUNCTIONS void add_kernel_density(const float kernel_density)
208 {
209 float& prt_kernel_density = this->sph_model->kernel_density[this->element_index];
210 backend::atomic_add(&prt_kernel_density, kernel_density);
211 }
212
213 inline ROCKY_FUNCTIONS float get_predicted_density() const
214 {
215 return this->sph_model->predicted_density[this->element_index];
216 }
217
218 inline ROCKY_FUNCTIONS void set_predicted_density(const float predicted_density)
219 {
220 this->sph_model->predicted_density[this->element_index] = predicted_density;
221 }
222
223 inline ROCKY_FUNCTIONS void add_predicted_density(const float predicted_density)
224 {
225 float& prt_predicted_density = this->sph_model->predicted_density[this->element_index];
226 backend::atomic_add(&prt_predicted_density, predicted_density);
227 }
228
229 inline ROCKY_FUNCTIONS float get_coefficients_a() const
230 {
231 return this->sph_model->coefficients_a[this->element_index];
232 }
233
234 inline ROCKY_FUNCTIONS void set_coefficients_a(const float coefficients_a)
235 {
236 this->sph_model->coefficients_a[this->element_index] = coefficients_a;
237 }
238
239 inline ROCKY_FUNCTIONS void add_coefficients_a(const float coefficients_a)
240 {
241 float& prt_coefficients_a = this->sph_model->coefficients_a[this->element_index];
242 backend::atomic_add(&prt_coefficients_a, coefficients_a);
243 }
244
245 inline ROCKY_FUNCTIONS const float3& get_coefficients_d() const
246 {
247 return this->sph_model->coefficients_d[this->element_index];
248 }
249
250 inline ROCKY_FUNCTIONS void set_coefficients_d(const float3& coefficients_d)
251 {
252 this->sph_model->coefficients_d[this->element_index] = coefficients_d;
253 }
254
255 inline ROCKY_FUNCTIONS void add_coefficients_d(const float3& coefficients_d)
256 {
257 float3& prt_coefficients_d = this->sph_model->coefficients_d[this->element_index];
258 backend::atomic_add(&prt_coefficients_d, coefficients_d);
259 }
260
261 inline ROCKY_FUNCTIONS float3 get_force() const
262 {
263 // For SPH elements, the force vector actually holds acceleration in those elements.
264 // For the sake of uniformity throughout our SPH-DEM APIs, we return here a force.
265 return this->get_acceleration() * this->get_mass();
266 }
267
268 inline ROCKY_FUNCTIONS const float3& get_acceleration() const
269 {
270 // For SPH elements, the force vector actually holds acceleration in those elements.
271 return this->get_scalars()->get_acceleration(this->element_index);
272 }
273
277 inline ROCKY_FUNCTIONS const float3& get_position_correction_velocity() const
278 {
279 return this->get_acceleration();
280 }
281
282 inline ROCKY_FUNCTIONS void add_force(const float3& f)
283 {
284 // For SPH elements, the force vector actually holds acceleration in those elements.
285 // For the sake of uniformity throughout our SPH-DEM APIs, we receive here a force,
286 // and therefore must extract the acceleration from it.
287 this->add_acceleration(f / this->get_mass());
288 }
289
290 inline ROCKY_FUNCTIONS float get_mass() const
291 {
292 return this->sph_model->gen_sph->get_mass(this->element_index, this->_refinement_count());
293 }
294
295 inline ROCKY_FUNCTIONS void add_acceleration(const float3& a)
296 {
297 // For SPH elements, the force vector actually holds acceleration in those elements.
298 float3& prt_forces = this->get_scalars()->get_acceleration(this->element_index);
299 backend::atomic_add(&prt_forces, a);
300 }
301
302 inline ROCKY_FUNCTIONS void set_acceleration(const float3& a)
303 {
304 this->get_scalars()->get_acceleration(this->element_index) = a;
305 }
306
307 inline ROCKY_FUNCTIONS PeriodicPosition get_periodic_position() const
308 {
309 if (this->get_scalars()->is_periodic_position_enabled())
310 return this->get_scalars()->get_periodic_position(this->element_index);
311 return { PeriodicPosition::NoFlags };
312 }
313
314 inline ROCKY_FUNCTIONS void set_periodic_position(const PeriodicPosition periodic)
315 {
316 this->get_scalars()->get_periodic_position(this->element_index) = periodic;
317 }
318
319 inline ROCKY_FUNCTIONS void reset_periodic_position()
320 {
321 if (this->get_scalars()->is_periodic_position_enabled())
322 this->get_scalars()->get_periodic_position(this->element_index).reset();
323 }
324
325 inline ROCKY_FUNCTIONS int get_gpu_id() const
326 {
327 if (this->get_scalars()->is_gpu_index_enabled())
328 return this->get_scalars()->get_gpu_index(this->element_index);
329 return 0;
330 }
331
332 inline ROCKY_FUNCTIONS void set_gpu_id(const int gpu_id)
333 {
334 this->get_scalars()->get_gpu_index(this->element_index) = int8_t(gpu_id);
335 }
336
337 inline ROCKY_FUNCTIONS int get_global_index() const
338 {
339 return this->get_scalars()->get_global_index(this->element_index);
340 }
341
342 inline ROCKY_FUNCTIONS void set_global_index(const int index)
343 {
344 this->get_scalars()->get_global_index(this->element_index) = index;
345 }
346
347 // General methods bindings --------------------------------------------------------------------
348
349 inline ROCKY_FUNCTIONS float get_size() const
350 {
351 return this->sph_model->gen_sph->get_dist(
352 this->element_index, this->_refinement_kernel_base());
353 }
354
355 inline ROCKY_FUNCTIONS float get_stiffness() const
356 {
357 return this->sph_model->gen_sph->get_stiff(
358 this->element_index, this->_refinement_kernel_base());
359 }
360
361 inline ROCKY_FUNCTIONS float get_dissipation() const
362 {
363 return this->sph_model->gen_sph->get_diss(
364 this->element_index, this->_refinement_kernel_base(), this->_refinement_count());
365 }
366
367 inline ROCKY_FUNCTIONS float get_minimum_distance() const
368 {
369 return this->sph_model->gen_sph->get_minimum_distance();
370 }
371
372 inline ROCKY_FUNCTIONS float get_minimum_distance_squared() const
373 {
374 return this->sph_model->gen_sph->get_minimum_distance_squared();
375 }
376
377 inline ROCKY_FUNCTIONS bool is_refinement_daughter() const
378 {
379 if (this->use_refinement && (this->sph_model->gen_sph->nprt_refinement_daughters > 0))
380 {
381 const int ig_diff =
382 this->get_global_index() - this->sph_model->gen_sph->refinement_daughters_start;
383
384 return (
385 (ig_diff >= 0) && (ig_diff < this->sph_model->gen_sph->nprt_refinement_daughters));
386 }
387 else
388 return false;
389 }
390
391 inline ROCKY_FUNCTIONS real_sph get_kernel_refinement_multiplier() const
392 {
393 if (this->is_refinement_daughter())
394 {
395 return 1.0f + this->sph_model->gen_sph->refinement_blending_fraction;
396 }
397 else
398 return 1.0f;
399 }
400
401 inline ROCKY_FUNCTIONS float get_kernel_base() const
402 {
403 return this->sph_model->gen_sph->get_kern_base_single(
404 this->element_index, this->get_kernel_refinement_multiplier(), this->_refinement_kernel_base());
405 }
406
407 inline ROCKY_FUNCTIONS float get_kernel_base(const RockySPHElement& near_element) const
408 {
409 return this->sph_model->gen_sph->get_kern_base_pair(
410 this->element_index,
411 near_element.element_index,
412 this->get_kernel_refinement_multiplier(),
413 near_element.get_kernel_refinement_multiplier(),
414 this->_refinement_kernel_base());
415 }
416
417 inline ROCKY_FUNCTIONS float get_kernel(const float distance) const
418 {
419 return this->sph_model->gen_sph->get_kernel_single(
420 distance,
421 this->element_index,
422 this->get_kernel_refinement_multiplier(),
423 this->_refinement_kernel_base());
424 }
425
426 inline ROCKY_FUNCTIONS float get_kernel(
427 const float distance, const RockySPHElement& near_element) const
428 {
429 return this->sph_model->gen_sph->get_kernel_pair(
430 distance,
431 this->element_index,
432 near_element.element_index,
433 this->get_kernel_refinement_multiplier(),
434 near_element.get_kernel_refinement_multiplier(),
435 this->_refinement_kernel_base());
436 }
437
438 inline ROCKY_FUNCTIONS float get_kernel_radius() const
439 {
440 return this->sph_model->gen_sph->get_kernel_radius_single(
441 this->element_index,
442 this->get_kernel_refinement_multiplier(),
443 this->_refinement_kernel_base());
444 }
445
446 inline ROCKY_FUNCTIONS float get_kernel_radius(const RockySPHElement& near_element) const
447 {
448 return this->sph_model->gen_sph->get_kernel_radius_pair(
449 this->element_index,
450 near_element.element_index,
451 this->get_kernel_refinement_multiplier(),
452 near_element.get_kernel_refinement_multiplier(),
453 this->_refinement_kernel_base());
454 }
455
456 inline ROCKY_FUNCTIONS float get_squared_kernel_radius(
457 const RockySPHElement& near_element, const real_sph eps = 0.f) const
458 {
459 return this->sph_model->gen_sph->get_squared_kernel_radius_pair(
460 this->element_index,
461 near_element.element_index,
462 this->get_kernel_refinement_multiplier(),
463 near_element.get_kernel_refinement_multiplier(),
464 this->_refinement_kernel_base(),
465 eps);
466 }
467
468 inline ROCKY_FUNCTIONS float get_kernel_derivative(
469 const float distance, const RockySPHElement& near_element) const
470 {
471 return this->sph_model->gen_sph->get_kernel_derivative(
472 distance,
473 this->element_index,
474 near_element.element_index,
475 this->get_kernel_refinement_multiplier(),
476 near_element.get_kernel_refinement_multiplier(),
477 this->_refinement_kernel_base());
478 }
479
480 // Refinement ----------------------------------------------------------------------------------
481 inline ROCKY_FUNCTIONS int get_refinement_count() const
482 {
483 return this->get_scalars()->get_refinement_count()[this->element_index];
484 }
485
486 inline ROCKY_FUNCTIONS void set_refinement_count(const int count)
487 {
488 this->get_scalars()->get_refinement_count()[this->element_index] = count;
489 }
490
491 inline ROCKY_FUNCTIONS float get_refinement_kernel_base() const
492 {
493 return this->get_scalars()->get_refinement_kernel_base()[this->element_index];
494 }
495
496 inline ROCKY_FUNCTIONS void set_refinement_kernel_base(const float base)
497 {
498 this->get_scalars()->get_refinement_kernel_base()[this->element_index] = base;
499 }
500
501 // Scalars -----------------------------------------------------------------------------------
502 inline ROCKY_FUNCTIONS float get_turbulent_viscosity() const
503 {
504 return this->get_scalars()->get_turbulent_viscosity(this->element_index);
505 }
506
507 inline ROCKY_FUNCTIONS void set_turbulent_viscosity(float turbulent_viscosity)
508 {
509 auto& scalar = this->get_scalars()->get_turbulent_viscosity(this->element_index);
510 scalar = turbulent_viscosity;
511 }
512
513 inline ROCKY_FUNCTIONS void add_turbulent_viscosity(float turbulent_viscosity)
514 {
515 auto& scalar = this->get_scalars()->get_turbulent_viscosity(this->element_index);
516 backend::atomic_add(&scalar, turbulent_viscosity);
517 }
518
519 // Scalars -----------------------------------------------------------------------------------
520 inline ROCKY_FUNCTIONS float get_molecular_viscosity() const
521 {
522 if (this->get_scalars()->is_variable_molecular_viscosity_enabled())
523 return this->get_scalars()->get_molecular_viscosity(this->element_index);
524 else
525 return this->sph_model->gen_sph->visc;
526 }
527
528 inline ROCKY_FUNCTIONS void set_molecular_viscosity(const float molecular_viscosity)
529 {
530 auto& scalar = this->get_scalars()->get_molecular_viscosity(this->element_index);
531 scalar = molecular_viscosity;
532 }
533
534 inline ROCKY_FUNCTIONS float get_temperature() const
535 {
536 return this->get_scalars()->get_temperature(this->element_index);
537 }
538
539 inline ROCKY_FUNCTIONS void set_temperature(float temperature)
540 {
541 this->get_scalars()->get_temperature(this->element_index) = temperature;
542 }
543
544 inline ROCKY_FUNCTIONS float3 get_implicit_viscosity_velocity_increment() const
545 {
546 return this->get_scalars()->get_implicit_viscosity_velocity_increment(this->element_index);
547 }
548
549 inline ROCKY_FUNCTIONS void set_implicit_viscosity_velocity_increment(float3 velocity_increment)
550 {
551 auto& scalar =
552 this->get_scalars()->get_implicit_viscosity_velocity_increment(this->element_index);
553 scalar = velocity_increment;
554 }
555
556 inline ROCKY_FUNCTIONS const rocky20::SPHParticleScalars* get_scalars() const
557 {
558 return this->scalars;
559 }
560
561 inline ROCKY_FUNCTIONS rocky20::SPHParticleScalars* get_scalars()
562 {
563 return this->scalars;
564 }
565
566 inline ROCKY_FUNCTIONS SymmetricTensor<float> get_strain_rate_tensor()
567 {
568 auto element_scalars = this->get_scalars();
569 if (!element_scalars->is_velocity_gradient_enabled())
570 {
571 return {};
572 }
573
574 // strain rate tensor = 0.5 * (grad_velocity + grad_velocity_transposed)
575 const auto& grad_vx = element_scalars->get_velocity_gradient_x(this->element_index);
576 const auto& grad_vy = element_scalars->get_velocity_gradient_y(this->element_index);
577 const auto& grad_vz = element_scalars->get_velocity_gradient_z(this->element_index);
578
579 return { { grad_vx.x, grad_vy.y, grad_vz.z },
580 { 0.5f * (grad_vx.y + grad_vy.x),
581 0.5f * (grad_vx.z + grad_vz.x),
582 0.5f * (grad_vy.z + grad_vz.y) } };
583 }
584
585 // Flags --------------------------------------------------------------------------------------
586
587 inline ROCKY_FUNCTIONS bool is_active() const
588 {
589 return this->_state().active();
590 }
591
592 inline ROCKY_FUNCTIONS void set_active(const bool active = true)
593 {
594 this->_state().set_active(active);
595 }
596
597 inline ROCKY_FUNCTIONS bool is_coupled_deactivated() const
598 {
599 return this->_state().coupled_deactivated();
600 }
601
602 inline ROCKY_FUNCTIONS void set_coupled_deactivated(const bool coupled_deactivated = true)
603 {
604 this->_state().set_coupled_deactivated(coupled_deactivated);
605 }
606
607 inline ROCKY_FUNCTIONS bool is_deactivate() const
608 {
609 return this->_state().deactivate();
610 }
611
612 inline ROCKY_FUNCTIONS void set_deactivate(const bool deactivate = true)
613 {
614 this->_state().set_deactivate(deactivate);
615 }
616
617 inline ROCKY_FUNCTIONS bool is_enabled() const
618 {
619 return this->_state().enabled();
620 }
621
622 inline ROCKY_FUNCTIONS void set_enabled(const bool enabled = true)
623 {
624 this->_state().set_enabled(enabled);
625 }
626
627 inline ROCKY_FUNCTIONS bool is_frozen() const
628 {
629 return this->_state().frozen();
630 }
631
632 inline ROCKY_FUNCTIONS void set_frozen(bool _frozen = true)
633 {
634 if (!this->is_dem_coupled())
635 {
636 this->_state().set_frozen(_frozen);
637 if (_frozen)
638 // Zero velocities of frozen elements
639 this->set_velocity({});
640 }
641 }
642
643 inline ROCKY_FUNCTIONS bool is_ghost() const
644 {
645 return this->_state().ghost();
646 }
647
648 inline ROCKY_FUNCTIONS void set_ghost(const bool ghost = true)
649 {
650 this->_state().set_ghost(ghost);
651 }
652
653 inline ROCKY_FUNCTIONS bool is_just_activated() const
654 {
655 return this->_state().just_activated();
656 }
657
658 inline ROCKY_FUNCTIONS void set_just_activated(const bool just_activated = true)
659 {
660 this->_state().set_just_activated(just_activated);
661 }
662
663 inline ROCKY_FUNCTIONS bool is_just_enabled() const
664 {
665 return this->_state().just_enabled();
666 }
667
668 inline ROCKY_FUNCTIONS void set_just_enabled(const bool just_enabled = true)
669 {
670 this->_state().set_just_enabled(just_enabled);
671 }
672
673 inline ROCKY_FUNCTIONS bool is_released() const
674 {
675 return this->_state().released();
676 }
677
678 inline ROCKY_FUNCTIONS void set_released(const bool released = true)
679 {
680 this->_state().set_released(released);
681 }
682
683 /* A regular free element is one that:
684 * is enabled (has been released)
685 * is not dem-coupled
686 * is not ghost
687 * is not frozen */
688 inline ROCKY_FUNCTIONS bool is_regular_free() const
689 {
690 return this->is_enabled() && !this->is_dem_coupled() && !this->is_ghost()
691 && !this->is_frozen();
692 }
693
694 inline ROCKY_FUNCTIONS void set_removed_from_neighbors_search(const bool removed)
695 {
696 this->_state().set_removed_from_neighbors_search(removed);
697 }
698
699 inline ROCKY_FUNCTIONS bool is_removed_from_neighbors_search() const
700 {
701 return this->_state().is_removed_from_neighbors_search();
702 }
703
704 inline ROCKY_FUNCTIONS bool is_on_periphery() const
705 {
706 return this->_state().on_periphery();
707 }
708
709 inline ROCKY_FUNCTIONS void set_on_periphery(const bool on_periphery = true)
710 {
711 this->_state().set_on_periphery(on_periphery);
712 }
713
714
715 // Setup data (non-resettable)
716 SPHDeviceModel* sph_model;
717 rocky20::SPHParticleScalars* scalars;
718
719 // Particle data (resettable)
720 int element_index;
721 bool use_refinement;
722
723 ROCKY_FUNCTIONS RockySPHElement(SPHDeviceModel* _sph_model, const int index)
724 : sph_model(_sph_model)
725 , scalars(_sph_model -> sph_particle_scalars)
726 , element_index(index)
727 , use_refinement(_sph_model -> gen_sph->use_refinement())
728 {
729 }
730
731 RockySPHElement(SPHModel& _sph_model, const int index)
732 : RockySPHElement(_sph_model.get_host_data(), index)
733 {
734 }
735
736 RockySPHElement(std::unique_ptr<SPHModel>& _sph_model, const int index)
737 : RockySPHElement(_sph_model->get_host_data(), index)
738 {
739 }
740
741 inline ROCKY_FUNCTIONS void reset(const int index)
742 {
743 this->element_index = index;
744 }
745
746 // Helper methods ------------------------------------------------------------------------------
747
748 [[nodiscard]] inline ROCKY_FUNCTIONS const float* _refinement_kernel_base() const
749 {
750 if (this->use_refinement)
751 return this->get_scalars()->get_refinement_kernel_base();
752 return nullptr;
753 }
754
755 [[nodiscard]] inline ROCKY_FUNCTIONS const int* _refinement_count() const
756 {
757 if (this->use_refinement)
758 return this->get_scalars()->get_refinement_count();
759 return nullptr;
760 }
761
762 __forceinline__ ROCKY_FUNCTIONS const SSPHState& _state() const
763 {
764 return this->get_scalars()->get_state(this->element_index);
765 }
766
767 __forceinline__ ROCKY_FUNCTIONS SSPHState& _state()
768 {
769 return this->get_scalars()->get_state(this->element_index);
770 }
771};

Connect with Ansys