Skip to main content

Rocky Solver SDK 2025 R2

api_omp_cfd_coupling

Last update: 16.07.2025
1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
2#pragma once
3
4#include <rocky20/device/omp_backend.hpp>
5#include <rocky20/api/device/api_device_cfd_coupling.hpp>
6
7namespace rocky::omp
8{
9
10template <class _Plugin=device::EmptyCustomCouplingPlugin>
11void select_and_dispatch_cfd_coupling_kernel(
12 IRockyModel& model,
13 DeviceParticleGroupData* device_group_data,
14 void** udf_devices_data
15)
16{
17 if (model.get_number_of_active_particles() <= 0)
18 return;
19
20 // shut up nvcc compile warnings when compiling device function version using OMPBackend
21#ifndef GPU_KERNEL_COMPILING_STAGE
22
23 bool collect_cfd_data = model._impl->GetDeviceModel(0).cfd_data_recorder != nullptr;
24 #pragma omp parallel num_threads(model.get_number_of_processes())
25 {
26 const auto& group_device_data = device_group_data[0];
27 model._impl->GetDeviceModel(0).cfd_monitor->thread_bins[OMPBackend::ThreadIndex()].reset();
28
29 unsigned int* group_particle_indexes = group_device_data.d_group_2_particles;
30 for (int i = 0; i < group_device_data.group_indexes.size(); ++i)
31 {
32 const int particle_group_index = group_device_data.group_indexes[i];
33 device::select_and_dispatch_coupling_kernel<_Plugin>(
34 false,
35 collect_cfd_data,
36 model.get_device_data(0),
37 group_particle_indexes,
38 group_device_data.n_particles_per_group[i],
39 (udf_devices_data != nullptr ? udf_devices_data[0] : nullptr),
40 model._impl->cfd_data.gen_cfd,
41 model._impl->cfd_data.cfd_particle_groups[particle_group_index]);
42 group_particle_indexes += group_device_data.n_particles_per_group[i];
43 }
44 }
45
46#endif
47}
48
49template <typename _Op>
50inline
51void dispatch_fluid_kernel(IRockyModel& model, _Op op, void** udf_devices_data)
52{
53 if (model.get_number_of_active_particles() <= 0)
54 return;
55
56 // shut up nvcc compile warnings when compiling device function version using OMPBackend
57#ifndef GPU_KERNEL_COMPILING_STAGE
58
59 #pragma omp parallel num_threads(model.get_number_of_processes())
60 device::api_compute_cfd_data_coupling<OMPBackend>(
61 model.get_device_data(0),
62 model.get_current_time(),
63 op,
64 (udf_devices_data != nullptr ? udf_devices_data[0] : nullptr)
65 );
66
67#endif
68}
69
70}
Definition rocky_api.h:58
int get_number_of_active_particles() const
Definition rocky_api.cpp:153
double get_current_time() const
Definition rocky_api.cpp:143

Connect with Ansys