44 template<
class AMRBlock,
class Tgr
idVec>
45 inline u32 get_merged_cell_index(TgridVec sibling_min, TgridVec merged_min) {
46 return AMRBlock::get_index(
47 {
static_cast<u32>(sibling_min.x() != merged_min.x()),
48 static_cast<u32>(sibling_min.y() != merged_min.y()),
49 static_cast<u32>(sibling_min.z() != merged_min.z())});
54template<
class Tvec,
class Tgr
idVec>
55template<
class UserAcc,
class... T>
62 using namespace shamrock::patch;
68 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
82 UserAcc uacc(depends_list, id_patch, cur_p, pdat,
args...);
84 auto refine_acc = refine_flags.get_write_access(depends_list);
85 auto derefine_acc = derefine_flags.get_write_access(depends_list);
88 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
89 cgh.parallel_for(sycl::range<1>(obj_cnt), [=](sycl::item<1> gid) {
90 bool flag_refine =
false;
91 bool flag_derefine =
false;
92 uacc.refine_criterion(gid.get_linear_id(), uacc, flag_refine, flag_derefine);
95 if (flag_refine && flag_derefine) {
96 flag_derefine =
false;
99 refine_acc[gid] = (flag_refine) ? 1 : 0;
100 derefine_acc[gid] = (flag_derefine) ? 1 : 0;
107 refine_flags.complete_event_state(resulting_events);
108 derefine_flags.complete_event_state(resulting_events);
110 uacc.finalize(resulting_events, id_patch, cur_p, pdat,
args...);
120 derefine_flags.copy_range(0, obj_cnt, derefine_flags_in);
124 auto acc_max = buf_cell_max.get_read_access(depends_list);
125 auto acc_want_merge = derefine_flags_in.get_read_access(depends_list);
126 auto acc_merge_flag = derefine_flags.get_write_access(depends_list);
129 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
130 cgh.parallel_for(sycl::range<1>(obj_cnt), [=](sycl::item<1> gid) {
131 u32 id = gid.get_linear_id();
133 std::array<BlockCoord, split_count> blocks;
134 bool do_merge =
true;
138 if (
id + split_count <= obj_cnt) {
139 bool all_want_to_merge =
true;
141 for (
u32 lid = 0; lid < split_count; lid++) {
142 blocks[lid] = BlockCoord{acc_min[gid + lid], acc_max[gid + lid]};
143 all_want_to_merge = all_want_to_merge && acc_want_merge[gid + lid];
146 do_merge = all_want_to_merge && BlockCoord::are_mergeable(blocks);
152 acc_merge_flag[gid] = do_merge;
157 buf_cell_max.complete_event_state(e);
158 derefine_flags_in.complete_event_state(e);
159 derefine_flags.complete_event_state(e);
169 "AMRGrid",
"patch ", id_patch,
"refine block count = ", buf_refine.get_size());
171 tot_refine += buf_refine.get_size();
174 dd_refine_list.add_obj(id_patch, std::move(buf_refine));
184 "AMRGrid",
"patch ", id_patch,
"merge block count = ", buf_derefine.get_size());
186 tot_derefine += buf_derefine.get_size();
189 dd_derefine_list.add_obj(id_patch, std::move(buf_derefine));
192 logger::info_ln(
"AMRGrid",
"on this process", tot_refine,
"blocks were refined");
194 "AMRGrid",
"on this process", tot_derefine * split_count,
"blocks were derefined");
196template<
class Tvec,
class Tgr
idVec>
197template<
class UserAcc>
201 using namespace shamrock::patch;
203 u64 sum_block_count = 0;
205 bool new_cell_were_added =
false;
217 pdat.expand(refine_flags.
get_size() * (split_count - 1));
224 auto block_bound_high = buf_cell_max.get_write_access(depends_list);
225 UserAcc uacc(depends_list, pdat);
229 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
230 u32 start_index_push = old_obj_cnt;
232 constexpr u32 new_splits = split_count - 1;
234 cgh.parallel_for(sycl::range<1>(refine_flags.
get_size()), [=](sycl::item<1> gid) {
235 u32 tid = gid.get_linear_id();
237 u32 idx_to_refine = index_to_ref[tid];
240 BlockCoord cur_block{
241 block_bound_low[idx_to_refine], block_bound_high[idx_to_refine]};
243 std::array<BlockCoord, split_count> block_coords
244 = BlockCoord::get_split(cur_block.bmin, cur_block.bmax);
247 std::array<u32, split_count> blocks_ids;
248 blocks_ids[0] = idx_to_refine;
253 for (
u32 pid = 0; pid < new_splits; pid++) {
254 blocks_ids[pid + 1] = start_index_push + tid * new_splits + pid;
260 for (
u32 pid = 0; pid < split_count; pid++) {
261 block_bound_low[blocks_ids[pid]] = block_coords[pid].bmin;
262 block_bound_high[blocks_ids[pid]] = block_coords[pid].bmax;
266 uacc.apply_refine(idx_to_refine, cur_block, blocks_ids, block_coords, uacc);
273 buf_cell_max.complete_event_state(resulting_events);
275 uacc.finalize(resulting_events, pdat);
281 new_cell_were_added = new_cell_were_added || refine_flags.
get_size() > 0;
286 return new_cell_were_added;
289template<
class Tvec,
class Tgr
idVec>
290template<
class UserAcc>
295 using namespace shamrock::patch;
297 bool cell_were_removed =
false;
300 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
307 if (derefine_flags.
get_size() > 0) {
311 keep_block_flag.fill(1);
318 auto block_bound_high = buf_cell_max.get_write_access(depends_list);
319 UserAcc uacc(depends_list, pdat);
321 auto flag_keep = keep_block_flag.get_write_access(depends_list);
324 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
325 cgh.parallel_for(sycl::range<1>(derefine_flags.
get_size()), [=](sycl::item<1> gid) {
326 u32 tid = gid.get_linear_id();
328 u32 idx_to_derefine = index_to_deref[gid];
331 std::array<u32, split_count> old_indexes;
333 for (u32 pid = 0; pid < split_count; pid++) {
334 old_indexes[pid] = idx_to_derefine + pid;
338 std::array<BlockCoord, split_count> block_coords;
340 for (
u32 pid = 0; pid < split_count; pid++) {
341 block_coords[pid] = BlockCoord{
342 block_bound_low[old_indexes[pid]], block_bound_high[old_indexes[pid]]};
346 BlockCoord merged_block_coord = BlockCoord::get_merge(block_coords);
349 block_bound_low[idx_to_derefine] = merged_block_coord.bmin;
350 block_bound_high[idx_to_derefine] = merged_block_coord.bmax;
354 for (
u32 pid = 1; pid < split_count; pid++) {
355 flag_keep[idx_to_derefine + pid] = 0;
360 old_indexes, block_coords, idx_to_derefine, merged_block_coord, uacc);
367 buf_cell_max.complete_event_state(resulting_events);
369 uacc.finalize(resulting_events, pdat);
371 keep_block_flag.complete_event_state(resulting_events);
382 "derefine block count ",
385 buf_keep.get_size());
387 if (buf_keep.get_size() == 0) {
388 throw std::runtime_error(
"buf keep must contain something at this point");
394 cell_were_removed = cell_were_removed || derefine_flags.
get_size() > 0;
398 return cell_were_removed;
401template<
class Tvec,
class Tgr
idVec>
402template<
class UserAccCrit,
class UserAccSplit,
class UserAccMerge>
407 AMRSortBlocks block_sorter(context, solver_config, storage);
408 block_sorter.reorder_amr_blocks();
414 gen_refine_block_changes<UserAccCrit>(dd_refine_list, dd_derefine_list);
418 internal_refine_grid<UserAccSplit>(std::move(dd_refine_list));
425 internal_derefine_grid<UserAccMerge>(std::move(dd_derefine_list));
428template<
class Tvec,
class Tgr
idVec>
432 class RefineCritBlock {
434 const TgridVec *block_low_bound;
435 const TgridVec *block_high_bound;
436 const Tscal *block_density_field;
438 Tscal one_over_Nside = 1. / AMRBlock::Nside;
444 sham::EventList &depends_list,
446 shamrock::patch::Patch p,
447 shamrock::patch::PatchDataLayer &pdat,
450 : dxfact(dxfact), wanted_mass(wanted_mass) {
452 block_low_bound = pdat.get_field<TgridVec>(0).get_buf().get_read_access(depends_list);
453 block_high_bound = pdat.get_field<TgridVec>(1).get_buf().get_read_access(depends_list);
454 block_density_field = pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
456 .get_read_access(depends_list);
460 sham::EventList &resulting_events,
462 shamrock::patch::Patch p,
463 shamrock::patch::PatchDataLayer &pdat,
467 sham::DeviceBuffer<i64_3> &buf_cell_low_bound = pdat.get_field<i64_3>(0).get_buf();
468 sham::DeviceBuffer<i64_3> &buf_cell_high_bound = pdat.get_field<i64_3>(1).get_buf();
472 pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
474 .complete_event_state(resulting_events);
477 void refine_criterion(
478 u32 block_id, RefineCritBlock acc,
bool &should_refine,
bool &should_derefine)
const {
480 TgridVec low_bound = acc.block_low_bound[block_id];
481 TgridVec high_bound = acc.block_high_bound[block_id];
484 = (high_bound - low_bound).
template convert<Tscal>() * (dxfact * one_over_Nside);
487 for (
u32 i = 0; i < AMRBlock::block_size; i++) {
488 sum_mass += acc.block_density_field[i + block_id * AMRBlock::block_size];
490 sum_mass *= block_cell_size.x() * block_cell_size.y() * block_cell_size.z();
492 if (sum_mass > wanted_mass * 8) {
493 should_refine =
true;
494 should_derefine =
false;
495 }
else if (sum_mass < wanted_mass) {
496 should_refine =
false;
497 should_derefine =
true;
499 should_refine =
false;
500 should_derefine =
false;
503 should_refine = should_refine && (high_bound.x() - low_bound.x() > AMRBlock::Nside);
504 should_refine = should_refine && (high_bound.y() - low_bound.y() > AMRBlock::Nside);
505 should_refine = should_refine && (high_bound.z() - low_bound.z() > AMRBlock::Nside);
509 class RefineCellAccessor {
515 RefineCellAccessor(sham::EventList &depends_list, shamrock::patch::PatchDataLayer &pdat) {
517 rho = pdat.get_field<
f64>(2).get_buf().get_write_access(depends_list);
518 rho_vel = pdat.get_field<f64_3>(3).get_buf().get_write_access(depends_list);
519 rhoE = pdat.get_field<
f64>(4).get_buf().get_write_access(depends_list);
522 void finalize(sham::EventList &resulting_events, shamrock::patch::PatchDataLayer &pdat) {
523 pdat.get_field<
f64>(2).get_buf().complete_event_state(resulting_events);
524 pdat.get_field<f64_3>(3).get_buf().complete_event_state(resulting_events);
525 pdat.get_field<
f64>(4).get_buf().complete_event_state(resulting_events);
530 BlockCoord cur_coords,
531 std::array<u32, 8> new_blocks,
532 std::array<BlockCoord, 8> new_block_coords,
533 RefineCellAccessor acc)
const {
535 auto get_coord_ref = [](
u32 i) -> std::array<u32, dim> {
536 constexpr u32 NsideBlockPow = 1;
537 constexpr u32 Nside = 1U << NsideBlockPow;
539 if constexpr (dim == 3) {
540 const u32 tmp = i >> NsideBlockPow;
541 return {i % Nside, (tmp) % Nside, (tmp) >> NsideBlockPow};
545 auto get_index_block = [](std::array<u32, dim> coord) ->
u32 {
546 constexpr u32 NsideBlockPow = 1;
547 constexpr u32 Nside = 1U << NsideBlockPow;
549 if constexpr (dim == 3) {
550 return coord[0] + Nside * coord[1] + Nside * Nside * coord[2];
554 auto get_gid_write = [&](std::array<u32, dim> &glid) ->
u32 {
555 std::array<u32, dim> bid
556 = {glid[0] >> AMRBlock::NsideBlockPow,
557 glid[1] >> AMRBlock::NsideBlockPow,
558 glid[2] >> AMRBlock::NsideBlockPow};
561 return new_blocks[get_index_block(bid)] * AMRBlock::block_size
562 + AMRBlock::get_index(
563 {glid[0] % AMRBlock::Nside,
564 glid[1] % AMRBlock::Nside,
565 glid[2] % AMRBlock::Nside});
568 std::array<f64, AMRBlock::block_size> old_rho_block;
569 std::array<f64_3, AMRBlock::block_size> old_rho_vel_block;
570 std::array<f64, AMRBlock::block_size> old_rhoE_block;
573 for (
u32 loc_id = 0; loc_id < AMRBlock::block_size; loc_id++) {
575 auto [lx, ly, lz] = get_coord_ref(loc_id);
576 u32 old_cell_idx = cur_idx * AMRBlock::block_size + loc_id;
577 old_rho_block[loc_id] = acc.rho[old_cell_idx];
578 old_rho_vel_block[loc_id] = acc.rho_vel[old_cell_idx];
579 old_rhoE_block[loc_id] = acc.rhoE[old_cell_idx];
582 for (
u32 loc_id = 0; loc_id < AMRBlock::block_size; loc_id++) {
584 auto [lx, ly, lz] = get_coord_ref(loc_id);
585 u32 old_cell_idx = cur_idx * AMRBlock::block_size + loc_id;
587 Tscal rho_block = old_rho_block[loc_id];
588 Tvec rho_vel_block = old_rho_vel_block[loc_id];
589 Tscal rhoE_block = old_rhoE_block[loc_id];
590 for (
u32 subdiv_lid = 0; subdiv_lid < 8; subdiv_lid++) {
592 auto [sx, sy, sz] = get_coord_ref(subdiv_lid);
594 std::array<u32, 3> glid = {lx * 2 + sx, ly * 2 + sy, lz * 2 + sz};
596 u32 new_cell_idx = get_gid_write(glid);
611 acc.rho[new_cell_idx] = rho_block;
612 acc.rho_vel[new_cell_idx] = rho_vel_block;
613 acc.rhoE[new_cell_idx] = rhoE_block;
619 std::array<u32, 8> old_blocks,
620 std::array<BlockCoord, 8> old_coords,
622 BlockCoord new_coord,
624 RefineCellAccessor acc)
const {
626 std::array<f64, AMRBlock::block_size> rho_block;
627 std::array<f64_3, AMRBlock::block_size> rho_vel_block;
628 std::array<f64, AMRBlock::block_size> rhoE_block;
630 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
631 rho_block[cell_id] = {};
632 rho_vel_block[cell_id] = {};
633 rhoE_block[cell_id] = {};
636 for (
u32 pid = 0; pid < 8; pid++) {
637 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
638 rho_block[cell_id] += acc.rho[old_blocks[pid] * AMRBlock::block_size + cell_id];
639 rho_vel_block[cell_id]
640 += acc.rho_vel[old_blocks[pid] * AMRBlock::block_size + cell_id];
642 += acc.rhoE[old_blocks[pid] * AMRBlock::block_size + cell_id];
646 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
647 rho_block[cell_id] /= 8;
648 rho_vel_block[cell_id] /= 8;
649 rhoE_block[cell_id] /= 8;
652 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
653 u32 newcell_idx = new_cell * AMRBlock::block_size + cell_id;
654 acc.rho[newcell_idx] = rho_block[cell_id];
655 acc.rho_vel[newcell_idx] = rho_vel_block[cell_id];
656 acc.rhoE[newcell_idx] = rhoE_block[cell_id];
661 using AMRmode_None =
typename AMRMode<Tvec, TgridVec>::None;
662 using AMRmode_DensityBased =
typename AMRMode<Tvec, TgridVec>::DensityBased;
664 bool has_cell_order_changed =
false;
666 if (AMRmode_None *cfg = std::get_if<AMRmode_None>(&solver_config.amr_mode.config)) {
669 AMRmode_DensityBased *cfg
670 = std::get_if<AMRmode_DensityBased>(&solver_config.amr_mode.config)) {
671 Tscal dxfact(solver_config.grid_coord_to_pos_fact);
677 gen_refine_block_changes_old<RefineCritBlock>(
678 refine_list, derefine_list, dxfact, cfg->crit_mass);
682 bool change_refine = internal_refine_grid_old<RefineCellAccessor>(std::move(refine_list));
690 = internal_derefine_grid_old<RefineCellAccessor>(std::move(derefine_list));
692 has_cell_order_changed = has_cell_order_changed || (change_refine || change_derefine);
697 "this AMR criterion is not implemented in the old AMR (cfg.set_amr_mode_old(False))");
700 if (has_cell_order_changed) {
702 AMRSortBlocks block_sorter(context, solver_config, storage);
703 block_sorter.reorder_amr_blocks();
707template<
class Tvec,
class Tgr
idVec>
708template<
class UserAcc,
class... T>
716 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
730 UserAcc uacc(depends_list, storage, id_patch, cur_p, pdat,
args...);
736 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
737 cgh.parallel_for(sycl::range<1>(obj_cnt), [=](sycl::item<1> gid) {
738 bool flag_refine =
false;
739 bool flag_derefine =
false;
740 uacc.refine_criterion_new(
741 gid.get_linear_id(), uacc, flag_refine, flag_derefine);
744 if (flag_refine && flag_derefine) {
745 flag_derefine =
false;
748 refine_acc[gid] = (flag_refine) ? 1 : 0;
749 derefine_acc[gid] = (flag_derefine) ? 1 : 0;
759 uacc.finalize_new(resulting_events, storage, id_patch, cur_p, pdat,
args...);
762 dd_refine_flags.add_obj(id_patch, std::move(refine_flags));
763 dd_derefine_flags.add_obj(id_patch, std::move(derefine_flags));
773template<
class Tvec,
class Tgr
idVec>
786 .get_refs_dir(Direction_::xp)
789 .get_refs_dir(Direction_::xm)
792 .get_refs_dir(Direction_::yp)
795 .get_refs_dir(Direction_::ym)
798 .get_refs_dir(Direction_::zp)
801 .get_refs_dir(Direction_::zm)
807 std::shared_ptr<sham::DeviceScheduler> dev_sched
808 = shamsys::instance::get_compute_scheduler_ptr();
812 for (
u32 pass = 0; pass < 100; pass++) {
814 changed_buf.set_val_at_idx(0, 0);
817 AMRGraphLinkiterator block_graph_xp
818 = block_graph_neighs_xp.get_read_access(depend_list);
819 AMRGraphLinkiterator block_graph_xm
820 = block_graph_neighs_xm.get_read_access(depend_list);
821 AMRGraphLinkiterator block_graph_yp
822 = block_graph_neighs_yp.get_read_access(depend_list);
823 AMRGraphLinkiterator block_graph_ym
824 = block_graph_neighs_ym.get_read_access(depend_list);
825 AMRGraphLinkiterator block_graph_zp
826 = block_graph_neighs_zp.get_read_access(depend_list);
827 AMRGraphLinkiterator block_graph_zm
828 = block_graph_neighs_zm.get_read_access(depend_list);
830 auto acc_amr_levels = buf_amr_block_levels.
get_read_access(depend_list);
831 auto acc_changed = changed_buf.get_write_access(depend_list);
835 auto e = q.
submit(depend_list, [&](sycl::handler &cgh) {
836 cgh.parallel_for(sycl::range<1>(obj_cnt), [=](sycl::item<1> gid) {
837 u32 block_id = gid.get_linear_id();
839 u32 cur_ref_flag = acc_ref_flags[block_id];
844 auto cur_block_level = acc_amr_levels[block_id];
846 auto check_2To1_ref = [&](
u32 nid) {
851 u32 neigh_ref_flag = acc_ref_flags[nid];
852 auto neigh_block_level = acc_amr_levels[nid];
854 auto cur_future = cur_block_level + (cur_ref_flag ? 1 : 0);
856 auto neigh_future = neigh_block_level + (neigh_ref_flag ? 1 : 0);
858 if (cur_ref_flag && (cur_future > neigh_future + 1)) {
860 if (!neigh_ref_flag) {
863 sycl::memory_order::relaxed,
864 sycl::memory_scope::system>
865 atomic_neigh_flag(acc_ref_flags[nid]);
866 atomic_neigh_flag.exchange(1);
870 sycl::memory_order::relaxed,
871 sycl::memory_scope::system>
872 atomic_changed(acc_changed[0]);
873 atomic_changed.exchange(1);
878 block_graph_xp.for_each_object_link(block_id, check_2To1_ref);
879 block_graph_xm.for_each_object_link(block_id, check_2To1_ref);
880 block_graph_yp.for_each_object_link(block_id, check_2To1_ref);
881 block_graph_ym.for_each_object_link(block_id, check_2To1_ref);
882 block_graph_zp.for_each_object_link(block_id, check_2To1_ref);
883 block_graph_zm.for_each_object_link(block_id, check_2To1_ref);
886 block_graph_neighs_xp.complete_event_state(e);
887 block_graph_neighs_xm.complete_event_state(e);
888 block_graph_neighs_yp.complete_event_state(e);
889 block_graph_neighs_ym.complete_event_state(e);
890 block_graph_neighs_zp.complete_event_state(e);
891 block_graph_neighs_zm.complete_event_state(e);
894 changed_buf.complete_event_state(e);
900 if (changed_buf.get_val_at_idx(0) == 0) {
901 logger::raw_ln(
"Refinement 2:1 balance converged in ", pass + 1,
" sweeps");
915 "AMRGrid",
"patch ", id_patch, dev_buf_ref.get_size(),
"marked for refinement + 2:1");
927template<
class Tvec,
class Tgr
idVec>
932 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
947 " Count block's flag for derefinement [No geometry validity check and no 2:1 check] \t "
949 dev_buf_deref_0.get_size(),
962 patch_derefine_flag.
copy_range(0, obj_cnt, patch_derefine_flag_in);
966 auto acc_max = buf_cell_max.get_read_access(depends_list);
968 auto acc_want_merge = patch_derefine_flag_in.get_read_access(depends_list);
970 auto acc_refine_flag = patch_refine_flag.
get_read_access(depends_list);
972 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
973 cgh.parallel_for(sycl::range<1>(obj_cnt), [=](sycl::item<1> gid) {
974 u32 id = gid.get_linear_id();
976 std::array<BlockCoord, split_count> blocks;
977 bool do_merge =
true;
981 if (
id + split_count <= obj_cnt) {
982 bool all_want_to_merge =
true;
984 auto get_coord = [](
u32 i) -> std::array<u32, dim> {
985 constexpr u32 NsideBlockPow = 1;
986 constexpr u32 Nside = 1U << NsideBlockPow;
988 if constexpr (dim == 3) {
989 const u32 tmp = i >> NsideBlockPow;
992 return {(tmp) >> NsideBlockPow, (tmp) % Nside, i % Nside};
997 = [=](BlockCoord target_block) -> std::array<BlockCoord, split_count> {
998 std::array<BlockCoord, split_count> ret;
999 auto bmin = target_block.bmin;
1000 auto bmax = target_block.bmax;
1001 auto split = bmin + (bmax - bmin) / 2;
1002 std::array<TgridVec, 3> szs = {bmin, split, bmax};
1003 for (
u32 i = 0; i < split_count; i++) {
1004 auto [lx, ly, lz] = get_coord(i);
1006 ret[i].bmin = TgridVec{szs[lx].x(), szs[ly].y(), szs[lz].z()};
1008 = TgridVec{szs[lx + 1].x(), szs[ly + 1].y(), szs[lz + 1].z()};
1014 for (
u32 b_lid = 0; b_lid < split_count; b_lid++) {
1015 blocks[b_lid] = BlockCoord{acc_min[
id + b_lid], acc_max[
id + b_lid]};
1016 all_want_to_merge = all_want_to_merge && acc_want_merge[
id + b_lid];
1019 BlockCoord merged = BlockCoord::get_merge(blocks);
1020 std::array<BlockCoord, split_count> splitted = get_split(merged);
1021 for (
u32 lid = 0; lid < split_count; lid++) {
1022 do_merge = do_merge && sham::equals(blocks[lid].bmin, splitted[lid].bmin)
1023 && sham::equals(blocks[lid].bmax, splitted[lid].bmax);
1026 do_merge = do_merge && all_want_to_merge;
1027 if (acc_refine_flag[
id] && do_merge) {
1034 acc_merge_flag[id] = do_merge;
1038 buf_cell_max.complete_event_state(e);
1039 patch_derefine_flag_in.complete_event_state(e);
1046 " Count block's flag for derefinement [After geometry validity check and before 2:1 "
1049 buf_derefine_1.get_size(),
1062template<
class Tvec,
class Tgr
idVec>
1068 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1081 .get_refs_dir(Direction_::xp)
1084 .get_refs_dir(Direction_::xm)
1087 .get_refs_dir(Direction_::yp)
1090 .get_refs_dir(Direction_::ym)
1093 .get_refs_dir(Direction_::zp)
1096 .get_refs_dir(Direction_::zm)
1106 std::shared_ptr<sham::DeviceScheduler> dev_sched
1107 = shamsys::instance::get_compute_scheduler_ptr();
1113 patch_derefine_flag.
copy_range(0, obj_cnt, patch_derefine_flag_old);
1118 for (
int it = 0; it < 100; it++) {
1119 changed_buf.set_val_at_idx(0, 0);
1123 AMRGraphLinkiterator block_graph_xp
1124 = block_graph_neighs_xp.get_read_access(depend_list);
1126 AMRGraphLinkiterator block_graph_xm
1127 = block_graph_neighs_xm.get_read_access(depend_list);
1128 AMRGraphLinkiterator block_graph_yp
1129 = block_graph_neighs_yp.get_read_access(depend_list);
1130 AMRGraphLinkiterator block_graph_ym
1131 = block_graph_neighs_ym.get_read_access(depend_list);
1132 AMRGraphLinkiterator block_graph_zp
1133 = block_graph_neighs_zp.get_read_access(depend_list);
1134 AMRGraphLinkiterator block_graph_zm
1135 = block_graph_neighs_zm.get_read_access(depend_list);
1137 auto acc_amr_levels = buf_amr_block_levels.
get_read_access(depend_list);
1139 auto acc_changed = changed_buf.get_write_access(depend_list);
1141 auto acc_deref_old = patch_derefine_flag_old.get_read_access(depend_list);
1142 auto acc_deref_new = patch_derefine_flag_new.get_write_access(depend_list);
1144 auto e_2to1 = q.
submit(depend_list, [&](sycl::handler &cgh) {
1145 cgh.parallel_for(sycl::range<1>(obj_cnt), [=](sycl::item<1> gid) {
1146 auto lid = gid.get_linear_id();
1148 auto old_flag = acc_deref_old[lid];
1149 auto new_flag = old_flag;
1151 auto check_2To1_der = [&](
u32 nid) {
1156 auto neigh_future = acc_amr_levels[nid] + (acc_ref_flag[nid] ? 1 : 0)
1157 - (acc_deref_old[nid] ? 1 : 0);
1159 auto my_future = acc_amr_levels[lid] - 1;
1161 if (neigh_future > my_future + 1) {
1169 for (
u32 i = 0; i < AMRBlock::block_size; i++) {
1170 block_graph_xp.for_each_object_link((lid + i), check_2To1_der);
1171 block_graph_xm.for_each_object_link((lid + i), check_2To1_der);
1172 block_graph_yp.for_each_object_link((lid + i), check_2To1_der);
1173 block_graph_ym.for_each_object_link((lid + i), check_2To1_der);
1174 block_graph_zp.for_each_object_link((lid + i), check_2To1_der);
1175 block_graph_zm.for_each_object_link((lid + i), check_2To1_der);
1178 if (old_flag != new_flag) {
1181 sycl::memory_order::relaxed,
1182 sycl::memory_scope::system>
1183 atomic_changed(acc_changed[0]);
1184 atomic_changed.exchange(1);
1188 acc_deref_new[lid] = new_flag;
1191 block_graph_neighs_xp.complete_event_state(e_2to1);
1192 block_graph_neighs_xm.complete_event_state(e_2to1);
1193 block_graph_neighs_yp.complete_event_state(e_2to1);
1194 block_graph_neighs_ym.complete_event_state(e_2to1);
1195 block_graph_neighs_zp.complete_event_state(e_2to1);
1196 block_graph_neighs_zm.complete_event_state(e_2to1);
1199 changed_buf.complete_event_state(e_2to1);
1201 patch_derefine_flag_old.complete_event_state(e_2to1);
1202 patch_derefine_flag_new.complete_event_state(e_2to1);
1205 std::swap(patch_derefine_flag_old, patch_derefine_flag_new);
1207 if (changed_buf.get_val_at_idx(0) == 0) {
1210 "Derefinement 2:1 balance converge in \t ", it + 1,
"\t sweeps \n\n");
1215 patch_derefine_flag_old.copy_range(0, obj_cnt, patch_derefine_flag);
1224 " Count block's flag for derefinement [After geometry validity check and after 2:1 "
1226 buf_derefine.get_size(),
1230 "AMRGrid",
"patch ", id_patch, buf_derefine.get_size(),
"marked for derefinement ");
1234template<
class Tvec,
class Tgr
idVec>
1235template<
class UserAcc>
1239 const AMRInterpMode amr_refine_interp_mode) {
1241 u64 sum_block_count = 0;
1243 bool new_cell_were_added =
false;
1245 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1250 dev_sched, dd_refine_flags.get(id_patch), old_obj_cnt);
1252 if (stream_compaction_result.get_size() > 0) {
1256 "Will refine \t", stream_compaction_result.get_size(),
" \t blocks \n\n");
1258 pdat.expand(
static_cast<u32>(stream_compaction_result.get_size()) * (split_count - 1));
1264 auto block_bound_high = buf_cell_max.get_write_access(depends_list);
1265 UserAcc uacc(depends_list, storage, id_patch, pdat, amr_refine_interp_mode);
1266 auto index_to_ref = stream_compaction_result.get_read_access(depends_list);
1269 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
1270 u32 start_index_push = old_obj_cnt;
1272 constexpr u32 new_splits = split_count - 1;
1275 sycl::range<1>(stream_compaction_result.get_size()), [=](sycl::item<1> gid) {
1276 u32 tid = gid.get_linear_id();
1278 u32 idx_to_refine = index_to_ref[gid];
1281 BlockCoord cur_block{
1282 block_bound_low[idx_to_refine], block_bound_high[idx_to_refine]};
1284 std::array<BlockCoord, split_count> block_coords
1285 = BlockCoord::get_split(cur_block.bmin, cur_block.bmax);
1288 std::array<u32, split_count> blocks_ids;
1289 blocks_ids[0] = idx_to_refine;
1294 for (
u32 pid = 0; pid < new_splits; pid++) {
1295 blocks_ids[pid + 1] = start_index_push + tid * new_splits + pid;
1301 for (
u32 pid = 0; pid < split_count; pid++) {
1302 block_bound_low[blocks_ids[pid]] = block_coords[pid].bmin;
1303 block_bound_high[blocks_ids[pid]] = block_coords[pid].bmax;
1307 uacc.apply_refine_new(
1308 idx_to_refine, cur_block, blocks_ids, block_coords, uacc);
1315 buf_cell_max.complete_event_state(resulting_events);
1316 stream_compaction_result.complete_event_state(e);
1317 uacc.finalize_new(resulting_events, storage, id_patch, pdat, amr_refine_interp_mode);
1320 shamlog_debug_ln(
"AMRGrid",
"patch ", id_patch,
"new block count = ", pdat.
get_obj_cnt());
1322 new_cell_were_added = new_cell_were_added || (stream_compaction_result.get_size() > 0);
1327 return new_cell_were_added;
1330template<
class Tvec,
class Tgr
idVec>
1331template<
class UserAcc>
1335 const AMRInterpMode amr_refine_interp_mode) {
1337 using namespace shamrock::patch;
1339 bool cell_were_removed =
false;
1342 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1346 u32 old_obj_cnt_before_refinement = dd_derefine_flags.get(id_patch).get_size();
1348 dev_sched, dd_derefine_flags.get(id_patch), old_obj_cnt_before_refinement);
1349 if (stream_compact_results.get_size() > 0) {
1351 sycl::buffer<u32> keep_block_flag
1360 auto block_bound_high = buf_cell_max.get_write_access(depends_list);
1361 UserAcc uacc(depends_list, storage, id_patch, pdat, amr_refine_interp_mode);
1362 auto index_to_deref = stream_compact_results.get_read_access(depends_list);
1365 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
1366 sycl::accessor flag_keep{keep_block_flag, cgh, sycl::read_write};
1368 sycl::range<1>(stream_compact_results.get_size()), [=](sycl::item<1> gid) {
1369 u32 tid = gid.get_linear_id();
1371 u32 idx_to_derefine = index_to_deref[gid];
1374 std::array<u32, split_count> old_indexes;
1376 for (u32 pid = 0; pid < split_count; pid++) {
1377 old_indexes[pid] = idx_to_derefine + pid;
1381 std::array<BlockCoord, split_count> block_coords;
1383 for (
u32 pid = 0; pid < split_count; pid++) {
1384 block_coords[pid] = BlockCoord{
1385 block_bound_low[old_indexes[pid]],
1386 block_bound_high[old_indexes[pid]]};
1390 BlockCoord merged_block_coord = BlockCoord::get_merge(block_coords);
1393 block_bound_low[idx_to_derefine] = merged_block_coord.bmin;
1394 block_bound_high[idx_to_derefine] = merged_block_coord.bmax;
1398 for (
u32 pid = 1; pid < split_count; pid++) {
1399 flag_keep[idx_to_derefine + pid] = 0;
1404 uacc.apply_derefine_new(
1405 old_indexes, block_coords, idx_to_derefine, merged_block_coord, uacc);
1412 buf_cell_max.complete_event_state(resulting_events);
1413 uacc.finalize_new(resulting_events, storage, id_patch, pdat, amr_refine_interp_mode);
1415 stream_compact_results.complete_event_state(resulting_events);
1425 "derefine block count = ",
1427 "new block count = ",
1431 throw std::runtime_error(
"opt buf must contain something at this point");
1438 cell_were_removed = cell_were_removed || stream_compact_results.get_size() > 0;
1442 return cell_were_removed;
1445template<
class Tvec,
class Tgr
idVec>
1446template<
class UserAccCrit,
class UserAccSplit,
class UserAccMerge>
1451 AMRSortBlocks block_sorter(context, solver_config, storage);
1452 block_sorter.reorder_amr_blocks();
1458 gen_refine_block_changes_new<UserAccCrit>(dd_refine_list, dd_derefine_list);
1462 internal_refine_grid_new<UserAccSplit>(std::move(dd_refine_list), amr_refine_interp_mode);
1469 internal_derefine_grid_new<UserAccMerge>(std::move(dd_derefine_list), amr_refine_interp_mode);
1472template<
class Tvec,
class Tgr
idVec>
1476 class RefineCritBlock {
1478 const TgridVec *block_low_bound;
1479 const TgridVec *block_high_bound;
1480 const Tscal *block_density_field;
1482 Tscal one_over_Nside = 1. / AMRBlock::Nside;
1495 : dxfact(dxfact), wanted_mass(wanted_mass) {
1497 block_low_bound = pdat.get_field<TgridVec>(0).get_buf().get_read_access(depends_list);
1498 block_high_bound = pdat.get_field<TgridVec>(1).get_buf().get_read_access(depends_list);
1499 block_density_field = pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
1501 .get_read_access(depends_list);
1511 Tscal wanted_mass) {
1513 pdat.get_field<TgridVec>(0).get_buf().complete_event_state(resulting_events);
1514 pdat.get_field<TgridVec>(1).get_buf().complete_event_state(resulting_events);
1515 pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
1517 .complete_event_state(resulting_events);
1520 void refine_criterion_new(
1521 u32 block_id, RefineCritBlock acc,
bool &should_refine,
bool &should_derefine)
const {
1523 TgridVec low_bound = acc.block_low_bound[block_id];
1524 TgridVec high_bound = acc.block_high_bound[block_id];
1526 Tvec block_cell_size
1527 = (high_bound - low_bound).
template convert<Tscal>() * (dxfact * one_over_Nside);
1530 for (
u32 i = 0; i < AMRBlock::block_size; i++) {
1531 sum_mass += acc.block_density_field[i + block_id * AMRBlock::block_size];
1533 sum_mass *= block_cell_size.x() * block_cell_size.y() * block_cell_size.z();
1535 if (sum_mass > wanted_mass * 8) {
1536 should_refine =
true;
1537 should_derefine =
false;
1538 }
else if (sum_mass < wanted_mass) {
1539 should_refine =
false;
1540 should_derefine =
true;
1542 should_refine =
false;
1543 should_derefine =
false;
1546 should_refine = should_refine && (high_bound.x() - low_bound.x() > AMRBlock::Nside);
1547 should_refine = should_refine && (high_bound.y() - low_bound.y() > AMRBlock::Nside);
1548 should_refine = should_refine && (high_bound.z() - low_bound.z() > AMRBlock::Nside);
1552 class RefineCellAccessor {
1560 const f64 *rho_old_snap;
1561 const f64_3 *rho_vel_old_snap;
1562 const f64 *rhoE_old_snap;
1566 f64 *phi_old =
nullptr;
1568 AMRInterpMode amr_ref_interp_mode;
1571 AMRGraphLinkiterator cell_graph_xp;
1572 AMRGraphLinkiterator cell_graph_xm;
1573 AMRGraphLinkiterator cell_graph_yp;
1574 AMRGraphLinkiterator cell_graph_ym;
1575 AMRGraphLinkiterator cell_graph_zp;
1576 AMRGraphLinkiterator cell_graph_zm;
1583 AMRInterpMode _amr_ref_interp_mode)
1586 .get_refs_dir(Direction::xp)
1589 .get_read_access(depends_list)),
1592 .get_refs_dir(Direction::xm)
1595 .get_read_access(depends_list)),
1598 .get_refs_dir(Direction::yp)
1601 .get_read_access(depends_list)),
1604 .get_refs_dir(Direction::ym)
1607 .get_read_access(depends_list)),
1610 .get_refs_dir(Direction::zp)
1613 .get_read_access(depends_list)),
1616 .get_refs_dir(Direction::zm)
1619 .get_read_access(depends_list)),
1620 amr_ref_interp_mode(_amr_ref_interp_mode)
1629 .get_read_access(depends_list);
1633 .get_read_access(depends_list);
1637 .get_read_access(depends_list);
1640 rho = pdat.get_field<
f64>(2).get_buf().get_write_access(depends_list);
1641 rho_vel = pdat.get_field<f64_3>(3).get_buf().get_write_access(depends_list);
1642 rhoE = pdat.get_field<
f64>(4).get_buf().get_write_access(depends_list);
1645 .get_write_access(depends_list);
1648 phi = pdat.get_field<
f64>(pdat.pdl().get_field_idx<f64>(
"phi"))
1650 .get_write_access(depends_list);
1651 phi_old = pdat.get_field<
f64>(pdat.pdl().get_field_idx<f64>(
"phi_old"))
1653 .get_write_access(depends_list);
1662 AMRInterpMode amr_ref_interp_mode) {
1664 pdat.get_field<
f64>(2).get_buf().complete_event_state(resulting_events);
1665 pdat.get_field<f64_3>(3).get_buf().complete_event_state(resulting_events);
1666 pdat.get_field<
f64>(4).get_buf().complete_event_state(resulting_events);
1669 pdat.get_field<
f64>(pdat.pdl().get_field_idx<f64>(
"phi"))
1671 .complete_event_state(resulting_events);
1672 pdat.get_field<
f64>(pdat.pdl().get_field_idx<f64>(
"phi_old"))
1674 .complete_event_state(resulting_events);
1678 .get_refs_dir(Direction_::xp)
1681 .complete_event_state(resulting_events);
1683 .get_refs_dir(Direction_::xm)
1686 .complete_event_state(resulting_events);
1688 .get_refs_dir(Direction_::yp)
1691 .complete_event_state(resulting_events);
1693 .get_refs_dir(Direction_::ym)
1696 .complete_event_state(resulting_events);
1698 .get_refs_dir(Direction_::zp)
1701 .complete_event_state(resulting_events);
1703 .get_refs_dir(Direction_::zm)
1706 .complete_event_state(resulting_events);
1710 .complete_event_state(resulting_events);
1716 .complete_event_state(resulting_events);
1720 .complete_event_state(resulting_events);
1724 .complete_event_state(resulting_events);
1727 void apply_refine_new(
1729 BlockCoord cur_coords,
1730 std::array<u32, 8> new_blocks,
1731 std::array<BlockCoord, 8> new_block_coords,
1732 RefineCellAccessor acc)
const {
1734 auto get_coord_ref = [](
u32 i) -> std::array<u32, dim> {
1735 constexpr u32 NsideBlockPow = 1;
1736 constexpr u32 Nside = 1U << NsideBlockPow;
1738 if constexpr (dim == 3) {
1739 const u32 tmp = i >> NsideBlockPow;
1740 return {i % Nside, (tmp) % Nside, (tmp) >> NsideBlockPow};
1744 auto get_index_block = [](std::array<u32, dim> coord) ->
u32 {
1745 constexpr u32 NsideBlockPow = 1;
1746 constexpr u32 Nside = 1U << NsideBlockPow;
1748 if constexpr (dim == 3) {
1749 return coord[0] + Nside * coord[1] + Nside * Nside * coord[2];
1753 auto get_gid_write = [&](std::array<u32, dim> &glid) ->
u32 {
1756 std::array<u32, dim> bid
1757 = {glid[0] >> AMRBlock::NsideBlockPow,
1758 glid[1] >> AMRBlock::NsideBlockPow,
1759 glid[2] >> AMRBlock::NsideBlockPow};
1762 auto new_glob_id = new_blocks[get_index_block(bid)] * AMRBlock::block_size;
1767 + AMRBlock::get_index(
1768 {glid[0] % AMRBlock::Nside,
1769 glid[1] % AMRBlock::Nside,
1770 glid[2] % AMRBlock::Nside});
1776 std::array<f64, AMRBlock::block_size> parent_phi{};
1777 std::array<f64, AMRBlock::block_size> parent_phi_old{};
1778 if (acc.phi !=
nullptr) {
1779 for (
u32 loc_id = 0; loc_id < AMRBlock::block_size; loc_id++) {
1780 parent_phi[loc_id] = acc.phi[cur_idx * AMRBlock::block_size + loc_id];
1781 parent_phi_old[loc_id] = acc.phi_old[cur_idx * AMRBlock::block_size + loc_id];
1785 for (
u32 loc_id = 0; loc_id < AMRBlock::block_size; loc_id++) {
1787 auto [lx, ly, lz] = get_coord_ref(loc_id);
1788 u32 old_cell_idx = cur_idx * AMRBlock::block_size + loc_id;
1791 Tscal delta_cell = cell_sizes[cur_idx];
1792 Tscal c_offset = delta_cell * 0.25;
1793 std::array<f64_3, AMRBlock::block_size> child_center_offsets;
1794 child_center_offsets[0] = {-c_offset, -c_offset, -c_offset};
1795 child_center_offsets[1] = {c_offset, -c_offset, -c_offset};
1796 child_center_offsets[2] = {-c_offset, c_offset, -c_offset};
1797 child_center_offsets[3] = {c_offset, c_offset, -c_offset};
1798 child_center_offsets[4] = {-c_offset, -c_offset, c_offset};
1799 child_center_offsets[5] = {c_offset, -c_offset, c_offset};
1800 child_center_offsets[6] = {-c_offset, c_offset, c_offset};
1801 child_center_offsets[7] = {c_offset, c_offset, c_offset};
1803 auto cons_var_slopes = get_3d_grad_cons<Tvec, Minmod>(
1805 AMRBlock::block_size,
1814 return acc.rho_old_snap[id];
1817 return acc.rho_vel_old_snap[id];
1820 return acc.rhoE_old_snap[id];
1823 std::array<f64, AMRBlock::block_size> _rho_block;
1824 std::array<f64_3, AMRBlock::block_size> _rho_vel_block;
1825 std::array<f64, AMRBlock::block_size> _rhoE_block;
1827 int mul_second_order
1828 = (acc.amr_ref_interp_mode == AMRInterpMode::SECOND_ORDER) ? 1 : 0;
1830 bool do_second_order =
true;
1832 for (
u32 subdiv_lid = 0; subdiv_lid < 8; subdiv_lid++) {
1834 = child_center_offsets[subdiv_lid][0] * cons_var_slopes[0]
1835 + child_center_offsets[subdiv_lid][1] * cons_var_slopes[1]
1836 + child_center_offsets[subdiv_lid][2] * cons_var_slopes[2];
1838 _rho_block[subdiv_lid]
1839 = acc.rho_old_snap[old_cell_idx] + cons_var_interp.rho * mul_second_order;
1840 _rho_vel_block[subdiv_lid] = acc.rho_vel_old_snap[old_cell_idx]
1841 + cons_var_interp.rhovel * mul_second_order;
1842 _rhoE_block[subdiv_lid]
1843 = acc.rhoE_old_snap[old_cell_idx] + cons_var_interp.rhoe * mul_second_order;
1846 = _rhoE_block[subdiv_lid]
1847 - 0.5 * sham::dot(_rho_vel_block[subdiv_lid], _rho_vel_block[subdiv_lid])
1848 / (_rho_block[subdiv_lid]);
1850 = do_second_order && (_rho_block[subdiv_lid] > 0.0) && (e_int > 0.0);
1853 for (
u32 subdiv_lid = 0; subdiv_lid < 8; subdiv_lid++) {
1855 auto [sx, sy, sz] = get_coord_ref(subdiv_lid);
1857 std::array<u32, 3> glid = {lx * 2 + sx, ly * 2 + sy, lz * 2 + sz};
1859 u32 new_cell_idx = get_gid_write(glid);
1861 acc.rho[new_cell_idx] = (do_second_order) ? _rho_block[subdiv_lid]
1862 : acc.rho_old_snap[old_cell_idx];
1863 acc.rho_vel[new_cell_idx] = (do_second_order)
1864 ? _rho_vel_block[subdiv_lid]
1865 : acc.rho_vel_old_snap[old_cell_idx];
1866 acc.rhoE[new_cell_idx] = (do_second_order) ? _rhoE_block[subdiv_lid]
1867 : acc.rhoE_old_snap[old_cell_idx];
1869 if (acc.phi !=
nullptr) {
1870 acc.phi[new_cell_idx] = parent_phi[loc_id];
1871 acc.phi_old[new_cell_idx] = parent_phi_old[loc_id];
1877 void apply_derefine_new(
1878 std::array<u32, 8> old_blocks,
1879 std::array<BlockCoord, 8> old_coords,
1881 BlockCoord new_coord,
1883 RefineCellAccessor acc)
const {
1885 std::array<f64, AMRBlock::block_size> rho_block;
1886 std::array<f64_3, AMRBlock::block_size> rho_vel_block;
1887 std::array<f64, AMRBlock::block_size> rhoE_block;
1890 std::array<f64, AMRBlock::block_size> phi_block{};
1891 std::array<f64, AMRBlock::block_size> phi_old_block{};
1894 for (
u32 pid = 0; pid < 8; pid++) {
1896 Tvec rho_vel_pid = {};
1897 Tscal rhoe_pid = {};
1899 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
1900 rho_pid += acc.rho[old_blocks[pid] * AMRBlock::block_size + cell_id];
1901 rho_vel_pid += acc.rho_vel[old_blocks[pid] * AMRBlock::block_size + cell_id];
1902 rhoe_pid += acc.rhoE[old_blocks[pid] * AMRBlock::block_size + cell_id];
1905 u32 cell_id = get_merged_cell_index<AMRBlock>(old_coords[pid].bmin, new_coord.bmin);
1907 rho_block[cell_id] = rho_pid * (1. / 8.);
1908 rho_vel_block[cell_id] = rho_vel_pid * (1. / 8.);
1909 rhoE_block[cell_id] = rhoe_pid * (1. / 8.);
1911 if (acc.phi !=
nullptr) {
1913 Tscal phi_old_pid = {};
1914 for (
u32 child_id = 0; child_id < AMRBlock::block_size; child_id++) {
1915 phi_pid += acc.phi[old_blocks[pid] * AMRBlock::block_size + child_id];
1917 += acc.phi_old[old_blocks[pid] * AMRBlock::block_size + child_id];
1919 phi_block[cell_id] = phi_pid * (1. / 8.);
1920 phi_old_block[cell_id] = phi_old_pid * (1. / 8.);
1924 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
1925 u32 newcell_idx = new_cell * AMRBlock::block_size + cell_id;
1926 acc.rho[newcell_idx] = rho_block[cell_id];
1927 acc.rho_vel[newcell_idx] = rho_vel_block[cell_id];
1928 acc.rhoE[newcell_idx] = rhoE_block[cell_id];
1930 if (acc.phi !=
nullptr) {
1931 acc.phi[newcell_idx] = phi_block[cell_id];
1932 acc.phi_old[newcell_idx] = phi_old_block[cell_id];
1941 class RefineCritPseudoGradientAccessor {
1943 Tscal one_over_Nside = 1. / AMRBlock::Nside;
1944 const TgridVec *block_low_bound;
1945 const TgridVec *block_high_bound;
1946 const Tscal *block_rho;
1947 const f64 *block_pressure;
1948 const f64_3 *block_velocity;
1950 const Tscal *rho_cons;
1953 u32 nblock_per_patch;
1955 AMRGraphLinkiterator cell_graph_xp;
1956 AMRGraphLinkiterator cell_graph_xm;
1957 AMRGraphLinkiterator cell_graph_yp;
1958 AMRGraphLinkiterator cell_graph_ym;
1959 AMRGraphLinkiterator cell_graph_zp;
1960 AMRGraphLinkiterator cell_graph_zm;
1962 RefineCritPseudoGradientAccessor(
1970 : error_min(err_min), error_max(err_max),
1973 .get_refs_dir(Direction_::xp)
1976 .get_read_access(depends_list)),
1979 .get_refs_dir(Direction_::xm)
1982 .get_read_access(depends_list)),
1985 .get_refs_dir(Direction_::yp)
1988 .get_read_access(depends_list)),
1991 .get_refs_dir(Direction_::ym)
1994 .get_read_access(depends_list)),
1997 .get_refs_dir(Direction_::zp)
2000 .get_read_access(depends_list)),
2003 .get_refs_dir(Direction_::zm)
2006 .get_read_access(depends_list))
2009 block_low_bound = pdat.get_field<TgridVec>(0).get_buf().get_read_access(depends_list);
2010 block_high_bound = pdat.get_field<TgridVec>(1).get_buf().get_read_access(depends_list);
2011 rho_cons = pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
2013 .get_read_access(depends_list);
2019 .get_read_access(depends_list);
2022 .get_read_access(depends_list);
2025 .get_read_access(depends_list);
2037 pdat.get_field<i64_3>(0).get_buf().complete_event_state(resulting_events);
2038 pdat.get_field<i64_3>(1).get_buf().complete_event_state(resulting_events);
2039 pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
2041 .complete_event_state(resulting_events);
2044 .get_refs_dir(Direction_::xp)
2047 .complete_event_state(resulting_events);
2050 .get_refs_dir(Direction_::xm)
2053 .complete_event_state(resulting_events);
2056 .get_refs_dir(Direction_::yp)
2059 .complete_event_state(resulting_events);
2061 .get_refs_dir(Direction_::ym)
2064 .complete_event_state(resulting_events);
2066 .get_refs_dir(Direction_::zp)
2069 .complete_event_state(resulting_events);
2071 .get_refs_dir(Direction_::zm)
2074 .complete_event_state(resulting_events);
2078 .complete_event_state(resulting_events);
2082 .complete_event_state(resulting_events);
2086 .complete_event_state(resulting_events);
2089 void refine_criterion_new(
2091 RefineCritPseudoGradientAccessor acc,
2092 bool &should_refine,
2093 bool &should_derefine)
const {
2094 TgridVec low_bound = acc.block_low_bound[block_id];
2095 TgridVec high_bound = acc.block_high_bound[block_id];
2114 Tscal block_rho_slope = shambase::VectorProperties<Tscal>::get_zero();
2134 Tscal block_press_grad = shambase::VectorProperties<Tscal>::get_zero();
2135 for (
u32 i = 0; i < AMRBlock::block_size; i++) {
2136 block_press_grad = sham::details::g_sycl_max(
2138 get_pseudo_grad<Tscal, Tvec>(
2139 i + block_id * AMRBlock::block_size,
2147 return block_pressure[id];
2151 Tscal error = sham::details::g_sycl_max(
2152 block_press_grad, sham::details::g_sycl_max(block_rho_slope, 0.0));
2154 should_refine =
false;
2155 should_derefine =
false;
2156 if (error > error_max) {
2157 should_refine =
true;
2158 }
else if (error < (error_min * error_max)) {
2159 should_derefine =
true;
2162 should_refine = should_refine && (high_bound.x() - low_bound.x() > AMRBlock::Nside);
2163 should_refine = should_refine && (high_bound.y() - low_bound.y() > AMRBlock::Nside);
2164 should_refine = should_refine && (high_bound.z() - low_bound.z() > AMRBlock::Nside);
2171 class RefineCritShearAccessor {
2173 Tscal one_over_Nside = 1. / AMRBlock::Nside;
2174 const TgridVec *block_low_bound;
2175 const TgridVec *block_high_bound;
2176 const Tscal *block_rho;
2177 const f64 *block_pressure;
2178 const f64_3 *block_velocity;
2184 AMRGraphLinkiterator cell_graph_xp;
2185 AMRGraphLinkiterator cell_graph_xm;
2186 AMRGraphLinkiterator cell_graph_yp;
2187 AMRGraphLinkiterator cell_graph_ym;
2188 AMRGraphLinkiterator cell_graph_zp;
2189 AMRGraphLinkiterator cell_graph_zm;
2191 RefineCritShearAccessor(
2200 : threshold(threshold), gamma(gamma), dxfact(dxfact),
2203 .get_refs_dir(Direction_::xp)
2206 .get_read_access(depends_list)),
2209 .get_refs_dir(Direction_::xm)
2212 .get_read_access(depends_list)),
2215 .get_refs_dir(Direction_::yp)
2218 .get_read_access(depends_list)),
2221 .get_refs_dir(Direction_::ym)
2224 .get_read_access(depends_list)),
2227 .get_refs_dir(Direction_::zp)
2230 .get_read_access(depends_list)),
2233 .get_refs_dir(Direction_::zm)
2236 .get_read_access(depends_list))
2239 block_low_bound = pdat.get_field<TgridVec>(0).get_buf().get_read_access(depends_list);
2240 block_high_bound = pdat.get_field<TgridVec>(1).get_buf().get_read_access(depends_list);
2244 .get_read_access(depends_list);
2247 .get_read_access(depends_list);
2250 .get_read_access(depends_list);
2263 pdat.get_field<i64_3>(0).get_buf().complete_event_state(resulting_events);
2264 pdat.get_field<i64_3>(1).get_buf().complete_event_state(resulting_events);
2267 .get_refs_dir(Direction_::xp)
2270 .complete_event_state(resulting_events);
2273 .get_refs_dir(Direction_::xm)
2276 .complete_event_state(resulting_events);
2279 .get_refs_dir(Direction_::yp)
2282 .complete_event_state(resulting_events);
2284 .get_refs_dir(Direction_::ym)
2287 .complete_event_state(resulting_events);
2289 .get_refs_dir(Direction_::zp)
2292 .complete_event_state(resulting_events);
2294 .get_refs_dir(Direction_::zm)
2297 .complete_event_state(resulting_events);
2301 .complete_event_state(resulting_events);
2305 .complete_event_state(resulting_events);
2309 .complete_event_state(resulting_events);
2312 void refine_criterion_new(
2314 RefineCritShearAccessor acc,
2315 bool &should_refine,
2316 bool &should_derefine)
const {
2317 TgridVec low_bound = acc.block_low_bound[block_id];
2318 TgridVec high_bound = acc.block_high_bound[block_id];
2320 Tvec block_cell_size
2321 = (high_bound - low_bound).
template convert<Tscal>() * (dxfact * one_over_Nside);
2323 Tscal block_normalized_shear = shambase::VectorProperties<Tscal>::get_zero();
2324 for (
u32 i = 0; i < AMRBlock::block_size; i++) {
2325 auto cell_id = i + block_id * AMRBlock::block_size;
2326 auto cs = sycl::sqrt(gamma * acc.block_pressure[cell_id] / acc.block_rho[cell_id]);
2327 block_normalized_shear = sham::details::g_sycl_max(
2328 block_normalized_shear,
2329 normalized_shear<Tvec>(
2341 return acc.block_velocity[id];
2344 should_refine =
false;
2345 should_derefine =
false;
2346 if (block_normalized_shear > threshold * threshold) {
2347 should_refine =
true;
2348 }
else if (block_normalized_shear < 0.25 * threshold * threshold) {
2349 should_derefine =
true;
2352 should_refine = should_refine && (high_bound.x() - low_bound.x() > AMRBlock::Nside);
2353 should_refine = should_refine && (high_bound.y() - low_bound.y() > AMRBlock::Nside);
2354 should_refine = should_refine && (high_bound.z() - low_bound.z() > AMRBlock::Nside);
2366 class RefineCritJeansLengthAccessor {
2368 Tscal one_over_Nside = 1. / AMRBlock::Nside;
2369 const TgridVec *block_low_bound;
2370 const TgridVec *block_high_bound;
2373 const Tscal *rhoetot;
2384 RefineCritJeansLengthAccessor(
2396 : dxfact(dxfact), N_J(N_J), G(G), use_barotrope(use_barotrope), barotrope(barotrope),
2397 adiabatic(adiabatic) {
2398 block_low_bound = pdat.get_field<TgridVec>(0).get_buf().get_read_access(depends_list);
2399 block_high_bound = pdat.get_field<TgridVec>(1).get_buf().get_read_access(depends_list);
2400 rho = pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
2402 .get_read_access(depends_list);
2403 rhovel = pdat.get_field<Tvec>(pdat.pdl().get_field_idx<Tvec>(
"rhovel"))
2405 .get_read_access(depends_list);
2406 rhoetot = pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rhoetot"))
2408 .get_read_access(depends_list);
2423 pdat.get_field<TgridVec>(0).get_buf().complete_event_state(resulting_events);
2424 pdat.get_field<TgridVec>(1).get_buf().complete_event_state(resulting_events);
2425 pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rho"))
2427 .complete_event_state(resulting_events);
2428 pdat.get_field<Tvec>(pdat.pdl().get_field_idx<Tvec>(
"rhovel"))
2430 .complete_event_state(resulting_events);
2431 pdat.get_field<Tscal>(pdat.pdl().get_field_idx<Tscal>(
"rhoetot"))
2433 .complete_event_state(resulting_events);
2436 void refine_criterion_new(
2438 RefineCritJeansLengthAccessor acc,
2439 bool &should_refine,
2440 bool &should_derefine)
const {
2441 TgridVec low_bound = acc.block_low_bound[block_id];
2442 TgridVec high_bound = acc.block_high_bound[block_id];
2445 Tscal dx = Tscal(high_bound.x() - low_bound.x()) * (dxfact * one_over_Nside);
2449 for (
u32 i = 0; i < AMRBlock::block_size; i++) {
2450 const u32 cell_id = i + block_id * AMRBlock::block_size;
2453 cons.rho = acc.rho[cell_id];
2454 cons.rhovel = acc.rhovel[cell_id];
2455 cons.rhoe = acc.rhoetot[cell_id];
2457 const Tscal cs = (use_barotrope)
2458 ? barotrope.sound_speed(barotrope.cons_to_prim(cons))
2459 : adiabatic.sound_speed(adiabatic.cons_to_prim(cons));
2461 const Tscal q = (N_J * dx) * (N_J * dx) * G * cons.rho
2462 / (shambase::constants::pi<Tscal> * cs * cs);
2463 q_max = sham::max(q_max, q);
2466 should_refine = q_max > 1;
2467 should_derefine = 4 * q_max < 0.5;
2469 should_refine = should_refine && (high_bound.x() - low_bound.x() > AMRBlock::Nside);
2470 should_refine = should_refine && (high_bound.y() - low_bound.y() > AMRBlock::Nside);
2471 should_refine = should_refine && (high_bound.z() - low_bound.z() > AMRBlock::Nside);
2478 class RefineCellAccessorAutogravity {
2490 AMRGraphLinkiterator cell_graph_xp;
2491 AMRGraphLinkiterator cell_graph_xm;
2492 AMRGraphLinkiterator cell_graph_yp;
2493 AMRGraphLinkiterator cell_graph_ym;
2494 AMRGraphLinkiterator cell_graph_zp;
2495 AMRGraphLinkiterator cell_graph_zm;
2497 RefineCellAccessorAutogravity(
2504 .get_refs_dir(Direction::xp)
2507 .get_read_access(depends_list)),
2510 .get_refs_dir(Direction::xm)
2513 .get_read_access(depends_list)),
2516 .get_refs_dir(Direction::yp)
2519 .get_read_access(depends_list)),
2522 .get_refs_dir(Direction::ym)
2525 .get_read_access(depends_list)),
2528 .get_refs_dir(Direction::zp)
2531 .get_read_access(depends_list)),
2534 .get_refs_dir(Direction::zm)
2537 .get_read_access(depends_list))
2541 rho = pdat.get_field<
f64>(2).get_buf().get_write_access(depends_list);
2542 rho_vel = pdat.get_field<f64_3>(3).get_buf().get_write_access(depends_list);
2543 rhoE = pdat.get_field<
f64>(4).get_buf().get_write_access(depends_list);
2544 phi_old = pdat.get_field<
f64>(pdat.pdl().get_field_idx<Tscal>(
"phi_old"))
2546 .get_write_access(depends_list);
2547 phi_new = pdat.get_field<
f64>(pdat.pdl().get_field_idx<Tscal>(
"phi"))
2549 .get_write_access(depends_list);
2557 pdat.get_field<
f64>(2).get_buf().complete_event_state(resulting_events);
2558 pdat.get_field<f64_3>(3).get_buf().complete_event_state(resulting_events);
2559 pdat.get_field<
f64>(4).get_buf().complete_event_state(resulting_events);
2560 pdat.get_field<
f64>(pdat.pdl().get_field_idx<Tscal>(
"phi_old"))
2562 .complete_event_state(resulting_events);
2563 pdat.get_field<
f64>(pdat.pdl().get_field_idx<Tscal>(
"phi"))
2565 .complete_event_state(resulting_events);
2568 .get_refs_dir(Direction_::xp)
2571 .complete_event_state(resulting_events);
2573 .get_refs_dir(Direction_::xm)
2576 .complete_event_state(resulting_events);
2578 .get_refs_dir(Direction_::yp)
2581 .complete_event_state(resulting_events);
2583 .get_refs_dir(Direction_::ym)
2586 .complete_event_state(resulting_events);
2588 .get_refs_dir(Direction_::zp)
2591 .complete_event_state(resulting_events);
2593 .get_refs_dir(Direction_::zm)
2596 .complete_event_state(resulting_events);
2599 void apply_refine_new(
2601 BlockCoord cur_coords,
2602 std::array<u32, 8> new_blocks,
2603 std::array<BlockCoord, 8> new_block_coords,
2604 RefineCellAccessorAutogravity acc)
const {
2606 auto get_coord_ref = [](
u32 i) -> std::array<u32, dim> {
2607 constexpr u32 NsideBlockPow = 1;
2608 constexpr u32 Nside = 1U << NsideBlockPow;
2610 if constexpr (dim == 3) {
2611 const u32 tmp = i >> NsideBlockPow;
2612 return {i % Nside, (tmp) % Nside, (tmp) >> NsideBlockPow};
2616 auto get_index_block = [](std::array<u32, dim> coord) ->
u32 {
2617 constexpr u32 NsideBlockPow = 1;
2618 constexpr u32 Nside = 1U << NsideBlockPow;
2620 if constexpr (dim == 3) {
2621 return coord[0] + Nside * coord[1] + Nside * Nside * coord[2];
2625 auto get_gid_write = [&](std::array<u32, dim> &glid) ->
u32 {
2628 std::array<u32, dim> bid
2629 = {glid[0] >> AMRBlock::NsideBlockPow,
2630 glid[1] >> AMRBlock::NsideBlockPow,
2631 glid[2] >> AMRBlock::NsideBlockPow};
2634 auto new_glob_id = new_blocks[get_index_block(bid)] * AMRBlock::block_size;
2639 + AMRBlock::get_index(
2640 {glid[0] % AMRBlock::Nside,
2641 glid[1] % AMRBlock::Nside,
2642 glid[2] % AMRBlock::Nside});
2645 std::array<f64, AMRBlock::block_size> old_rho_block;
2646 std::array<f64_3, AMRBlock::block_size> old_rho_vel_block;
2647 std::array<f64, AMRBlock::block_size> old_rhoE_block;
2648 std::array<f64, AMRBlock::block_size> old_phi_old_block;
2649 std::array<f64, AMRBlock::block_size> old_phi_new_block;
2652 for (
u32 loc_id = 0; loc_id < AMRBlock::block_size; loc_id++) {
2654 auto [lx, ly, lz] = get_coord_ref(loc_id);
2655 u32 old_cell_idx = cur_idx * AMRBlock::block_size + loc_id;
2656 old_rho_block[loc_id] = acc.rho[old_cell_idx];
2657 old_rho_vel_block[loc_id] = acc.rho_vel[old_cell_idx];
2658 old_rhoE_block[loc_id] = acc.rhoE[old_cell_idx];
2659 old_phi_old_block[loc_id] = acc.phi_old[old_cell_idx];
2660 old_phi_new_block[loc_id] = acc.phi_new[old_cell_idx];
2663 for (
u32 loc_id = 0; loc_id < AMRBlock::block_size; loc_id++) {
2665 auto [lx, ly, lz] = get_coord_ref(loc_id);
2666 u32 old_cell_idx = cur_idx * AMRBlock::block_size + loc_id;
2700 Tscal rho_block = old_rho_block[loc_id];
2701 Tvec rho_vel_block = old_rho_vel_block[loc_id];
2702 Tscal rhoE_block = old_rhoE_block[loc_id];
2703 Tscal phi_old_block = old_phi_old_block[loc_id];
2704 Tscal phi_new_block = old_phi_new_block[loc_id];
2706 for (
u32 subdiv_lid = 0; subdiv_lid < 8; subdiv_lid++) {
2708 auto [sx, sy, sz] = get_coord_ref(subdiv_lid);
2710 std::array<u32, 3> glid = {lx * 2 + sx, ly * 2 + sy, lz * 2 + sz};
2712 u32 new_cell_idx = get_gid_write(glid);
2723 acc.rho[new_cell_idx] = rho_block;
2724 acc.rho_vel[new_cell_idx] = rho_vel_block;
2725 acc.rhoE[new_cell_idx] = rhoE_block;
2726 acc.phi_old[new_cell_idx] = phi_old_block;
2727 acc.phi_new[new_cell_idx] = phi_new_block;
2732 void apply_derefine_new(
2733 std::array<u32, 8> old_blocks,
2734 std::array<BlockCoord, 8> old_coords,
2736 BlockCoord new_coord,
2738 RefineCellAccessorAutogravity acc)
const {
2740 std::array<f64, AMRBlock::block_size> rho_block;
2741 std::array<f64_3, AMRBlock::block_size> rho_vel_block;
2742 std::array<f64, AMRBlock::block_size> rhoE_block;
2743 std::array<f64, AMRBlock::block_size> phi_old_block;
2744 std::array<f64, AMRBlock::block_size> phi_new_block;
2746 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
2747 phi_old_block[cell_id] = {};
2748 phi_new_block[cell_id] = {};
2752 for (
u32 pid = 0; pid < 8; pid++) {
2754 Tvec rho_vel_pid = {};
2755 Tscal rhoe_pid = {};
2756 Tscal phi_old_pid = {};
2757 Tscal phi_new_pid = {};
2759 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
2760 rho_pid += acc.rho[old_blocks[pid] * AMRBlock::block_size + cell_id];
2761 rho_vel_pid += acc.rho_vel[old_blocks[pid] * AMRBlock::block_size + cell_id];
2762 rhoe_pid += acc.rhoE[old_blocks[pid] * AMRBlock::block_size + cell_id];
2763 phi_old_pid += acc.phi_old[old_blocks[pid] * AMRBlock::block_size + cell_id];
2764 phi_new_pid += acc.phi_new[old_blocks[pid] * AMRBlock::block_size + cell_id];
2767 u32 cell_id = get_merged_cell_index<AMRBlock>(old_coords[pid].bmin, new_coord.bmin);
2769 rho_block[cell_id] = rho_pid * (1. / 8.);
2770 rho_vel_block[cell_id] = rho_vel_pid * (1. / 8.);
2771 rhoE_block[cell_id] = rhoe_pid * (1. / 8.);
2776 for (
u32 cell_id = 0; cell_id < AMRBlock::block_size; cell_id++) {
2777 u32 newcell_idx = new_cell * AMRBlock::block_size + cell_id;
2778 acc.rho[newcell_idx] = rho_block[cell_id];
2779 acc.rho_vel[newcell_idx] = rho_vel_block[cell_id];
2780 acc.rhoE[newcell_idx] = rhoE_block[cell_id];
2794 bool has_cell_order_changed =
false;
2800 if (AMRmode_None *cfg = std::get_if<AMRmode_None>(&solver_config.amr_mode.config)) {
2803 if (AMRmode_DensityBased *cfg
2804 = std::get_if<AMRmode_DensityBased>(&solver_config.amr_mode.config)) {
2806 Tscal dxfact(solver_config.grid_coord_to_pos_fact);
2807 gen_refine_block_changes_new<RefineCritBlock>(
2808 refine_list, derefine_list, dxfact, cfg->crit_mass);
2812 AMRmode_PseudoGradientBased *cfg
2813 = std::get_if<AMRmode_PseudoGradientBased>(&solver_config.amr_mode.config)) {
2815 gen_refine_block_changes_new<RefineCritPseudoGradientAccessor>(
2816 refine_list, derefine_list, cfg->error_min, cfg->error_max);
2820 AMRmode_ShearBased *cfg
2821 = std::get_if<AMRmode_ShearBased>(&solver_config.amr_mode.config)) {
2822 Tscal dxfact(solver_config.grid_coord_to_pos_fact);
2823 Tscal gamma(solver_config.get_eos_gamma());
2825 gen_refine_block_changes_new<RefineCritShearAccessor>(
2826 refine_list, derefine_list, cfg->threshold, gamma, dxfact);
2830 AMRmode_JeansLengthBased *cfg
2831 = std::get_if<AMRmode_JeansLengthBased>(&solver_config.amr_mode.config)) {
2832 Tscal dxfact(solver_config.grid_coord_to_pos_fact);
2833 Tscal G = solver_config.get_constant_G();
2836 const auto *baro_cfg
2837 = std::get_if<CoolingInstantBarotropic>(&solver_config.cooling_config.config);
2841 bool use_barotrope = baro_cfg !=
nullptr;
2843 = (use_barotrope) ? baro_cfg->get_barotrope()
2847 gen_refine_block_changes_new<RefineCritJeansLengthAccessor>(
2863 enforce_two_to_one_refinement_new(refine_list);
2865 check_geometrical_validity(refine_list, derefine_list);
2867 enforce_two_to_one_derefinement_new(derefine_list, refine_list);
2870 const AMRInterpMode amr_ref_interp_mode = solver_config.amr_interp_mode;
2871 bool change_refine = internal_refine_grid_new<RefineCellAccessor>(
2872 std::move(refine_list), amr_ref_interp_mode);
2879 bool change_derefine = internal_derefine_grid_new<RefineCellAccessor>(
2880 std::move(derefine_list), amr_ref_interp_mode);
2882 has_cell_order_changed = has_cell_order_changed || (change_refine || change_derefine);
2884 if (has_cell_order_changed) {
2886 AMRSortBlocks block_sorter(context, solver_config, storage);
2887 block_sorter.reorder_amr_blocks();
double f64
Alias for double.
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.
void copy_range(size_t begin, size_t end, sham::DeviceBuffer< T, dest_target > &dest) const
Copy a range of elements from the buffer to another buffer.
size_t get_size() const
Gets the number of elements in 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::queue q
The SYCL queue associated with this context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
void add_event(sycl::event e)
Add an event to the list of events.
Represents a collection of objects distributed across patches identified by a u64 id.
FluidStateSpec implementation for a barotropic equation of state that is isothermal below a threshold...
void update_refinement_new()
bool has_field_name(const std::string &field_name) const
Check whether a field with the given name already exists.
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
void index_remap_resize(sycl::buffer< u32 > &index_map, u32 len)
this function remaps the patchdatafield like so val[id] = val[index_map[id]] This function can be use...
Class holding the value of numerous constants generated from the following source.
main include file for the shamalgs algorithms
Slope mode enum + json serialization/deserialization.
This header file contains utility functions related to exception handling in the code.
alias namespace to simplify the use of log functions
sycl::buffer< typename std::invoke_result_t< Fct, u32 > > gen_buffer_device(sycl::queue &q, u32 len, Fct &&func)
generate a buffer from a lambda expression based on the indexes
std::tuple< std::optional< sycl::buffer< u32 > >, u32 > stream_compact(sycl::queue &q, sycl::buffer< u32 > &buf_flags, u32 len)
Stream compaction algorithm.
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...
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
std::vector< std::string_view > args
Executable argument list (mapped from argv).
void raw_ln(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.
FluidStateSpec implementation for an ideal (adiabatic) gas equation of state.
Refine the blocks where the Jeans length is resolved by less than N_J cells.
Instantaneous cooling onto a barotrope (RAMSES-like).
Patch object that contain generic patch information.
u64 id_patch
unique key that identify the patch