23template<
class Tvec,
class Tgr
idVec>
24template<shammath::Flu
idStateSpec FSpec>
25void shammodels::basegodunov::modules::ComputeCFL<Tvec, TgridVec>::compute_cfl_gas(
30 using namespace shamrock::patch;
65 auto cfl_dt = cfl_dt_buf.get_write_access(depends_list);
67 auto acc_block_max = buf_block_max.get_read_access(depends_list);
68 auto rho = buf_rho.get_read_access(depends_list);
69 auto rhov = buf_rhov.get_read_access(depends_list);
70 auto rhoe = buf_rhoe.get_read_access(depends_list);
72 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
73 Tscal C_safe = solver_config.Csafe;
75 Tscal one_over_Nside = 1. / AMRBlock::Nside;
77 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
81 shambase::parallel_for(cgh, cell_count,
"compute_cfl", [=](
u64 gid) {
82 const u32 cell_global_id = (
u32) gid;
84 const u32 block_id = cell_global_id / AMRBlock::block_size;
85 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
87 TgridVec lower = acc_block_min[block_id];
88 TgridVec upper = acc_block_max[block_id];
92 = (upper - lower).
template convert<Tscal>() * (dxfact * one_over_Nside);
93 Tscal dx = block_cell_size.x();
98 auto prim_state = fspec.cons_to_prim(conststate);
100 constexpr Tscal div = 1. / 3.;
102 Tscal cs = fspec.sound_speed(prim_state);
103 Tscal vnorm = sycl::length(prim_state.vel);
104 Tscal dt = C_safe * dx * div / (cs + vnorm);
110 cfl_dt_buf.complete_event_state(e);
112 buf_block_max.complete_event_state(e);
113 buf_rho.complete_event_state(e);
114 buf_rhov.complete_event_state(e);
115 buf_rhoe.complete_event_state(e);
119template<
class Tvec,
class Tgr
idVec>
132 [&](
const auto &eos_cfg) {
133 compute_cfl_gas(cfl_dt, eos_cfg.get_spec());
135 solver_config.eos_config.config);
137 Tscal rank_dt = cfl_dt.compute_rank_min();
141 Tscal next_cfl = shamalgs::collective::allreduce_min(rank_dt);
150template<
class Tvec,
class Tgr
idVec>
151auto shammodels::basegodunov::modules::ComputeCFL<Tvec, TgridVec>::compute_dust_cfl() -> Tscal {
155 using namespace shamrock::patch;
160 u32 ndust = solver_config.dust_config.ndust;
162 = utility.make_compute_field<Tscal>(
"dust_cfl_dt", ndust * AMRBlock::block_size);
167 const u32 icell_min = pdl.get_field_idx<TgridVec>(
"cell_min");
168 const u32 icell_max = pdl.get_field_idx<TgridVec>(
"cell_max");
169 const u32 irho_dust = pdl.get_field_idx<Tscal>(
"rho_dust");
170 const u32 irhovel_dust = pdl.get_field_idx<Tvec>(
"rhovel_dust");
190 auto dust_cfl_dt = dust_cfl_dt_buf.get_write_access(depends_list);
192 auto rhov_dust = buf_rhov_dust.get_read_access(depends_list);
193 auto acc_aabb_cell_size = block_cell_sizes.
get_read_access(depends_list);
195 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
196 Tscal C_safe = solver_config.Csafe;
198 shambase::parallel_for(cgh, ndust * cell_count,
"compute_dust_cfl", [=](
u64 gid) {
199 const u32 tmp_gid = (
u32) gid;
200 const u32 cell_global_id = tmp_gid / ndust;
201 const u32 ndust_off_loc = tmp_gid % ndust;
203 const u32 block_id = cell_global_id / AMRBlock::block_size;
204 const u32 cell_loc_id = cell_global_id % AMRBlock::block_size;
207 rho_dust[ndust * cell_global_id + ndust_off_loc],
208 rhov_dust[ndust * cell_global_id + ndust_off_loc]};
209 Tscal dx = acc_aabb_cell_size[block_id];
212 auto prim_state = dust_fluid.cons_to_prim(conststate);
214 constexpr Tscal div = 1. / 3.;
216 Tscal vnorm = sycl::length(prim_state.vel);
217 Tscal dt = C_safe * dx * div / (vnorm);
219 dust_cfl_dt[ndust * cell_global_id + ndust_off_loc] = dt;
223 dust_cfl_dt_buf.complete_event_state(e);
225 buf_rhov_dust.complete_event_state(e);
229 Tscal rank_dust_dt = dust_cfl_dt.compute_rank_min();
234 Tscal next_dust_cfl = shamalgs::collective::allreduce_min(rank_dust_dt);
240 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.
Tscal compute_cfl()
Gas CFL timestep, using the equation of state selected in solver_config.eos_config.
ComputeField< T > make_compute_field(std::string new_name, u32 nvar)
create a compute field and init it to zeros
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.
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.
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