Skip to main content

Rocky Solver SDK 2025 R1

rocky_cfd

Last update: 17.07.2025
1#pragma once
2
3// Includes =======================================================================================
4#include "rocky_particle_scalars.hpp"
5#include "rocky_fluid_scalars.hpp"
6
7#include <rocky20/api/rocky_particle.hpp>
8#include <rocky20/api/device/api_backend.hpp>
9#include <rocky20/device/device_model.hpp>
10#include <rocky20/cuda/interaction_forces.hpp>
11
12// ================================================================================================
13// IRockyCFDProperties
14// ================================================================================================
15
26{
32 inline ROCKY_FUNCTIONS double get_fluid_density() const
33 {
34 return this->model->fluid_scalars->get_density(this->cfd_index);
35 }
36
37
43 inline ROCKY_FUNCTIONS double get_fluid_viscosity() const
44 {
45 return this->model->fluid_scalars->get_viscosity(this->cfd_index);
46 }
47
48
54 inline ROCKY_FUNCTIONS double get_fluid_temperature() const
55 {
56 return this->model->fluid_scalars->get_temperature(this->cfd_index);
57 }
58
59
64 inline ROCKY_FUNCTIONS double get_fluid_specific_heat() const
65 {
66 return this->model->fluid_scalars->get_specific_heat(this->cfd_index);
67 }
68
69
74 inline ROCKY_FUNCTIONS double get_fluid_thermal_conductivity() const
75 {
76 return this->model->fluid_scalars->get_thermal_conductivity(this->cfd_index);
77 }
78
79
85 inline ROCKY_FUNCTIONS double3 get_fluid_pressure_gradient() const
86 {
87 return this->model->fluid_scalars->get_pressure_gradient(this->cfd_index);
88 }
89
90
97 inline ROCKY_FUNCTIONS double3 compute_fluid_vorticity() const
98 {
99 const cu_real3 grad_u = this->model->fluid_scalars->get_velocity_u_gradient(this->cfd_index);
100 const cu_real3 grad_v = this->model->fluid_scalars->get_velocity_v_gradient(this->cfd_index);
101 const cu_real3 grad_w = this->model->fluid_scalars->get_velocity_w_gradient(this->cfd_index);
102 return double3{ grad_w.y - grad_v.z, grad_u.z - grad_w.x, grad_v.x - grad_u.y };
103 }
104
105
112 inline ROCKY_FUNCTIONS double3 get_relative_velocity() const
113 {
114 return this->props.relative_velocity;
115 }
116
117
125 inline ROCKY_FUNCTIONS double get_reynolds_number() const
126 {
127 return Reynolds(
128 props.relative_velocity_norm,
129 this->get_fluid_density(), props.diameter,
130 this->get_fluid_viscosity() * props.cgm_factor
131 ) + DBL_EPSILON;
132 }
133
134
142 inline ROCKY_FUNCTIONS double compute_vorticity_reynolds_number() const
143 {
144 double omega_f = rocky::vector::get_norm(this->compute_fluid_vorticity());
145 return Reynolds_omega(omega_f, this->get_fluid_density(), this->props.diameter,
146 this->get_fluid_viscosity() * props.cgm_factor) + DBL_EPSILON;
147 }
148
149
157 inline ROCKY_FUNCTIONS double compute_relative_angular_reynolds_number(
158 const double3& particle_angular_velocity) const
159 {
160 double omega_r = rocky::vector::get_norm(0.5 * this->compute_fluid_vorticity() - particle_angular_velocity);
161 return Reynolds_omega(omega_r, this->get_fluid_density(), this->props.diameter,
162 this->get_fluid_viscosity() * props.cgm_factor) + DBL_EPSILON;
163 }
164
165
172 inline ROCKY_FUNCTIONS double get_prandtl_number() const
173 {
174 if (this->get_fluid_thermal_conductivity() > SMALL_VALUE)
175 {
176 return this->get_fluid_specific_heat() * this->get_fluid_viscosity()
178 }
179 else
180 {
181 return DBL_MAX;
182 }
183 }
184
185
194 inline ROCKY_FUNCTIONS double get_solid_fraction() const
195 {
196 return this->model->fluid_scalars->get_solid_volume_fraction(this->cfd_index);
197 }
198
204 inline ROCKY_FUNCTIONS double get_cell_volume() const
205 {
206 return this->model->fluid_scalars->get_cell_volume(this->cfd_index);
207 }
208
214 inline ROCKY_FUNCTIONS IRockyFluidScalars get_scalars() const
215 {
216 return IRockyFluidScalars(*this->model->fluid_scalars, this->cfd_index);
217 }
218
222 inline ROCKY_FUNCTIONS double get_cfd_time_step() const
223 {
224 return this->model->gen_cfd->dt_target_f;
225 }
226
227
230 inline ROCKY_FUNCTIONS double get_particle_equivalent_diameter() const
231 {
232 return this->props.diameter;
233 }
234
235 inline ROCKY_FUNCTIONS double get_particle_volume() const
236 {
237 return M_PI / 6.0 * this->props.diameter * this->props.diameter * this->props.diameter;
238 }
239
240 inline ROCKY_FUNCTIONS double get_particle_equivalent_cross_area() const
241 {
242 return 0.25 * M_PI * this->props.diameter * this->props.diameter;
243 }
244
245 // Equivalent to RockyParticle::get_sphericity but faster, as the equivalent diameter is already
246 // computed (which requires a cubic root)
247 inline ROCKY_FUNCTIONS double compute_particle_sphericity(const RockyParticle& particle) const
248 {
249 return (particle.get_group().tpe == ptSpherical)
250 ? 1.0
251 : (M_PI * this->props.diameter * this->props.diameter) / particle.get_area();
252 }
253
254 inline ROCKY_FUNCTIONS double get_relative_velocity_norm() const
255 {
256 return this->props.relative_velocity_norm;
257 }
258
259
260
261 SDeviceModel* model;
262 CFDParticleProperties props;
263 int cfd_index;
264 const CFDParticleGroup* cfd_particle_group;
265
266 inline ROCKY_FUNCTIONS void reset(int particle_index, int cfd_index)
267 {
268 this->cfd_index = cfd_index;
269 this->update_properties(particle_index);
270 }
271
272 inline ROCKY_FUNCTIONS void update_properties(int particle_index)
273 {
274 const RockyParticle particle(this->model, particle_index);
275
276 this->cfd_particle_group =
277 &this->model->cfd_particle_groups[particle.get_particle_group_index()];
278
279 props.diameter = particle.get_equivalent_diameter();
280 props.density = particle.get_mass() / particle.get_solid_volume();
281 props.cgm_factor = particle.get_cgm_scale_factor();
282
283 const double3 particle_velocity = particle.get_translational_velocity();
284 const double3 fluid_velocity = this->model->fluid_scalars->get_velocity(this->cfd_index);
285
286 /* converting particle_velocity according to Fluent's porous particle_velocity formulation*/
287 if (this->model->gen_cfd->superficial_velocity_formulation)
288 {
289 double porosity = 1.0 - this->model->fluid_scalars->get_solid_volume_fraction(this->cfd_index);
290
291 auto true_velocity = [porosity] (double superficial_velocity, double particle_vel)
292 {
293 double direction;
294 direction = superficial_velocity >= 0.0 ? 1.0 : -1.0;
295
296 double velocity = superficial_velocity + (1.0/porosity - 1.0)*(superficial_velocity - particle_vel);
297 velocity = max(abs(velocity), abs(superficial_velocity));
298 /* where superficial_velocity/porosity is the physical particle_velocity */
299 return min(velocity, abs(superficial_velocity/porosity))*direction;
300 };
301
302 props.relative_velocity = {
303 true_velocity(fluid_velocity.x, particle_velocity.x) - particle_velocity.x,
304 true_velocity(fluid_velocity.y, particle_velocity.y) - particle_velocity.y,
305 true_velocity(fluid_velocity.z, particle_velocity.z) - particle_velocity.z,
306 };
307 }
308 else
309 {
310 props.relative_velocity = fluid_velocity - particle_velocity;
311 }
312
313 if (this->model->gen_cfd->use_turbulent_dispersion)
314 {
315 props.relative_velocity += this->model->particle_scalars->get_turbulence_velocity(particle_index);
316 }
317
318 props.relative_velocity_norm = rocky::vector::get_norm(props.relative_velocity);
319 }
320
322};
323
Definition rocky_cfd.hpp:26
ROCKY_FUNCTIONS double get_cell_volume() const
Definition rocky_cfd.hpp:204
ROCKY_FUNCTIONS double get_fluid_thermal_conductivity() const
Definition rocky_cfd.hpp:74
ROCKY_FUNCTIONS double get_prandtl_number() const
Definition rocky_cfd.hpp:172
ROCKY_FUNCTIONS double get_cfd_time_step() const
Definition rocky_cfd.hpp:222
ROCKY_FUNCTIONS double3 get_fluid_pressure_gradient() const
Definition rocky_cfd.hpp:85
ROCKY_FUNCTIONS double get_reynolds_number() const
Definition rocky_cfd.hpp:125
ROCKY_FUNCTIONS double get_fluid_specific_heat() const
Definition rocky_cfd.hpp:64
ROCKY_FUNCTIONS double compute_vorticity_reynolds_number() const
Definition rocky_cfd.hpp:142
ROCKY_FUNCTIONS double3 get_relative_velocity() const
Definition rocky_cfd.hpp:112
ROCKY_FUNCTIONS double3 compute_fluid_vorticity() const
Definition rocky_cfd.hpp:97
ROCKY_FUNCTIONS IRockyFluidScalars get_scalars() const
Definition rocky_cfd.hpp:214
ROCKY_FUNCTIONS double get_fluid_temperature() const
Definition rocky_cfd.hpp:54
ROCKY_FUNCTIONS double get_fluid_viscosity() const
Definition rocky_cfd.hpp:43
ROCKY_FUNCTIONS double get_fluid_density() const
Definition rocky_cfd.hpp:32
ROCKY_FUNCTIONS double compute_relative_angular_reynolds_number(const double3 &particle_angular_velocity) const
Definition rocky_cfd.hpp:157
ROCKY_FUNCTIONS double get_solid_fraction() const
Definition rocky_cfd.hpp:194
Definition rocky_fluid_scalars.hpp:57

Connect with Ansys