Skip to main content

Rocky Solver SDK 2025 R2

api_device_cfd_coupling

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/rocky_api_cfd_functions.h>
6#include <rocky20/device/device_cfd_drag.hpp>
7#include <rocky20/device/device_cfd_coupling.hpp>
8
9namespace device
10{
11
12template<typename... Op>
13__host__ __device__
14void execute_operators(
15 const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data,
16 Op... ops)
17{
18 int dummy[sizeof...(Op)] = { (ops(particle, cfd, output, data), 0)... };
19}
20
21/*
22A utility structure to hold all device data used to execute the coupling kernel
23All data is a device data, so only the final kernel would be able to access such data
24*/
25struct CouplingDispatchData
26{
27 bool is_cuda{ false }, collect_cfd_data{ false };
28
29 SDeviceModel* device_data;
30 unsigned int* particle_indexes;
31 int n_particles;
32 void* udf_data;
33};
34
35/*
36Coupling kernel
37*/
38template <class backend, typename... Op>
39__host__ __device__
40void api_coupling_kernel(CouplingDispatchData& data, Op... operators)
41{
42 auto device_data = data.device_data;
43
44 IRockyParticle particle_api(-1, device_data);
45
47 cfd.model = device_data;
48 double3 gravity { device_data->gen->gx, device_data->gen->gy, device_data->gen->gz };
49
50#ifdef GPU_KERNEL_COMPILING_STAGE
51 __shared__ CFDTimestepBin block_bins[CD_NTHREADS];
52 const int thread_index = threadIdx.x;
53 CFDTimestepBin& block_bin = block_bins[thread_index];
54#else
55 CFDTimestepBin& block_bin = device_data->cfd_monitor->thread_bins[backend::ThreadIndex()];
56#endif
57
58 block_bin.reset();
59
60 int thread_start, thread_step, thread_stop;
61 backend::ThreadIteration(thread_start, thread_step, thread_stop, data.n_particles);
62 for (auto i = thread_start; i < thread_stop; i += thread_step)
63 {
64 // particle
65 const int ip = data.particle_indexes[i];
66 particle_api._impl.reset(ip);
67 if (!particle_api._impl.particle->enabled()) {
68 continue;
69 }
70
71 const auto ic = device_data->particle_scalars->get_cfd_index(ip);
72 if (ic < 0) {
73 continue;
74 }
75
76 cfd.reset(ip, ic);
77 CFDCouplingOutput output{};
78 const auto porosity = device_data->pgr[particle_api.get_particle_group_index()].porosity;
79
80 // Relative Buoyancy force, due to the relative fluid density
81 output.set_relative_buoyancy_force(
82 -cfd.get_particle_solid_volume(porosity) * cfd.model->gen_cfd->relative_density * gravity
83 );
84
85 // Force due to pressure gradient (accounts for buoyancy and flow-induced
86 // pressure variations).
87 output.set_pressure_gradient_force(
88 -cfd.get_particle_solid_volume(porosity) * cfd.get_fluid_pressure_gradient()
89 );
90
91 execute_operators(particle_api, cfd, output, data.udf_data, operators...);
92
93 // add forces and moments to the particle
94 auto& particle_forces = device_data->frc[ip];
95 particle_forces.fx += output.total_cfd_force.x;
96 particle_forces.fy += output.total_cfd_force.y;
97 particle_forces.fz += output.total_cfd_force.z;
98
99 if (output.has_moment()) {
100 particle_forces.mx += output.total_cfd_moment.x;
101 particle_forces.my += output.total_cfd_moment.y;
102 particle_forces.mz += output.total_cfd_moment.z;
103 }
104
105 // add critical time-step ratio to CFD Monitor
106 block_bin.check_critical_timestep(
107 device_data->get_general().dt,
108 output.drag_coefficient_fluent / particle_api.get_mass(),
109 device_data->cfd_monitor->levels
110 );
111 }
112
113#ifdef GPU_KERNEL_COMPILING_STAGE
114 // Block reduce
115 device::cuda_block_reduce(
116 block_bins, device_data->cfd_monitor->thread_bins,
117 [](CFDTimestepBin &left, const CFDTimestepBin& right)
118 {
119 left.join(right);
120 }
121 );
122#endif
123}
124
125struct EmptyCustomCouplingPlugin {};
126
127struct InvalidOperator
128{
129 InvalidOperator()
130 {
131 #ifndef GPU_KERNEL_COMPILING_STAGE
132 ROCKY_RUNTIME_ERROR("Invalid operation selection");
133 #endif
134 }
135
136 __host__ __device__ inline
137 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
138 {}
139};
140
141
142template <class Plugin>
143auto custom_drag_operator() { return InvalidOperator(); }
144
145template <class Plugin>
146auto custom_lift_operator() { return InvalidOperator(); }
147
148template <class Plugin>
149auto custom_virtual_mass_operator(SDeviceModel *device_data) { return InvalidOperator(); }
150
151template <class Plugin>
152auto custom_torque_operator() { return InvalidOperator(); }
153
154template <class Plugin>
155auto custom_convection_operator(SDeviceModel* device_data) { return InvalidOperator(); }
156
157/*
158Coupling Operators: executed, when enabled in the following order:
159 - Drag
160 - Lift
161 - Virtual Mass
162 - Torque
163 - Heat Convection
164 - CFD Data recorder
165 - Two Way Coupling
166 - Turbulence
167*/
168struct DragOperator
169{
170 __host__ __device__ inline
171 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
172 {
173 device::compute_cfd_drag(particle, cfd, output, data);
174 }
175};
176
177
178
179template <typename _DragLawOperator>
180struct DragParametricOperator
181{
182 __host__ __device__ inline
183 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
184 {
185 DragLaw<_DragLawOperator>(particle, cfd, output, data);
186 }
187};
188
189// Operator defined with drag laws implementation with light weight code, with less impact of performance.
190struct DragLightWeightOperator
191{
192 static bool valid(const ECFDDragLaw drag_law)
193 {
194 switch (drag_law)
195 {
196 case cfd_drag_law_SchillerNaumann1933:
197 case cfd_drag_law_Dallavalle1948:
198 case cfd_drag_law_HaiderLevenspiel1989:
199 case cfd_drag_law_MorsiAlexander1972:
200 case cfd_drag_law_WenYu1966:
201 case cfd_drag_law_Ergun1958:
202 case cfd_drag_law_GidaspowBezburuahDing1992:
203 case cfd_drag_law_HuilinGidaspow2003:
204 case cfd_drag_law_DiFelice1994:
205 case cfd_drag_law_HillKochLadd2001:
206 case cfd_drag_law_HillKoch2001:
207 case cfd_drag_law_SyamlalOBrien1987:
208 return true;
209 default:
210 return false;
211 }
212 }
213
214 __host__ __device__ inline
215 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
216 {
217 switch (cfd.cfd_particle_group->drag_law)
218 {
219 case cfd_drag_law_SchillerNaumann1933: DragLaw<SchillerNaumann1933Operator>(particle, cfd, output, data); break;
220 case cfd_drag_law_Dallavalle1948: DragLaw<Dallavalle1948Operator>(particle, cfd, output, data); break;
221 case cfd_drag_law_HaiderLevenspiel1989: DragLaw<HaiderLevenspiel1989Operator>(particle, cfd, output, data); break;
222 case cfd_drag_law_MorsiAlexander1972: DragLaw<MorsiAlexander1972Operator>(particle, cfd, output, data); break;
223 case cfd_drag_law_WenYu1966: DragLaw<WenYu1966Operator>(particle, cfd, output, data); break;
224 case cfd_drag_law_Ergun1958: DragLaw<Ergun1958Operator>(particle, cfd, output, data); break;
225 case cfd_drag_law_GidaspowBezburuahDing1992: DragLaw<GidaspowBezburuahDing1992Operator>(particle, cfd, output, data); break;
226 case cfd_drag_law_HuilinGidaspow2003: DragLaw<HuilinGidaspow2003Operator>(particle, cfd, output, data); break;
227 case cfd_drag_law_DiFelice1994: DragLaw<DiFelice1994Operator>(particle, cfd, output, data); break;
228 case cfd_drag_law_HillKochLadd2001: DragLaw<HillKochLadd2001Operator>(particle, cfd, output, data); break;
229 case cfd_drag_law_HillKoch2001: DragLaw<HillKoch2001Operator>(particle, cfd, output, data); break;
230 case cfd_drag_law_SyamlalOBrien1987: DragLaw<SyamlalOBrien1987Operator>(particle, cfd, output, data); break;
231 }
232 }
233};
234
235// Operator defined with drag laws implementation with light weight code, with less impact of performance.
236struct DragHeavyWeightOperator
237{
238 static bool valid(const ECFDDragLaw drag_law)
239 {
240 switch (drag_law)
241 {
242 case cfd_drag_law_Ganser1993:
243 case cfd_drag_law_MarheinekeWegener2011:
244 return true;
245 default:
246 return false;
247 }
248 }
249
250 __host__ __device__ inline
251 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
252 {
253 switch (cfd.cfd_particle_group->drag_law)
254 {
255 case cfd_drag_law_Ganser1993: Ganser1993Operator::DragLaw(particle, cfd, output); break;
256 case cfd_drag_law_MarheinekeWegener2011: MarheinekeWegener2011Operator::DragLaw(particle, cfd, output); break;
257 }
258 }
259};
260
261struct LiftOperator
262{
263 __host__ __device__ inline
264 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
265 {
266 device::compute_cfd_lift(particle, cfd, output, data);
267 }
268};
269
270template <typename _LiftCoeff>
271struct LiftParametricOperator
272{
273 __host__ __device__ inline
274 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
275 {
276 device::LiftLaw<_LiftCoeff>(particle, cfd, output, data);
277 }
278};
279
280struct VirtualMassOperator
281{
282 SDeviceModel* device_data;
283
284 __host__ __device__ inline
285 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
286 {
287 device::compute_cfd_virtual_mass(particle, cfd, output, data);
288 device_data->particle_scalars->get_virtual_mass(particle._impl.particle_index) = output.virtual_mass;
289 }
290};
291
292template <typename _Coeff>
293struct VirtualMassParametricOperator
294{
295 SDeviceModel* device_data;
296
297 __host__ __device__ inline
298 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
299 {
300 device::VirtualMassLaw<_Coeff>(particle, cfd, output, data);
301 device_data->particle_scalars->get_virtual_mass(particle._impl.particle_index) = output.virtual_mass;
302 }
303};
304
305struct TorqueOperator
306{
307 __host__ __device__ inline
308 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
309 {
310 device::compute_cfd_torque(particle, cfd, output, data);
311 }
312};
313
314template <typename _Coeff>
315struct TorqueParametricOperator
316{
317 __host__ __device__ inline
318 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
319 {
320 device::TorqueLaw<_Coeff>(particle, cfd, output, data);
321 }
322};
323
324struct HeatConvectionOperator
325{
326 SDeviceModel* device_data;
327
328 __host__ __device__ inline
329 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
330 {
331 device::compute_cfd_convection(particle, cfd, output, data);
332 device_data->particle_transfer_scalars->get_heat_transfer(particle._impl.particle_index) += output.heat_transfer;
333 }
334};
335
336template <typename _Coeff>
337struct HeatConvectionParametricOperator
338{
339 SDeviceModel* device_data;
340
341 __host__ __device__ inline
342 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
343 {
344 device::ConvectionLaw<_Coeff>(particle, cfd, output, data);
345 device_data->particle_transfer_scalars->get_heat_transfer(particle._impl.particle_index) += output.heat_transfer;
346 }
347};
348
349struct CFDDataRecorderOperator
350{
351 SDeviceModel* device_data;
352
353 __host__ __device__ inline
354 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
355 {
356#ifndef CFD_NO_CUSTOM_LAWS
357 if (device_data->cfd_data_recorder != nullptr && device_data->cfd_data_recorder->enabled)
358#endif
359 device_data->cfd_data_recorder->register_coupling_data(
360 output, device_data->particle_scalars, particle._impl.particle_index, device_data->gen->dt
361 );
362 }
363};
364
365struct TwoWayCouplingOperator
366{
367 SDeviceModel* device_data;
368
369 __host__ __device__ inline void operator()(
370 const IRockyParticle& particle,
371 const IRockyCFDProperties& cfd,
372 CFDCouplingOutput& output,
373 void* data)
374 {
375 if (device_data->gen_cfd->cfd_coupling_mode == cfdcTwoWay)
376 {
377 auto dt = device_data->get_general().dt;
378 auto particle_scalars = particle.get_scalars();
379
380 const auto& particle_velocity = particle.get_translational_velocity();
381 const auto& relative_velocity = cfd.get_relative_velocity();
382
383 if (device_data->gen_cfd->use_2023R2_cfd_sources)
384 {
385 particle_scalars.add_explicit_fluid_momentum(
386 particle_velocity * output.drag_coefficient_fluent * dt);
387 }
388 else
389 {
390 particle_scalars.add_explicit_fluid_momentum(
391 -output.drag_coefficient_fluent * relative_velocity * dt);
392 }
393 particle_scalars.add_implicit_fluid_momentum(-output.drag_coefficient_fluent * dt);
394
395 if (output.has_explicit_forces())
396 {
397 particle_scalars.add_explicit_fluid_momentum(
398 -output.momentum_source_explicit_fluent * dt);
399 }
400 if (output.has_heat())
401 {
402 if (device_data->gen_cfd->use_2023R2_cfd_sources)
403 {
404 particle_scalars.add_explicit_fluid_heat_transfer_rate(
405 output.heat_source_explicit_fluent * dt);
406 }
407 else
408 {
409 particle_scalars.add_explicit_fluid_heat_transfer_rate(
410 (output.heat_source_explicit_fluent
411 + output.heat_source_implicit_fluent * cfd.get_fluid_temperature())
412 * dt);
413 }
414 particle_scalars.add_implicit_fluid_heat_transfer_rate(
415 output.heat_source_implicit_fluent * dt);
416 }
417 }
418 }
419};
420
421struct TurbulenceOperator
422{
423 SDeviceModel* device_data;
424
425 __host__ __device__ inline
426 void operator()(const IRockyParticle& particle, const IRockyCFDProperties& cfd, CFDCouplingOutput& output, void* data)
427 {
428#ifndef CFD_NO_CUSTOM_LAWS
429 if (device_data->gen_cfd->use_turbulent_dispersion)
430#endif
431 update_turbulent_dispersion(
432 device_data->particle_scalars,
433 particle._impl.particle_index,
434 cfd.cfd_index,
435 device_data->get_general().dt,
436 device_data->prt_vel,
437 device_data->fluid_scalars,
438 cfd.props,
439 particle._impl.get_group(),
440 output.C_D,
441 device_data->cfd_random
442 );
443 }
444};
445
446#ifndef SKIP_COUPLING_COMPILATION
447
448/*
449Dispatch function, a sequence of selector function calls, that will at the end collected all operators in a
450variadic template list, used to instantiate and dispatch a kernel.
451*/
452
453template <class backend, typename... Operators>
454__global__
455void cuda_coupling_kernel(CouplingDispatchData data, Operators... operators)
456{
457 api_coupling_kernel<backend>(data, operators...);
458}
459
460template <class backend, typename... Operators>
461void omp_coupling_kernel(CouplingDispatchData &data, Operators... operators)
462{
463 // shut up nvcc compile warnings when compiling device function version using OMPBackend
464 #ifndef GPU_KERNEL_COMPILING_STAGE
465
466 api_coupling_kernel<backend>(data, operators...);
467
468 #endif
469}
470
471template <typename... Operators> inline
472void dispatch_coupling_kernel(CouplingDispatchData &data, Operators... operators)
473{
474 if (data.is_cuda) {
475#ifdef GPU_COMPILER
476 cuda_coupling_kernel<CudaBackend><<<CD_NBLOCKS, CD_NTHREADS>>>(data, operators...);
477#else
478 ROCKY_RUNTIME_ERROR("Invalid GPU kernel execution.");
479#endif
480 }
481 else
482 omp_coupling_kernel<OMPBackend>(data, operators...);
483}
484
485/*
486Selector functions, called in ascending order
487e.g. drag -> lift -> virtual mass -> ....
488*/
489template<typename... Operators>
490void select_turbulence_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, Operators... operators)
491{
492 if (h_gen_cfd.use_turbulent_dispersion)
493 dispatch_coupling_kernel(data, operators..., TurbulenceOperator{ data.device_data });
494 else
495 dispatch_coupling_kernel(data, operators...);
496}
497
498template<typename... Operators>
499void select_coupling_mode_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, Operators... operators)
500{
501 if (h_gen_cfd.cfd_coupling_mode == cfdcTwoWay)
502 select_turbulence_and(
503 data, h_gen_cfd, operators..., TwoWayCouplingOperator{ data.device_data });
504 else
505 select_turbulence_and(data, h_gen_cfd, operators...);
506}
507
508template<typename... Operators>
509void select_cfd_data_recorder_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, Operators... operators)
510{
511#ifdef CFD_NO_CUSTOM_LAWS
512 if (data.collect_cfd_data)
513 select_coupling_mode_and(data, h_gen_cfd, operators..., CFDDataRecorderOperator{ data.device_data });
514 else
515 select_coupling_mode_and(data, h_gen_cfd, operators...);
516#else
517 // When compiling the kernel with custom laws, we must limit the number of times we instantiate the coupling kernel.
518 // To avoid code bloat, we create here just a single one with all remaining functions enabled
519 dispatch_coupling_kernel(
520 data,
521 operators...,
522 CFDDataRecorderOperator{ data.device_data },
523 TwoWayCouplingOperator{ data.device_data },
524 TurbulenceOperator{ data.device_data }
525 );
526#endif
527}
528
529template<class Plugin, typename... Operators>
530void select_convection_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, const CFDParticleGroup& group, Operators... operators)
531{
532 switch (group.convection_law)
533 {
534 case cfd_convection_law_none:
535 select_cfd_data_recorder_and(data, h_gen_cfd, operators...);
536 break;
537#ifndef CFD_NO_CUSTOM_LAWS
538 case cfd_convection_law_custom:
539 select_cfd_data_recorder_and(data, h_gen_cfd, operators..., custom_convection_operator<Plugin>(data.device_data));
540 break;
541#endif
542 default:
543 select_cfd_data_recorder_and(data, h_gen_cfd, operators..., HeatConvectionOperator{ data.device_data });
544 }
545}
546
547template<class Plugin, typename... Operators>
548void select_torque_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, const CFDParticleGroup& group, Operators... operators)
549{
550 switch (group.torque_law)
551 {
552 case cfd_torque_law_none:
553 select_convection_and<Plugin>(data, h_gen_cfd, group, operators...);
554 break;
555 case cfd_torque_law_DennisSinghIngham1980:
556 select_convection_and<Plugin>(data, h_gen_cfd, group, operators..., TorqueParametricOperator<DennisSinghIngham1980Operator>());
557 break;
558#ifndef CFD_NO_CUSTOM_LAWS
559 case cfd_torque_law_custom:
560 select_convection_and<Plugin>(data, h_gen_cfd, group, operators..., custom_torque_operator<Plugin>());
561 break;
562#endif
563 }
564}
565
566template<class Plugin, typename... Operators>
567void select_virtual_mass_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, const CFDParticleGroup& group, Operators... operators)
568{
569 switch (group.virtual_mass_law)
570 {
571 case cfd_virtual_mass_law_none:
572 select_torque_and<Plugin>(data, h_gen_cfd, group, operators...);
573 break;
574#ifndef CFD_NO_CUSTOM_LAWS
575 case cfd_virtual_mass_law_custom:
576 select_torque_and<Plugin>(data, h_gen_cfd, group, operators..., custom_virtual_mass_operator<Plugin>(data.device_data));
577 break;
578#endif
579 default:
580 select_torque_and<Plugin>(data, h_gen_cfd, group, operators..., VirtualMassOperator{ data.device_data });
581 }
582}
583
584template<class Plugin, typename... Operators>
585void select_lift_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, const CFDParticleGroup& h_group, Operators... operators)
586{
587 switch (h_group.lift_law)
588 {
589 case cfd_lift_law_none:
590 select_virtual_mass_and<Plugin>(data, h_gen_cfd, h_group, operators...);
591 break;
592 //case cfd_lift_law_Mei1992:
593 // select_virtual_mass_and<Plugin>(data, h_gen_cfd, h_group, operators..., LiftOperator<Mei1992Operator>());
594 // break;
595 //case cfd_lift_law_Saffman1968:
596 // select_virtual_mass_and<Plugin>(data, h_gen_cfd, h_group, operators..., LiftOperator<Saffman1968Operator>());
597 // break;
598#ifndef CFD_NO_CUSTOM_LAWS
599 case cfd_lift_law_custom:
600 select_virtual_mass_and<Plugin>(data, h_gen_cfd, h_group, operators..., custom_lift_operator<Plugin>());
601 break;
602#endif
603 default:
604 select_virtual_mass_and<Plugin>(data, h_gen_cfd, h_group, operators..., LiftOperator());
605 }
606}
607
608template <class Plugin>
609void select_drag_and(CouplingDispatchData& data, const cuda_general_cfd& h_gen_cfd, const CFDParticleGroup& h_group)
610{
611#ifndef CFD_NO_CUSTOM_LAWS
612 switch (h_group.drag_law)
613 {
614 case cfd_drag_law_custom:
615 select_lift_and<Plugin>(data, h_gen_cfd, h_group, custom_drag_operator<Plugin>());
616 break;
617 default: {
618#else
619 {{
620#endif
621 if (DragLightWeightOperator::valid(h_group.drag_law))
622 select_lift_and<Plugin>(data, h_gen_cfd, h_group, DragLightWeightOperator());
623 else if (DragHeavyWeightOperator::valid(h_group.drag_law))
624 select_lift_and<Plugin>(data, h_gen_cfd, h_group, DragHeavyWeightOperator());
625 else
626 select_lift_and<Plugin>(data, h_gen_cfd, h_group, DragOperator());
627 }
628 }
629}
630
631#endif
632
633template <class Plugin>
634void select_and_dispatch_coupling_kernel(
635 bool is_cuda, bool collect_cfd_data,
636 SDeviceModel* device_data, unsigned int* particle_indexes, int n_particles, void* udf_data,
637 const cuda_general_cfd& h_gen_cfd, const CFDParticleGroup& h_group
638)
639{
640#ifndef SKIP_COUPLING_COMPILATION
641 CouplingDispatchData data{ is_cuda, collect_cfd_data, device_data, particle_indexes, n_particles, udf_data };
642 select_drag_and<Plugin>(data, h_gen_cfd, h_group);
643#else
644 ROCKY_RUNTIME_ERROR("Rocky compiled without support to CFD coupling kernels")
645#endif
646}
647
648template <class backend, typename _Op>
649__host__ __device__ void api_compute_cfd_data_coupling(
650 SDeviceModel* device_data, double current_time, _Op op, void* udf_data)
651{
652 IRockyDeviceModel device_model_api;
653 device_model_api._impl.model = device_data;
654 device_model_api._impl.current_time = current_time;
655
656 IRockyParticle particle_api(-1, device_data);
657
659 cfd.model = device_data;
660
661 const cuda_general& general = device_data->get_general();
662
663 int thread_start, thread_step, thread_stop;
664 backend::ThreadIteration(thread_start, thread_step, thread_stop, general.nprt_active);
665 for (int i = thread_start; i < thread_stop; i += thread_step)
666 {
667 particle_api._impl.reset(i);
668 int ind_cfd = device_data->particle_scalars->get_cfd_index(i);
669 if (!particle_api._impl.particle->enabled() || ind_cfd < 0)
670 {
671 continue;
672 }
673
674 cfd.reset(i, ind_cfd);
675
676 op(device_model_api, particle_api, cfd, udf_data);
677 }
678}
679
680} // namespace device
Definition rocky_cfd.hpp:27
ROCKY_FUNCTIONS double3 get_relative_velocity() const
Definition rocky_cfd.hpp:113
ROCKY_FUNCTIONS double get_fluid_temperature() const
Definition rocky_cfd.hpp:55
Definition rocky_model_api.hpp:20
Definition rocky_particle_api.hpp:28
ROCKY_FUNCTIONS IRockyParticleScalars get_scalars()
Definition rocky_particle_api.hpp:536
ROCKY_FUNCTIONS double3 get_translational_velocity() const
Definition rocky_particle_api.hpp:415

Connect with Ansys