Skip to main content

Rocky Solver SDK 2024 R2

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 inline ROCKY_FUNCTIONS double compute_particle_sphericity(const RockyParticle& particle) const
246 {
247 return (particle.get_group().tpe == ptSpherical
248 ? 1.0
249 : (M_PI * this->props.diameter * this->props.diameter) / particle.get_area()
250 );
251 }
252
253 inline ROCKY_FUNCTIONS double get_relative_velocity_norm() const
254 {
255 return this->props.relative_velocity_norm;
256 }
257
258
259
260 SDeviceModel* model;
261 CFDParticleProperties props;
262 int cfd_index;
263 const CFDParticleGroup* cfd_particle_group;
264
265 inline ROCKY_FUNCTIONS void reset(int particle_index, int cfd_index)
266 {
267 this->cfd_index = cfd_index;
268 this->update_properties(particle_index);
269 }
270
271 inline ROCKY_FUNCTIONS void update_properties(int particle_index)
272 {
273 auto& particle = this->model->get_particle(particle_index);
274 const cuda_particle_group& particle_group = this->model->get_particle_group(particle.get_group_index());
275
276 this->cfd_particle_group = &this->model->cfd_particle_groups[particle.get_group_index()];
277
278 const double mass = ParticleProperties::get_mass(this->model, particle, particle_index);
279 const double bulk_volume = ParticleProperties::get_bulk_volume(this->model, particle, particle_index);
280 const double solid_volume = ParticleProperties::get_solid_volume(this->model, particle, particle_index);
281 props.diameter = cbrt(6.0 * bulk_volume / M_PI);
282 props.density = mass / solid_volume;
283 props.cgm_factor = particle_group.cgm_scale_factor;
284
285 auto &particle_vel = this->model->get_particle_velocity(particle_index);
286 double3 fluid_velocity = this->model->fluid_scalars->get_velocity(this->cfd_index);
287
288 /* converting velocity according to Fluent's porous velocity formulation*/
289 if (this->model->gen_cfd->superficial_velocity_formulation)
290 {
291 double porosity = 1.0 - this->model->fluid_scalars->get_solid_volume_fraction(this->cfd_index);
292
293 auto true_velocity = [porosity] (double superficial_velocity, double particle_vel)
294 {
295 double direction;
296 direction = superficial_velocity >= 0.0 ? 1.0 : -1.0;
297
298 double velocity = superficial_velocity + (1.0/porosity - 1.0)*(superficial_velocity - particle_vel);
299 velocity = max(abs(velocity), abs(superficial_velocity));
300 /* where superficial_velocity/porosity is the physical velocity */
301 return min(velocity, abs(superficial_velocity/porosity))*direction;
302 };
303
304 props.relative_velocity = {
305 true_velocity(fluid_velocity.x, particle_vel.ux) - particle_vel.ux,
306 true_velocity(fluid_velocity.y, particle_vel.uy) - particle_vel.uy,
307 true_velocity(fluid_velocity.z, particle_vel.uz) - particle_vel.uz,
308 };
309 }
310 else
311 {
312 props.relative_velocity = {
313 fluid_velocity.x - particle_vel.ux,
314 fluid_velocity.y - particle_vel.uy,
315 fluid_velocity.z - particle_vel.uz };
316 }
317
318 if (this->model->gen_cfd->use_turbulent_dispersion)
319 {
320 props.relative_velocity += this->model->particle_scalars->get_turbulence_velocity(particle_index);
321 }
322
323 props.relative_velocity_norm = rocky::vector::get_norm(props.relative_velocity);
324 }
325
327};
328
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