23template<
class Tvec,
class Tgr
idVec>
28 using namespace shamrock::patch;
33 ComputeField<Tscal> cfl_dt = utility.make_compute_field<Tscal>(
"cfl_dt", AMRBlock::block_size);
39 const u32 icell_max = pdl.get_field_idx<TgridVec>(
"cell_max");
40 const u32 irho = pdl.get_field_idx<Tscal>(
"rho");
41 const u32 irhoetot = pdl.get_field_idx<Tscal>(
"rhoetot");
42 const u32 irhovel = pdl.get_field_idx<Tvec>(
"rhovel");
47 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
66 auto cfl_dt = cfl_dt_buf.get_write_access(depends_list);
68 auto acc_block_max = buf_block_max.get_read_access(depends_list);
69 auto rho = buf_rho.get_read_access(depends_list);
70 auto rhov = buf_rhov.get_read_access(depends_list);
71 auto rhoe = buf_rhoe.get_read_access(depends_list);
73 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
74 Tscal C_safe = solver_config.Csafe;
75 Tscal gamma = solver_config.eos_gamma;
77 Tscal one_over_Nside = 1. / AMRBlock::Nside;
79 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
80 shambase::parallel_for(cgh, cell_count,
"compute_cfl", [=](
u64 gid) {
81 const u32 cell_global_id = (
u32) gid;
83 const u32 block_id = cell_global_id / AMRBlock::block_size;
84 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
86 TgridVec lower = acc_block_min[block_id];
87 TgridVec upper = acc_block_max[block_id];
88 Tvec lower_flt = lower.template convert<Tscal>() * dxfact;
89 Tvec upper_flt = upper.template convert<Tscal>() * dxfact;
90 Tvec block_cell_size = (upper_flt - lower_flt) * one_over_Nside;
91 Tscal dx = block_cell_size.x();
95 auto prim_state = shammath::cons_to_prim(conststate, gamma);
97 constexpr Tscal div = 1. / 3.;
99 Tscal cs = sound_speed(prim_state, gamma);
100 Tscal vnorm = sycl::length(prim_state.vel);
101 Tscal dt = C_safe * dx * div / (cs + vnorm);
107 cfl_dt_buf.complete_event_state(e);
109 buf_block_max.complete_event_state(e);
110 buf_rho.complete_event_state(e);
111 buf_rhov.complete_event_state(e);
112 buf_rhoe.complete_event_state(e);
115 Tscal rank_dt = cfl_dt.compute_rank_min();
119 Tscal next_cfl = shamalgs::collective::allreduce_min(rank_dt);
122 logger::info_ln(
"amr::basegodunov",
"cfl dt =", next_cfl);
128template<
class Tvec,
class Tgr
idVec>
133 using namespace shamrock::patch;
138 u32 ndust = solver_config.dust_config.ndust;
140 = utility.make_compute_field<Tscal>(
"dust_cfl_dt", ndust * AMRBlock::block_size);
146 const u32 icell_max = pdl.get_field_idx<TgridVec>(
"cell_max");
147 const u32 irho_dust = pdl.get_field_idx<Tscal>(
"rho_dust");
148 const u32 irhovel_dust = pdl.get_field_idx<Tvec>(
"rhovel_dust");
153 u32 cell_count = pdat.get_obj_cnt() * AMRBlock::block_size;
168 auto dust_cfl_dt = dust_cfl_dt_buf.get_write_access(depends_list);
170 auto rhov_dust = buf_rhov_dust.get_read_access(depends_list);
171 auto acc_aabb_cell_size = block_cell_sizes.
get_read_access(depends_list);
173 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
174 Tscal C_safe = solver_config.Csafe;
176 shambase::parallel_for(cgh, ndust * cell_count,
"compute_dust_cfl", [=](
u64 gid) {
177 const u32 tmp_gid = (
u32) gid;
178 const u32 cell_global_id = tmp_gid / ndust;
179 const u32 ndust_off_loc = tmp_gid % ndust;
181 const u32 block_id = cell_global_id / AMRBlock::block_size;
182 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
185 rho_dust[ndust * cell_global_id + ndust_off_loc],
186 rhov_dust[ndust * cell_global_id + ndust_off_loc]};
187 Tscal dx = acc_aabb_cell_size[block_id];
189 auto prim_state = shammath::d_cons_to_prim(conststate);
191 constexpr Tscal div = 1. / 3.;
193 Tscal vnorm = sycl::length(prim_state.vel);
194 Tscal dt = C_safe * dx * div / (vnorm);
196 dust_cfl_dt[ndust * cell_global_id + ndust_off_loc] = dt;
200 dust_cfl_dt_buf.complete_event_state(e);
202 buf_rhov_dust.complete_event_state(e);
206 Tscal rank_dust_dt = dust_cfl_dt.compute_rank_min();
211 Tscal next_dust_cfl = shamalgs::collective::allreduce_min(rank_dust_dt);
214 logger::info_ln(
"amr::basegodunov",
"dust cfl dt =", next_dust_cfl);
217 return next_dust_cfl;
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.
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.
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
PatchDataLayer container class, the layout is described in patchdata_layout.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
namespace for math utility
namespace for the main framework
From original version by Thomas Guillet (T.A.Guillet@exeter.ac.uk)
This file contain states and Riemann solvers for dust.
Patch object that contain generic patch information.
u64 id_patch
unique key that identify the patch