34template<
class Tvec,
class Tgr
idVec>
35auto shammodels::zeus::Solver<Tvec, TgridVec>::evolve_once(Tscal t_current, Tscal dt_input)
43 logger::normal_ln(
"amr::Zeus", sham::format(
"t = {}, dt = {}", t_current, dt_input));
50 return scheduler().patch_data.owned_data.get(p.id_patch).get_obj_cnt();
55 storage.serial_patch_tree.set(std::move(_sptree));
58 modules::GhostZones gz(context, solver_config, storage);
59 gz.build_ghost_cache();
66 modules::AMRTree amrtree(context, solver_config, storage);
67 amrtree.build_trees();
69 amrtree.correct_bounding_box();
72 amrtree.build_neigh_cache();
74 modules::ComputePressure comp_eos(context, solver_config, storage);
77 modules::FaceFlagger compute_face_flag(context, solver_config, storage);
78 compute_face_flag.flag_faces();
79 compute_face_flag.split_face_list();
84 using namespace shamrock::patch;
86 using Block =
typename Config::AMRBlock;
88 "ghost_dump_debug" + std::to_string(t_current) + std::to_string(solver_config.use_van_leer)
89 + std::to_string(solver_config.use_consistent_transport));
91 bool do_debug_dump =
false;
95 debug_dump.create_id(p.id_patch);
100 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
101 debug_dump.get_file(p.id_patch).change_table_name(
"Nobj_original",
"u32");
102 debug_dump.get_file(p.id_patch).write_val(mpdat.original_elements);
103 debug_dump.get_file(p.id_patch).change_table_name(
"Nobj_total",
"u32");
104 debug_dump.get_file(p.id_patch).write_val(mpdat.total_elements);
109 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
121 = mpdat.pdat.get_field_buf_ref<Tscal>(irho_interf);
123 = mpdat.pdat.get_field_buf_ref<Tscal>(ieint_interf);
126 debug_dump.get_file(p.id_patch).change_table_name(
"cell_min",
"i64_3");
127 debug_dump.get_file(p.id_patch)
128 .write_table(cell_min.copy_to_stdvec(), mpdat.total_elements);
129 debug_dump.get_file(p.id_patch).change_table_name(
"cell_max",
"i64_3");
130 debug_dump.get_file(p.id_patch)
131 .write_table(cell_max.copy_to_stdvec(), mpdat.total_elements);
133 debug_dump.get_file(p.id_patch).change_table_name(
"rho",
"f64");
134 debug_dump.get_file(p.id_patch)
136 rho_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
137 debug_dump.get_file(p.id_patch).change_table_name(
"eint",
"f64");
138 debug_dump.get_file(p.id_patch)
140 eint_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
141 debug_dump.get_file(p.id_patch).change_table_name(
"vel",
"f64_3");
142 debug_dump.get_file(p.id_patch)
144 vel_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
158 using MergedPDat = shamrock::MergedPatchData;
159 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(id_patch);
160 return mpdat.pdat.get_field<Tvec>(ivel_interf);
164 modules::ValueLoader<Tvec, TgridVec, Tvec> val_load_vec(context, solver_config, storage);
165 storage.vel_n_xp.set(val_load_vec.load_value_with_gz(
"vel", {1, 0, 0},
"vel_n_xp"));
166 storage.vel_n_yp.set(val_load_vec.load_value_with_gz(
"vel", {0, 1, 0},
"vel_n_yp"));
167 storage.vel_n_zp.set(val_load_vec.load_value_with_gz(
"vel", {0, 0, 1},
"vel_n_zp"));
169 modules::ValueLoader<Tvec, TgridVec, Tscal> val_load_scal(context, solver_config, storage);
170 storage.rho_n_xm.set(val_load_scal.load_value_with_gz(
"rho", {-1, 0, 0},
"rho_n_xm"));
171 storage.rho_n_ym.set(val_load_scal.load_value_with_gz(
"rho", {0, -1, 0},
"rho_n_ym"));
172 storage.rho_n_zm.set(val_load_scal.load_value_with_gz(
"rho", {0, 0, -1},
"rho_n_zm"));
175 storage.pres_n_xm.set(
176 val_load_scal.load_value_with_gz(pressure_field, {-1, 0, 0},
"pres_n_xm"));
177 storage.pres_n_ym.set(
178 val_load_scal.load_value_with_gz(pressure_field, {0, -1, 0},
"pres_n_ym"));
179 storage.pres_n_zm.set(
180 val_load_scal.load_value_with_gz(pressure_field, {0, 0, -1},
"pres_n_zm"));
182 modules::SourceStep src_step(context, solver_config, storage);
183 src_step.compute_forces();
188 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
192 debug_dump.get_file(p.id_patch).change_table_name(
"force_press",
"f64_3");
193 debug_dump.get_file(p.id_patch)
195 forces_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
199 src_step.apply_force(dt_input);
201 src_step.compute_AV();
204 storage.q_AV_n_xm.set(val_load_vec.load_value_with_gz(q_AV, {-1, 0, 0},
"q_AV_n_xm"));
205 storage.q_AV_n_ym.set(val_load_vec.load_value_with_gz(q_AV, {0, -1, 0},
"q_AV_n_ym"));
206 storage.q_AV_n_zm.set(val_load_vec.load_value_with_gz(q_AV, {0, 0, -1},
"q_AV_n_zm"));
208 src_step.apply_AV(dt_input);
212 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
224 = mpdat.pdat.get_field_buf_ref<Tscal>(irho_interf);
226 = mpdat.pdat.get_field_buf_ref<Tscal>(ieint_interf);
229 debug_dump.get_file(p.id_patch).change_table_name(
"eint_post_source",
"f64");
230 debug_dump.get_file(p.id_patch)
232 eint_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
233 debug_dump.get_file(p.id_patch).change_table_name(
"vel_post_source",
"f64_3");
234 debug_dump.get_file(p.id_patch)
236 vel_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
240 src_step.compute_div_v();
241 src_step.update_eint_eos(dt_input);
246 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
250 debug_dump.get_file(p.id_patch).change_table_name(
"divv_source",
"f64");
251 debug_dump.get_file(p.id_patch)
252 .write_table(divv.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
256 storage.div_v_n.reset();
258 modules::WriteBack wb(context, solver_config, storage);
259 wb.write_back_merged_data();
261 storage.merged_patchdata_ghost.reset();
262 storage.ghost_layout.reset();
264 storage.vel_n.reset();
265 storage.vel_n_xp.reset();
266 storage.vel_n_yp.reset();
267 storage.vel_n_zp.reset();
269 storage.rho_n_xm.reset();
270 storage.rho_n_ym.reset();
271 storage.rho_n_zm.reset();
273 storage.pres_n_xm.reset();
274 storage.pres_n_ym.reset();
275 storage.pres_n_zm.reset();
277 storage.q_AV.reset();
278 storage.q_AV_n_xm.reset();
279 storage.q_AV_n_ym.reset();
280 storage.q_AV_n_zm.reset();
288 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
300 = mpdat.pdat.get_field_buf_ref<Tscal>(irho_interf);
302 = mpdat.pdat.get_field_buf_ref<Tscal>(ieint_interf);
305 debug_dump.get_file(p.id_patch).change_table_name(
"eint_start_transp",
"f64");
306 debug_dump.get_file(p.id_patch)
308 eint_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
309 debug_dump.get_file(p.id_patch).change_table_name(
"vel_start_transp",
"f64_3");
310 debug_dump.get_file(p.id_patch)
312 vel_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
316 modules::ValueLoader<Tvec, TgridVec, Tvec> val_load_vec_v2(context, solver_config, storage);
317 storage.vel_n_xp.set(val_load_vec_v2.load_value_with_gz(
"vel", {1, 0, 0},
"vel_n_xp"));
318 storage.vel_n_yp.set(val_load_vec_v2.load_value_with_gz(
"vel", {0, 1, 0},
"vel_n_yp"));
319 storage.vel_n_zp.set(val_load_vec_v2.load_value_with_gz(
"vel", {0, 0, 1},
"vel_n_zp"));
324 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
328 debug_dump.get_file(p.id_patch).change_table_name(
"vel_n_xp",
"f64_3");
329 debug_dump.get_file(p.id_patch)
331 vel_n_xp.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
389 modules::TransportStep transport(context, solver_config, storage);
390 transport.compute_cell_centered_momentas();
393 using Tscal8 = sycl::vec<Tscal, 8>;
396 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
400 debug_dump.get_file(p.id_patch).change_table_name(
"Q",
"f64_8");
401 debug_dump.get_file(p.id_patch)
402 .write_table(Q_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
406 storage.vel_n_xp.reset();
407 storage.vel_n_yp.reset();
408 storage.vel_n_zp.reset();
410 transport.compute_limiter();
413 using Tscal8 = sycl::vec<Tscal, 8>;
416 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
422 debug_dump.get_file(p.id_patch).change_table_name(
"ax",
"f64_8");
423 debug_dump.get_file(p.id_patch)
424 .write_table(ax_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
425 debug_dump.get_file(p.id_patch).change_table_name(
"ay",
"f64_8");
426 debug_dump.get_file(p.id_patch)
427 .write_table(ay_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
428 debug_dump.get_file(p.id_patch).change_table_name(
"az",
"f64_8");
429 debug_dump.get_file(p.id_patch)
430 .write_table(az_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
434 transport.compute_face_centered_moments(dt_input);
439 storage.Q_xm.reset();
440 storage.Q_ym.reset();
441 storage.Q_zm.reset();
443 transport.exchange_face_centered_gz();
446 using Tscal8 = sycl::vec<Tscal, 8>;
449 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
452 = storage.Qstar_x.get().get_buf_check(p.id_patch);
454 = storage.Qstar_y.get().get_buf_check(p.id_patch);
456 = storage.Qstar_z.get().get_buf_check(p.id_patch);
458 debug_dump.get_file(p.id_patch).change_table_name(
"Qstar_x",
"f64_8");
459 debug_dump.get_file(p.id_patch)
461 Qstarx_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
462 debug_dump.get_file(p.id_patch).change_table_name(
"Qstar_y",
"f64_8");
463 debug_dump.get_file(p.id_patch)
465 Qstary_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
466 debug_dump.get_file(p.id_patch).change_table_name(
"Qstar_z",
"f64_8");
467 debug_dump.get_file(p.id_patch)
469 Qstarz_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
473 transport.compute_flux();
476 using Tscal8 = sycl::vec<Tscal, 8>;
479 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
485 debug_dump.get_file(p.id_patch).change_table_name(
"Flux_x",
"f64_8");
486 debug_dump.get_file(p.id_patch)
488 Fluxx_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
489 debug_dump.get_file(p.id_patch).change_table_name(
"Flux_y",
"f64_8");
490 debug_dump.get_file(p.id_patch)
492 Fluxy_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
493 debug_dump.get_file(p.id_patch).change_table_name(
"Flux_z",
"f64_8");
494 debug_dump.get_file(p.id_patch)
496 Fluxz_buf.
copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
500 transport.compute_stencil_flux();
502 transport.update_Q(dt_input);
504 transport.compute_new_qte();
509 MergedPDat &mpdat = storage.merged_patchdata_ghost.get().get(p.id_patch);
518 = mpdat.pdat.get_field_buf_ref<Tscal>(irho_interf);
520 = mpdat.pdat.get_field_buf_ref<Tscal>(ieint_interf);
523 debug_dump.get_file(p.id_patch).change_table_name(
"rho_end_transp",
"f64");
524 debug_dump.get_file(p.id_patch)
526 rho_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
527 debug_dump.get_file(p.id_patch).change_table_name(
"eint_end_transp",
"f64");
528 debug_dump.get_file(p.id_patch)
530 eint_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
531 debug_dump.get_file(p.id_patch).change_table_name(
"vel_end_transp",
"f64_3");
532 debug_dump.get_file(p.id_patch)
534 vel_merged.copy_to_stdvec(), mpdat.total_elements * AMRBlock::block_size);
538 wb.write_back_merged_data();
541 storage.Q_xm.reset();
542 storage.Q_ym.reset();
543 storage.Q_zm.reset();
545 storage.face_lists.reset();
546 storage.pressure.reset();
547 storage.trees.reset();
548 storage.merge_patch_bounds.reset();
549 storage.merged_patchdata_ghost.reset();
550 storage.ghost_layout.reset();
551 storage.ghost_zone_infos.reset();
552 storage.serial_patch_tree.reset();
556 debug_dump.get_file(p.id_patch).close();
571 u64 rank_count = scheduler().get_rank_count() * AMRBlock::block_size;
574 u64 npatch = scheduler().patch_list.local.size();
576 std::string log_step = report_perf_timestep(
590 "amr::Zeus",
"estimated rate :", dt_input * (3600 / tstep.
elapsed_sec()),
"(tsim/hr)");
593 storage.timings_details.reset();
601 ComputeField<Tscal> cfl_dt = utility.make_compute_field<Tscal>(
"cfl_dt", AMRBlock::block_size);
603 Tscal gamma = solver_config.eos_gamma;
604 Tscal Csafe = solver_config.Csafe;
605 Tscal dxfact = solver_config.grid_coord_to_pos_fact;
606 Tscal one_over_Nside = 1. / AMRBlock::Nside;
621 auto acc_cfl_dt = cfl_dt_buf.get_write_access(depends_list);
623 auto acc_block_max = buf_block_max.get_read_access(depends_list);
624 auto acc_rho = buf_rho.get_read_access(depends_list);
625 auto acc_eint = buf_eint.get_read_access(depends_list);
626 auto acc_vel = buf_vel.get_read_access(depends_list);
628 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
629 shambase::parallel_for(cgh, cell_count,
"compute_cfl_zeus", [=](
u64 gid) {
630 const u32 block_id = (
u32) gid / AMRBlock::block_size;
632 TgridVec lower = acc_block_min[block_id];
633 TgridVec upper = acc_block_max[block_id];
634 Tvec lower_flt = lower.template convert<Tscal>() * dxfact;
635 Tvec upper_flt = upper.template convert<Tscal>() * dxfact;
636 Tvec block_cell_size = (upper_flt - lower_flt) * one_over_Nside;
637 Tscal dx = block_cell_size.x();
639 Tscal rho = acc_rho[gid];
640 Tscal eint = acc_eint[gid];
641 Tvec vel = acc_vel[gid];
643 Tscal press = (gamma - 1) * eint;
644 Tscal cs = sycl::sqrt(gamma * press / rho);
646 constexpr Tscal div = 1.;
648 Tscal dt_vel = dx / sycl::length(vel);
649 Tscal dt_cs = dx / cs;
651 = Csafe * div * sycl::rsqrt(sycl::pown(dt_vel, -2) + sycl::pown(dt_cs, -2));
653 acc_cfl_dt[gid] = dt;
657 cfl_dt_buf.complete_event_state(e);
659 buf_block_max.complete_event_state(e);
660 buf_rho.complete_event_state(e);
661 buf_eint.complete_event_state(e);
662 buf_vel.complete_event_state(e);
665 Tscal rank_dt = cfl_dt.compute_rank_min();
666 Tscal next_dt = shamalgs::collective::allreduce_min(rank_dt);
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A class to dump a simulation state into ASCII files.
A buffer allocated in USM (Unified Shared Memory).
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
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.
Class Timer measures the time elapsed since the timer was started.
f64 elapsed_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
void start()
Starts the timer.
void stop()
Stops the timer and stores the elapsed time in nanoseconds.
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
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
MemPerfInfos get_mem_perf_info()
Retrieve the memory performance information.
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 the main framework
void normal_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
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.
Structure to store the performance informations about memory allocation and deallocation.
f64 time_alloc_host
Time spent allocating memory on the host.
size_t max_allocated_byte_host
max bytes allocated on the host
f64 time_free_device
Time spent deallocating memory on the device.
size_t max_allocated_byte_device
max bytes allocated on the device
f64 time_alloc_device
Time spent allocating memory on the device.
f64 time_free_host
Time spent deallocating memory on the host.
Patch object that contain generic patch information.
u64 id_patch
unique key that identify the patch
f64 get_timer(std::string timername)
get a timer value