api_device_particles Last update: 16.07.2025 1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited. 2#pragma once 3 4#include <rocky20/api/rocky_model_api.hpp> 5 6namespace device 7{ 8 9template <class backend, typename Callable> 10__global__ void execute_particles_function( 11 SDeviceModel* device_data, double current_time, 12 Callable particle_f_ptr, 13 void* udf_data 14) 15{ 16 IRockyDeviceModel device_model_api; 17 device_model_api._impl.model = device_data; 18 device_model_api._impl.current_time = current_time; 19 20 const cuda_general& general = device_data->get_general(); 21 const cuda_particle* particles = device_data->prt; 22 23 int thread_start, thread_step, thread_stop; 24 backend::ThreadIteration(thread_start, thread_step, thread_stop, general.nprt_active); 25 for (int i = thread_start; i < thread_stop; i += thread_step) 26 { 27 if (particles[i].enabled()) 28 { 29 IRockyParticle particle_api(i, device_data); 30 particle_f_ptr(device_model_api, particle_api, udf_data); 31 } 32 } 33} 34 35template <class backend, typename Callable> 36__host__ __device__ void compute_instantaneous_breakage( 37 SDeviceModel* device_data, int device_id, 38 Callable process_instantaneous_breakage_ptr, void* udf_data, 39 cu_real time_curr 40) 41{ 42 const cuda_general& general = device_data->get_general(); 43 44 if (time_curr < general.breakage_start_time || general.start_sim) return; 45 46 int j = 0; 47 auto* scalars = device_data->particle_scalars; 48 49 int* skip_counters = scalars->get_skip_breakage_counters(); 50 double* release_times = scalars->get_release_times(); 51 auto* breakage_states = scalars->get_breakage_states(); 52 53 int thread_start, thread_step, thread_stop; 54 backend::ThreadIteration(thread_start, thread_step, thread_stop, general.nprt_active); 55 for (int i = thread_start; i < thread_stop; i += thread_step) 56 { 57 IRockyParticle particle_api(i, device_data); 58 auto& particle = particle_api._impl; 59 auto& p_group = device_data->get_particle_group(particle.get_particle_group_index()); 60 61 if (skip_counters[i] < general.nbreak_dt_skip) skip_counters[i]++; 62 63 if (p_group.breakage_model == pbmInstantaneousCustom) 64 { 65 if (breakage_states[i].is_breakable() 66 && time_curr >= release_times[i] + general.breakage_start_release_time 67 && skip_counters[i] >= general.nbreak_dt_skip) 68 { 69 bool broken = false; 70 process_instantaneous_breakage_ptr(particle_api, broken, udf_data); 71 72 if (broken) 73 { 74 backend::AtomicAdd(device_data->nbreak, 1, j); 75 device_data->prt_brk[j].i = i; 76 } 77 } 78 } 79 } 80} 81 82} // namespace device IRockyDeviceModelDefinition rocky_model_api.hpp:20 IRockyParticleDefinition rocky_particle_api.hpp:28