23template<
class Tvec,
class Tgr
idVec>
24auto shammodels::basegodunov::modules::ComputeCFL<Tvec, TgridVec>::compute_cfl() -> Tscal {
28 using namespace shamrock::patch;
33 ComputeField<Tscal> cfl_dt = utility.make_compute_field<Tscal>(
"cfl_dt", AMRBlock::block_size);
38 const u32 icell_min = pdl.get_field_idx<TgridVec>(
"cell_min");
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");
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();
96 auto prim_state = adiab_fluid.cons_to_prim(conststate);
98 constexpr Tscal div = 1. / 3.;
100 Tscal cs = adiab_fluid.sound_speed(prim_state);
101 Tscal vnorm = sycl::length(prim_state.vel);
102 Tscal dt = C_safe * dx * div / (cs + vnorm);
108 cfl_dt_buf.complete_event_state(e);
110 buf_block_max.complete_event_state(e);
111 buf_rho.complete_event_state(e);
112 buf_rhov.complete_event_state(e);
113 buf_rhoe.complete_event_state(e);
116 Tscal rank_dt = cfl_dt.compute_rank_min();
120 Tscal next_cfl = shamalgs::collective::allreduce_min(rank_dt);
129template<
class Tvec,
class Tgr
idVec>
130auto shammodels::basegodunov::modules::ComputeCFL<Tvec, TgridVec>::compute_dust_cfl() -> Tscal {
134 using namespace shamrock::patch;
139 u32 ndust = solver_config.dust_config.ndust;
141 = utility.make_compute_field<Tscal>(
"dust_cfl_dt", ndust * AMRBlock::block_size);
146 const u32 icell_min = pdl.get_field_idx<TgridVec>(
"cell_min");
147 const u32 icell_max = pdl.get_field_idx<TgridVec>(
"cell_max");
148 const u32 irho_dust = pdl.get_field_idx<Tscal>(
"rho_dust");
149 const u32 irhovel_dust = pdl.get_field_idx<Tvec>(
"rhovel_dust");
169 auto dust_cfl_dt = dust_cfl_dt_buf.get_write_access(depends_list);
171 auto rhov_dust = buf_rhov_dust.get_read_access(depends_list);
172 auto acc_aabb_cell_size = block_cell_sizes.
get_read_access(depends_list);
174 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
175 Tscal C_safe = solver_config.Csafe;
177 shambase::parallel_for(cgh, ndust * cell_count,
"compute_dust_cfl", [=](
u64 gid) {
178 const u32 tmp_gid = (
u32) gid;
179 const u32 cell_global_id = tmp_gid / ndust;
180 const u32 ndust_off_loc = tmp_gid % ndust;
182 const u32 block_id = cell_global_id / AMRBlock::block_size;
183 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
186 rho_dust[ndust * cell_global_id + ndust_off_loc],
187 rhov_dust[ndust * cell_global_id + ndust_off_loc]};
188 Tscal dx = acc_aabb_cell_size[block_id];
191 auto prim_state = dust_fluid.cons_to_prim(conststate);
193 constexpr Tscal div = 1. / 3.;
195 Tscal vnorm = sycl::length(prim_state.vel);
196 Tscal dt = C_safe * dx * div / (vnorm);
198 dust_cfl_dt[ndust * cell_global_id + ndust_off_loc] = dt;
202 dust_cfl_dt_buf.complete_event_state(e);
204 buf_rhov_dust.complete_event_state(e);
208 Tscal rank_dust_dt = dust_cfl_dt.compute_rank_min();
213 Tscal next_dust_cfl = shamalgs::collective::allreduce_min(rank_dust_dt);
219 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.
Class to manage a list of SYCL events.
PatchDataLayer container class, the layout is described in patchdata_layout.
u32 get_obj_cnt() const
get the number of objects (particles) stored in this layer
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
Umbrella header pulling in the gas states and all gas Riemann solvers (Rusanov, HLL,...
Umbrella header pulling in the dust states and all dust Riemann solvers (HLL, Huang & Bai).
void info_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
FluidStateSpec implementation for an ideal (adiabatic) gas equation of state.
cons_to_prim/prim_to_cons/vn/flux wrapper for a pressureless (dust) fluid. Unlike FluidStateAdiabatic...
Patch object that contain generic patch information.
u64 id_patch
unique key that identify the patch