Skip to main content

Rocky Solver SDK 2025 R2

rocky_cfd

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

Connect with Ansys