22using namespace shamrock::sph;
26 template<
class vec,
class SPHKernel>
27 void SPHUtilities<vec, SPHKernel>::iterate_smoothing_length_cache(
33 sycl::range<1> update_range,
48 auto ploop_ptrs =
neigh_cache.get_read_access(depends_list);
49 auto eps =
eps_h.get_write_access(depends_list);
52 auto e = queue.
submit(depends_list, [&](sycl::handler &cgh) {
59 const flt part_mass = gpart_mass;
60 const flt h_max_tot_max_evol = h_evol_max;
61 const flt h_max_evol_p = h_evol_iter_max;
62 const flt h_max_evol_m = 1 / h_evol_iter_max;
64 shambase::parallel_for(cgh, update_range.size(),
"iter h", [=](
u32 id_a) {
65 if (eps[id_a] > 1e-6) {
69 flt h_a = h_new[id_a];
70 flt dint = h_a * h_a * Rkern * Rkern;
72 vec inter_box_a_min = xyz_a - h_a * Rkern;
73 vec inter_box_a_max = xyz_a + h_a * Rkern;
82 particle_looper.for_each_object(id_a, [&](u32 id_b) {
83 vec dr = xyz_a - r[id_b];
84 flt rab2 = sycl::dot(dr, dr);
90 flt rab = sycl::sqrt(rab2);
92 rho_sum += part_mass * SPHKernel::W_3d(rab, h_a);
93 sumdWdh += part_mass * SPHKernel::dhW_3d(rab, h_a);
96 using namespace shamrock::sph;
98 flt rho_ha = rho_h(part_mass, h_a, SPHKernel::hfactd);
99 flt new_h = newton_iterate_new_h(rho_ha, rho_sum, sumdWdh, h_a);
101 if (new_h < h_a * h_max_evol_m)
102 new_h = h_max_evol_m * h_a;
103 if (new_h > h_a * h_max_evol_p)
104 new_h = h_max_evol_p * h_a;
106 flt ha_0 = h_old[id_a];
108 if (new_h < ha_0 * h_max_tot_max_evol) {
110 eps[id_a] = sycl::fabs(new_h - h_a) / ha_0;
112 h_new[id_a] = ha_0 * h_max_tot_max_evol;
120 eps_h.complete_event_state(e);
126 neigh_cache.complete_event_state(resulting_events);
129 template<
class vec,
class SPHKernel,
class u_morton>
130 void SPHTreeUtilities<vec, SPHKernel, u_morton>::iterate_smoothing_length_tree(
131 sycl::buffer<vec> &merged_r,
132 sycl::buffer<flt> &hnew,
133 sycl::buffer<flt> &hold,
134 sycl::buffer<flt> &eps_h,
135 sycl::range<1> update_range,
140 flt h_evol_iter_max) {
143 .submit([&](sycl::handler &cgh) {
147 sycl::accessor eps{
eps_h, cgh, sycl::read_write};
148 sycl::accessor r{merged_r, cgh, sycl::read_only};
149 sycl::accessor
h_new{hnew, cgh, sycl::read_write};
150 sycl::accessor
h_old{hold, cgh, sycl::read_only};
153 const flt part_mass = gpart_mass;
154 const flt h_max_tot_max_evol = h_evol_max;
155 const flt h_max_evol_p = h_evol_iter_max;
156 const flt h_max_evol_m = 1 / h_evol_iter_max;
158 shambase::parallel_for(cgh, update_range.size(),
"iter h", [=](
u32 id_a) {
159 if (eps[id_a] > 1e-6) {
163 flt h_a = h_new[id_a];
164 flt dint = h_a * h_a * Rkern * Rkern;
166 vec inter_box_a_min = xyz_a - h_a * Rkern;
167 vec inter_box_a_max = xyz_a + h_a * Rkern;
172 particle_looper.rtree_for(
173 [&](u32, vec bmin, vec bmax) -> bool {
174 return shammath::domain_are_connected(
175 bmin, bmax, inter_box_a_min, inter_box_a_max);
179 vec dr = xyz_a - r[id_b];
180 flt rab2 = sycl::dot(dr, dr);
186 flt rab = sycl::sqrt(rab2);
188 rho_sum += part_mass * SPHKernel::W_3d(rab, h_a);
189 sumdWdh += part_mass * SPHKernel::dhW_3d(rab, h_a);
192 using namespace shamrock::sph;
194 flt rho_ha = rho_h(part_mass, h_a, SPHKernel::hfactd);
195 flt new_h = newton_iterate_new_h(rho_ha, rho_sum, sumdWdh, h_a);
197 if (new_h < h_a * h_max_evol_m)
198 new_h = h_max_evol_m * h_a;
199 if (new_h > h_a * h_max_evol_p)
200 new_h = h_max_evol_p * h_a;
202 flt ha_0 = h_old[id_a];
204 if (new_h < ha_0 * h_max_tot_max_evol) {
206 eps[id_a] = sycl::fabs(new_h - h_a) / ha_0;
208 h_new[id_a] = ha_0 * h_max_tot_max_evol;
217 template<
class vec,
class SPHKernel>
218 void SPHUtilities<vec, SPHKernel>::compute_omega(
222 sycl::range<1> part_range,
234 auto ploop_ptrs =
neigh_cache.get_read_access(depends_list);
236 auto e = queue.
submit(depends_list, [&](sycl::handler &cgh) {
241 const flt part_mass = gpart_mass;
243 shambase::parallel_for(cgh, part_range.size(),
"compute omega", [=](
u32 id_a) {
246 flt h_a = hpart[id_a];
247 flt dint = h_a * h_a * Rkern * Rkern;
253 flt part_omega_sum = 0;
259 particle_looper.for_each_object(id_a, [&](u32 id_b) {
260 vec dr = xyz_a - r[id_b];
261 flt rab2 = sycl::dot(dr, dr);
267 flt rab = sycl::sqrt(rab2);
269 rho_sum += part_mass * SPHKernel::W_3d(rab, h_a);
270 part_omega_sum += part_mass * SPHKernel::dhW_3d(rab, h_a);
273 using namespace shamrock::sph;
275 flt rho_ha = rho_h(part_mass, h_a, SPHKernel::hfactd);
276 flt omega_a = 1 + (h_a / (3 * rho_ha)) * part_omega_sum;
277 omega[id_a] = omega_a;
290 neigh_cache.complete_event_state(resulting_events);
293 template class SPHUtilities<f64_3, shammath::M4<f64>>;
294 template class SPHUtilities<f64_3, shammath::M6<f64>>;
295 template class SPHUtilities<f64_3, shammath::M8<f64>>;
297 template class SPHUtilities<f64_3, shammath::C2<f64>>;
298 template class SPHUtilities<f64_3, shammath::C4<f64>>;
299 template class SPHUtilities<f64_3, shammath::C6<f64>>;
301 template class SPHTreeUtilities<f64_3, shammath::M4<f64>,
u32>;
302 template class SPHTreeUtilities<f64_3, shammath::M6<f64>,
u64>;
303 template class SPHTreeUtilities<f64_3, shammath::M8<f64>,
u64>;
305 template class SPHTreeUtilities<f64_3, shammath::C2<f64>,
u32>;
306 template class SPHTreeUtilities<f64_3, shammath::C4<f64>,
u64>;
307 template class SPHTreeUtilities<f64_3, shammath::C6<f64>,
u64>;
constexpr const char * eps_h
Epsilon h references (for h-iteration convergence)
constexpr const char * h_new
New smoothing length references (for h-iteration)
constexpr const char * h_old
Old smoothing length references (for h-iteration)
constexpr const char * hpart
Smoothing length field.
constexpr const char * neigh_cache
Neighbor cache.
constexpr const char * omega
Grad-h correction factor \Omega.
sycl::queue & get_compute_queue(u32 id=0)
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
DeviceQueue & get_queue(u32 id=0)
Get a reference to a DeviceQueue.
Class to manage a list of SYCL events.
void add_event(sycl::event e)
Add an event to the list of events.
namespace for the sph model