82template<
class Tvec,
template<
class>
class Kern>
83void shammodels::gsph::Solver<Tvec, Kern>::init_solver_graph() {
89 auto &sync_data = scheduler().synchronized_data;
93 = [&](
const std::string &name,
const std::string &tex_symbol,
auto init_value) {
94 using T =
decltype(init_value);
95 if (!sync_data.has_edge(name)) {
96 auto edge = sync_data.register_edge(
98 edge->data = std::move(init_value);
102 ensure_sync_edge(
"time",
"t", Tscal{0});
103 ensure_sync_edge(
"dt",
"dt", Tscal{0});
109 storage.part_counts = std::make_shared<shamrock::solvergraph::Indexes<u32>>(
110 edges::part_counts,
"N_{\\rm part}");
112 storage.part_counts_with_ghost = std::make_shared<shamrock::solvergraph::Indexes<u32>>(
113 edges::part_counts_with_ghost,
"N_{\\rm part, with ghost}");
115 storage.patch_rank_owner = std::make_shared<shamrock::solvergraph::RankGetter>(
116 [&](
u64 patch_id) ->
u32 {
117 return scheduler().get_patch_rank_owner(patch_id);
123 storage.positions_with_ghosts = std::make_shared<shamrock::solvergraph::FieldRefs<Tvec>>(
124 edges::positions_with_ghosts,
"\\mathbf{r}");
125 storage.hpart_with_ghosts
126 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(edges::hpart_with_ghosts,
"h");
129 = std::make_shared<shammodels::sph::solvergraph::NeighCache>(edges::neigh_cache,
"neigh");
132 storage.ghost_handler = storage.solver_graph.register_edge(
133 "ghost_handler", solvergraph::GhostHandlerEdge<Tvec>(
"ghost_handler",
"\\mathcal{G}"));
135 storage.omega = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1,
"omega",
"\\Omega");
136 storage.density = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1,
"density",
"\\rho");
137 storage.pressure = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1,
"pressure",
"P");
139 = std::make_shared<shamrock::solvergraph::Field<Tscal>>(1,
"soundspeed",
"c_s");
144 = std::make_shared<shamrock::solvergraph::Field<Tvec>>(1,
"grad_density",
"\\nabla\\rho");
145 storage.grad_pressure
146 = std::make_shared<shamrock::solvergraph::Field<Tvec>>(1,
"grad_pressure",
"\\nabla P");
148 = std::make_shared<shamrock::solvergraph::Field<Tvec>>(1,
"grad_vx",
"\\nabla v_x");
150 = std::make_shared<shamrock::solvergraph::Field<Tvec>>(1,
"grad_vy",
"\\nabla v_y");
152 = std::make_shared<shamrock::solvergraph::Field<Tvec>>(1,
"grad_vz",
"\\nabla v_z");
155template<
class Tvec,
template<
class>
class Kern>
156void shammodels::gsph::Solver<Tvec, Kern>::vtk_do_dump(
157 std::string filename,
bool add_patch_world_id) {
159 modules::VTKDump<Tvec, Kern>(context, solver_config).do_dump(filename, add_patch_world_id);
162template<
class Tvec,
template<
class>
class Kern>
163void shammodels::gsph::Solver<Tvec, Kern>::gen_serial_patch_tree() {
167 _sptree.attach_buf();
168 storage.serial_patch_tree.set(std::move(_sptree));
171template<
class Tvec,
template<
class>
class Kern>
175 using namespace shamrock::patch;
176 using namespace shamrock::solvergraph;
180 using BCConfig =
typename Config::BCConfig;
181 using BCFree =
typename BCConfig::Free;
182 using BCPeriodic =
typename BCConfig::Periodic;
183 using BCShearingPeriodic =
typename BCConfig::ShearingPeriodic;
185 const auto &bc_config = solver_config.boundary_config.config;
192 .set(GhostHandle{scheduler(), storage.patch_rank_owner, storage.xyzh_ghost_layout});
206 Tscal h_evol_max = solver_config.htol_up_coarse_cycle;
207 if (solver_config.is_force_inutsuka_v2()) {
208 h_evol_max *= shambase::constants::sqrt_2<Tscal>;
211 const u32 ihpart = sched.pdl_old().template get_field_idx<Tscal>(
"hpart");
213 PatchField<Tscal> interactR_patch = sched.map_owned_to_patch_field_simple<Tscal>(
215 if (!pdat.is_empty()) {
216 return pdat.get_field<Tscal>(ihpart).compute_max() * h_evol_max * Rkern;
218 return shambase::VectorProperties<Tscal>::get_min();
226 [](Tscal h0, Tscal h1, Tscal h2, Tscal h3, Tscal h4, Tscal h5, Tscal h6, Tscal h7) {
227 return sham::max_8points(h0, h1, h2, h3, h4, h5, h6, h7);
236 auto sim_box_edge = std::make_shared<ScalarEdge<shammath::AABB<Tvec>>>(
"",
"");
239 auto patch_tree_edge = std::make_shared<SerialPatchTreeRefEdge<Tvec>>(
"",
"");
240 patch_tree_edge->patch_tree = std::ref(sptree);
242 auto interact_radius_tree = std::make_shared<PatchtreeFieldEdge<Tscal>>(
"",
"");
243 interact_radius_tree->patchtree_field = std::move(interactR_mpi_tree);
247 auto interact_radius = std::make_shared<ScalarsEdge<Tscal>>(
"",
"");
248 interact_radius->values = std::move(interactR_patch.field_all);
250 auto local_patch_boxes = std::make_shared<ScalarsEdge<shammath::CoordRange<Tvec>>>(
"",
"");
251 sched.for_each_local_patch([&](
const Patch &p) {
252 local_patch_boxes->values.add_obj(p.id_patch, patch_coord_transf.to_obj_coord(p));
255 auto interface_infos = std::make_shared<DDSharedScalar<InterfaceBuildInfos>>(
"",
"");
259 [&](
const BCFree &) {
264 interact_radius_tree,
270 [&](
const BCPeriodic &) {
275 interact_radius_tree,
281 [&](
const BCShearingPeriodic &cfg) {
282 auto shear_value = IDataEdge<Tscal>::make_shared(
"",
"");
283 shear_value->data = cfg.shear_speed * time_val;
286 cfg.shear_base, cfg.shear_dir, cfg.shear_speed);
290 interact_radius_tree,
302 storage.ghost_patch_cache.set(
303 ghost_handle.gen_id_table_interfaces(std::move(interface_infos->values)));
306template<
class Tvec,
template<
class>
class Kern>
307void shammodels::gsph::Solver<Tvec, Kern>::clear_ghost_cache() {
309 storage.ghost_patch_cache.reset();
312template<
class Tvec,
template<
class>
class Kern>
313void shammodels::gsph::Solver<Tvec, Kern>::merge_position_ghost() {
316 storage.merged_xyzh.set(
319 .build_comm_merge_positions(storage.ghost_patch_cache.get()));
323 = storage.xyzh_ghost_layout->template get_field_idx<Tvec>(gsph::names::common::xyz);
324 const u32 ihpart_ghost
325 = storage.xyzh_ghost_layout->template get_field_idx<Tscal>(gsph::names::common::hpart);
329 = storage.merged_xyzh.get().template map<u32>(
331 return scheduler().patch_data.get_pdat(
id).get_obj_cnt();
336 = storage.merged_xyzh.get().template map<u32>(
346 return std::ref(mpdat.get_field<Tvec>(ixyz_ghost));
353 return std::ref(mpdat.get_field<Tscal>(ihpart_ghost));
357template<
class Tvec,
template<
class>
class Kern>
358void shammodels::gsph::Solver<Tvec, Kern>::build_merged_pos_trees() {
361 auto &merged_xyzh = storage.merged_xyzh.get();
362 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
366 = storage.xyzh_ghost_layout->template get_field_idx<Tvec>(gsph::names::common::xyz);
371 Tvec bmax = pos.compute_max();
372 Tvec bmin = pos.compute_min();
376 Tscal infty = std::numeric_limits<Tscal>::infinity();
379 aabb.lower[0] = std::nextafter(aabb.lower[0], -infty);
380 aabb.lower[1] = std::nextafter(aabb.lower[1], -infty);
381 aabb.lower[2] = std::nextafter(aabb.lower[2], -infty);
382 aabb.upper[0] = std::nextafter(aabb.upper[0], infty);
383 aabb.upper[1] = std::nextafter(aabb.upper[1], infty);
384 aabb.upper[2] = std::nextafter(aabb.upper[2], infty);
386 auto bvh = RTree::make_empty(dev_sched);
387 bvh.rebuild_from_positions(
388 pos.get_buf(), pos.get_obj_cnt(), aabb, solver_config.tree_reduction_level);
393 storage.merged_pos_trees.set(std::move(trees));
396template<
class Tvec,
template<
class>
class Kern>
397void shammodels::gsph::Solver<Tvec, Kern>::clear_merged_pos_trees() {
399 storage.merged_pos_trees.reset();
402template<
class Tvec,
template<
class>
class Kern>
403void shammodels::gsph::Solver<Tvec, Kern>::compute_presteps_rint() {
406 auto &xyzh_merged = storage.merged_xyzh.get();
407 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
415 Tscal htol = solver_config.htol_up_coarse_cycle;
416 if (solver_config.is_force_inutsuka_v2()) {
417 htol *= shambase::constants::sqrt_2<Tscal>;
420 storage.rtree_rint_field.set(
423 shamrock::patch::PatchDataLayer &tmp = xyzh_merged.get(id);
424 auto &buf = tmp.get_field_buf_ref<Tscal>(1);
425 auto buf_int = shamtree::new_empty_karras_radix_tree_field<Tscal>();
427 auto ret = shamtree::compute_tree_field_max_field<Tscal>(
429 rtree.reduced_morton_set.get_leaf_cell_iterator(),
435 dev_sched->get_queue(),
438 ret.buf_field.get_size(),
439 [htol](
u32 i, Tscal *h_tree) {
443 return std::move(ret);
447template<
class Tvec,
template<
class>
class Kern>
448void shammodels::gsph::Solver<Tvec, Kern>::reset_presteps_rint() {
449 storage.rtree_rint_field.reset();
452template<
class Tvec,
template<
class>
class Kern>
453void shammodels::gsph::Solver<Tvec, Kern>::start_neighbors_cache() {
459 Tscal h_tolerance = solver_config.htol_up_coarse_cycle;
466 if (solver_config.is_force_inutsuka_v2()) {
467 h_tolerance *= shambase::constants::sqrt_2<Tscal>;
472 auto &mfield = storage.merged_xyzh.get().get(patch_id);
478 = storage.rtree_rint_field.get().get(patch_id).buf_field;
480 RTree &tree = storage.merged_pos_trees.get().get(patch_id);
481 auto obj_it = tree.get_object_iterator();
485 constexpr Tscal Rker2 = Kernel::Rkern * Kernel::Rkern;
489 obj_cnt, shamsys::instance::get_compute_scheduler_ptr());
501 auto neigh_cnt = neigh_count.get_write_access(depends_list);
502 auto particle_looper = obj_it.get_read_access(depends_list);
504 auto e = q.
submit(depends_list, [&, h_tolerance](sycl::handler &cgh) {
505 shambase::parallel_for(cgh, obj_cnt,
"gsph_count_neighbors", [=](
u64 gid) {
508 Tscal rint_a =
hpart[id_a] * h_tolerance;
509 Tvec xyz_a =
xyz[id_a];
511 Tvec inter_box_a_min = xyz_a - rint_a * Kernel::Rkern;
512 Tvec inter_box_a_max = xyz_a + rint_a * Kernel::Rkern;
516 particle_looper.rtree_for(
518 Tscal int_r_max_cell = rint_tree[node_id] * Kernel::Rkern;
520 using namespace walker::interaction_crit;
522 return sph_radix_cell_crit(
531 Tvec dr = xyz_a -
xyz[id_b];
532 Tscal rab2 = sycl::dot(dr, dr);
533 Tscal rint_b =
hpart[id_b] * h_tolerance;
536 = rab2 > rint_a * rint_a * Rker2 && rab2 > rint_b * rint_b * Rker2;
538 cnt += (no_interact) ? 0 : 1;
541 neigh_cnt[id_a] = cnt;
547 neigh_count.complete_event_state(e);
549 obj_it.complete_event_state(e);
554 = shamrock::tree::prepare_object_cache(std::move(neigh_count), obj_cnt);
564 auto scanned_neigh_cnt = pcache.scanned_cnt.
get_read_access(depends_list);
566 auto particle_looper = obj_it.get_read_access(depends_list);
568 auto e = q.
submit(depends_list, [&, h_tolerance](sycl::handler &cgh) {
569 shambase::parallel_for(cgh, obj_cnt,
"gsph_fill_neighbors", [=](
u64 gid) {
572 Tscal rint_a =
hpart[id_a] * h_tolerance;
573 Tvec xyz_a =
xyz[id_a];
575 Tvec inter_box_a_min = xyz_a - rint_a * Kernel::Rkern;
576 Tvec inter_box_a_max = xyz_a + rint_a * Kernel::Rkern;
578 u32 write_idx = scanned_neigh_cnt[id_a];
580 particle_looper.rtree_for(
582 Tscal int_r_max_cell = rint_tree[node_id] * Kernel::Rkern;
584 using namespace walker::interaction_crit;
586 return sph_radix_cell_crit(
595 Tvec dr = xyz_a -
xyz[id_b];
596 Tscal rab2 = sycl::dot(dr, dr);
597 Tscal rint_b =
hpart[id_b] * h_tolerance;
600 = rab2 > rint_a * rint_a * Rker2 && rab2 > rint_b * rint_b * Rker2;
603 neigh[write_idx++] = id_b;
614 obj_it.complete_event_state(e);
622 using namespace shamrock::patch;
625 ncache.neigh_cache.add_obj(cur_p.
id_patch, build_neigh_cache(cur_p.
id_patch));
629 storage.timings_details.neighbors += time_neigh.
elapsed_sec();
632template<
class Tvec,
template<
class>
class Kern>
633void shammodels::gsph::Solver<Tvec, Kern>::reset_neighbors_cache() {
634 storage.neigh_cache->neigh_cache = {};
637template<
class Tvec,
template<
class>
class Kern>
642 using namespace shamrock::patch;
644 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
645 const Tscal pmass = solver_config.gpart_mass;
646 static constexpr Tscal Rkern = Kernel::Rkern;
650 "invalid gpart_mass 0 in compute_density, this configuration can not converge.");
663 auto &merged_xyzh = storage.merged_xyzh.get();
664 auto &neigh_cache = storage.neigh_cache->neigh_cache;
671 auto &mfield = merged_xyzh.get(p.
id_patch);
672 auto &pcache = neigh_cache.get(p.
id_patch);
675 auto &buf_xyz = mfield.template get_field_buf_ref<Tvec>(0);
676 auto &buf_hpart = pdat.get_field_buf_ref<Tscal>(ihpart);
683 auto ploop_ptrs = pcache.get_read_access(depends_list);
686 auto density_acc = dens_field.get_buf().get_write_access(depends_list);
688 auto e = q.
submit(depends_list, [&, pmass](sycl::handler &cgh) {
691 shambase::parallel_for(cgh, cnt,
"gsph_compute_density", [=](
u64 gid) {
694 Tvec xyz_a = xyz_acc[id_a];
695 Tscal h_a = h_acc[id_a];
696 Tscal dint = h_a * h_a * Rkern * Rkern;
700 Tscal rho_sum = pmass * Kernel::W_3d(Tscal(0), h_a);
702 particle_looper.for_each_object(id_a, [&](
u32 id_b) {
707 Tvec dr = xyz_a - xyz_acc[id_b];
708 Tscal rab2 = sycl::dot(dr, dr);
714 Tscal rab = sycl::sqrt(rab2);
715 rho_sum += pmass * Kernel::W_3d(rab, h_a);
718 density_acc[id_a] = sycl::max(rho_sum, Tscal(1e-30));
722 pcache.complete_event_state({e});
725 dens_field.get_buf().complete_event_state(e);
729template<
class Tvec,
template<
class>
class Kern>
730void shammodels::gsph::Solver<Tvec, Kern>::gsph_prestep(Tscal time_val, Tscal dt) {
733 shamlog_debug_ln(
"GSPH",
"Prestep at t =", time_val,
"dt =", dt);
736 using namespace shamrock::patch;
746 auto should_set_omega_mask = std::make_shared<shamrock::solvergraph::Field<u32>>(
747 1,
"should_set_omega_mask",
"should_set_omega_mask");
750 u32 hstep_max = solver_config.h_max_subcycles_count;
751 for (; hstep_cnt < hstep_max; hstep_cnt++) {
753 build_ghost_cache(time_val + dt);
754 merge_position_ghost();
755 build_merged_pos_trees();
756 compute_presteps_rint();
757 start_neighbors_cache();
759 _epsilon_h = utility.make_compute_field<Tscal>(
"epsilon_h", 1, Tscal(100));
760 _h_old = utility.save_field<Tscal>(ihpart,
"h_old");
764 if (solver_config.gpart_mass == 0) {
766 "invalid gpart_mass {}, this configuration can not converge.\n"
767 "Please set it using either model.set_particle_mass(pmass) or "
768 "cfg.set_particle_mass(pmass)",
769 solver_config.gpart_mass));
773 std::shared_ptr<shamrock::solvergraph::Indexes<u32>> sizes
774 = std::make_shared<shamrock::solvergraph::Indexes<u32>>(
"",
"");
783 auto &
pos_merged = storage.positions_with_ghosts;
786 std::shared_ptr<shamrock::solvergraph::FieldRefs<Tscal>> hold
787 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
"",
"");
790 auto &field = _h_old.get_field(p.
id_patch);
791 hold_refs.add_obj(p.
id_patch, std::ref(field));
793 hold->set_refs(hold_refs);
796 std::shared_ptr<shamrock::solvergraph::FieldRefs<Tscal>> hnew
797 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
"",
"");
800 auto &field = pdat.get_field<Tscal>(ihpart);
801 hnew_refs.add_obj(p.
id_patch, std::ref(field));
803 hnew->set_refs(hnew_refs);
806 std::shared_ptr<shamrock::solvergraph::FieldRefs<Tscal>>
eps_h
807 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
"",
"");
810 auto &field = _epsilon_h.get_field(p.
id_patch);
811 eps_h_refs.add_obj(p.
id_patch, std::ref(field));
813 eps_h->set_refs(eps_h_refs);
815 std::shared_ptr<shamrock::solvergraph::INode> smth_h_iter_ptr;
817 using h_conf_density_based =
typename gsph::SmoothingLengthConfig::DensityBased;
818 using h_conf_neigh_lim =
typename gsph::SmoothingLengthConfig::DensityBasedNeighLim;
820 if (h_conf_density_based *conf
821 = std::get_if<h_conf_density_based>(&solver_config.smoothing_length_config.config)) {
822 std::shared_ptr<shammodels::sph::modules::IterateSmoothingLengthDensity<Tvec, Kernel>>
823 smth_h_iter = std::make_shared<
825 solver_config.gpart_mass,
826 solver_config.htol_up_coarse_cycle,
827 solver_config.htol_up_fine_cycle,
828 solver_config.epsilon_h);
829 smth_h_iter->set_edges(sizes, neigh_cache, pos_merged, hold, hnew, eps_h);
830 smth_h_iter_ptr = smth_h_iter;
832 h_conf_neigh_lim *conf
833 = std::get_if<h_conf_neigh_lim>(&solver_config.smoothing_length_config.config)) {
836 smth_h_iter_neigh_lim = std::make_shared<
838 solver_config.gpart_mass,
839 solver_config.htol_up_coarse_cycle,
840 solver_config.htol_up_fine_cycle,
841 conf->max_neigh_count,
842 solver_config.epsilon_h);
843 smth_h_iter_neigh_lim->set_edges(
844 sizes, neigh_cache, pos_merged, hold, hnew, eps_h, should_set_omega_mask);
845 smth_h_iter_ptr = smth_h_iter_neigh_lim;
851 std::shared_ptr<shamrock::solvergraph::IDataEdge<bool>> is_converged
852 = shamrock::solvergraph::IDataEdge<bool>::make_shared(
"",
"");
855 smth_h_iter_ptr, solver_config.epsilon_h, solver_config.h_iter_per_subcycles,
false);
856 loop_smth_h_iter.set_edges(eps_h, is_converged);
858 loop_smth_h_iter.evaluate();
860 if (!is_converged->data) {
865 largest_h = sham::max(largest_h, pdat.get_field<Tscal>(ihpart).compute_max());
867 Tscal global_largest_h = shamalgs::collective::allreduce_max(largest_h);
869 std::string add_info =
"";
870 u64 cnt_unconverged = 0;
873 = _epsilon_h.get_field(p.
id_patch).get_ids_where([](
auto access,
u32 id) {
874 return access[id] == -1;
877 if (hstep_cnt == hstep_max - 1) {
879 add_info +=
"\n patch " + std::to_string(p.
id_patch) +
" ";
880 add_info +=
"errored parts : \n";
885 auto pos =
xyz.copy_to_stdvec();
886 auto h =
hpart.copy_to_stdvec();
890 += sham::format(
"{} - pos : {}, hpart : {}\n", i, pos[i], h[i]);
895 cnt_unconverged += idx_err.
get_size();
898 u64 global_cnt_unconverged = shamalgs::collective::allreduce_sum(cnt_unconverged);
903 "smoothing length is not converged, rerunning the iterator ...\n largest h "
907 global_cnt_unconverged,
911 reset_ghost_handler();
919 storage.merged_xyzh.reset();
921 clear_merged_pos_trees();
922 reset_presteps_rint();
923 reset_neighbors_cache();
940 if (hstep_cnt == hstep_max) {
941 logger::err_ln(
"GSPH",
"the h iterator is not converged after", hstep_cnt,
"iterations");
944 std::shared_ptr<shamrock::solvergraph::FieldRefs<Tscal>> hnew_edge
945 = std::make_shared<shamrock::solvergraph::FieldRefs<Tscal>>(
"",
"");
948 auto &field = pdat.get_field<Tscal>(ihpart);
949 hnew_refs.add_obj(p.
id_patch, std::ref(field));
951 hnew_edge->set_refs(hnew_refs);
953 sph::modules::NodeComputeOmega<Tvec, Kern> compute_omega{solver_config.gpart_mass};
954 compute_omega.set_edges(
957 storage.positions_with_ghosts,
960 compute_omega.evaluate();
962 if (solver_config.smoothing_length_config.is_density_based_neigh_lim()) {
966 sph::modules::SetWhenMask<Tscal> set_omega_mask{1};
967 set_omega_mask.set_edges(storage.part_counts, should_set_omega_mask, storage.omega);
968 set_omega_mask.evaluate();
978template<
class Tvec,
template<
class>
class Kern>
979void shammodels::gsph::Solver<Tvec, Kern>::apply_position_boundary(Tscal time_val) {
982 shamlog_debug_ln(
"GSPH",
"apply position boundary");
988 auto &pdl = sched.pdl_old();
991 auto [bmin, bmax] = sched.get_box_volume<Tvec>();
993 using SolverConfigBC =
typename Config::BCConfig;
994 using SolverBCFree =
typename SolverConfigBC::Free;
995 using SolverBCPeriodic =
typename SolverConfigBC::Periodic;
996 using SolverBCShearingPeriodic =
typename SolverConfigBC::ShearingPeriodic;
998 if (SolverBCFree *c = std::get_if<SolverBCFree>(&solver_config.boundary_config.config)) {
1000 logger::info_ln(
"PositionUpdated",
"free boundaries skipping geometry update");
1004 = std::get_if<SolverBCPeriodic>(&solver_config.boundary_config.config)) {
1005 integrators.fields_apply_periodicity(ixyz, std::pair{bmin, bmax});
1007 SolverBCShearingPeriodic *c
1008 = std::get_if<SolverBCShearingPeriodic>(&solver_config.boundary_config.config)) {
1010 integrators.fields_apply_shearing_periodicity(
1013 std::pair{bmin, bmax},
1016 c->shear_speed * time_val,
1022 reatrib.reatribute_patch_objects(storage.serial_patch_tree.get(), gsph::names::common::xyz);
1025template<
class Tvec,
template<
class>
class Kern>
1026void shammodels::gsph::Solver<Tvec, Kern>::do_predictor_leapfrog(Tscal dt) {
1028 using namespace shamrock::patch;
1035 const bool has_uint = solver_config.has_field_uint();
1036 const u32 iuint = has_uint ? pdl.
get_field_idx<Tscal>(gsph::names::newtonian::uint) : 0;
1037 const u32 iduint = has_uint ? pdl.
get_field_idx<Tscal>(gsph::names::newtonian::duint) : 0;
1039 Tscal half_dt = dt / 2;
1047 auto &xyz_field = pdat.get_field<Tvec>(ixyz);
1048 auto &vxyz_field = pdat.get_field<Tvec>(ivxyz);
1049 auto &axyz_field = pdat.get_field<Tvec>(iaxyz);
1051 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1056 dev_sched->get_queue(),
1060 [half_dt, dt](
u32 i,
const Tvec *axyz, Tvec *xyz, Tvec *vxyz) {
1062 vxyz[i] += axyz[i] * half_dt;
1064 xyz[i] += vxyz[i] * dt;
1071 auto &uint_field = pdat.get_field<Tscal>(iuint);
1072 auto &duint_field = pdat.get_field<Tscal>(iduint);
1075 dev_sched->get_queue(),
1079 [half_dt](
u32 i,
const Tscal *duint, Tscal *uint) {
1081 uint[i] += duint[i] * half_dt;
1087template<
class Tvec,
template<
class>
class Kern>
1088void shammodels::gsph::Solver<Tvec, Kern>::init_ghost_layout() {
1092 storage.xyzh_ghost_layout = std::make_shared<shamrock::patch::PatchDataLayerLayout>();
1093 storage.xyzh_ghost_layout->template add_field<Tvec>(gsph::names::common::xyz, 1);
1094 storage.xyzh_ghost_layout->template add_field<Tscal>(gsph::names::common::hpart, 1);
1097 storage.ghost_layout = std::make_shared<shamrock::patch::PatchDataLayerLayout>();
1102 solver_config.set_ghost_layout(ghost_layout);
1105template<
class Tvec,
template<
class>
class Kern>
1106void shammodels::gsph::Solver<Tvec, Kern>::communicate_merge_ghosts_fields() {
1110 timer_interf.
start();
1113 using namespace shamrock::patch;
1120 const bool has_uint = solver_config.has_field_uint();
1121 const u32 iuint = has_uint ? pdl.
get_field_idx<Tscal>(gsph::names::newtonian::uint) : 0;
1123 auto &ghost_layout_ptr = storage.ghost_layout;
1125 u32 ihpart_interf = ghost_layout.
get_field_idx<Tscal>(gsph::names::common::hpart);
1126 u32 ivxyz_interf = ghost_layout.
get_field_idx<Tvec>(gsph::names::newtonian::vxyz);
1127 u32 iomega_interf = ghost_layout.
get_field_idx<Tscal>(gsph::names::newtonian::omega);
1128 u32 idensity_interf = ghost_layout.
get_field_idx<Tscal>(gsph::names::newtonian::density);
1130 = has_uint ? ghost_layout.
get_field_idx<Tscal>(gsph::names::newtonian::uint) : 0;
1133 const bool has_grads = solver_config.requires_gradients();
1135 = has_grads ? ghost_layout.
get_field_idx<Tvec>(gsph::names::newtonian::grad_density) : 0;
1137 = has_grads ? ghost_layout.
get_field_idx<Tvec>(gsph::names::newtonian::grad_pressure) : 0;
1139 = has_grads ? ghost_layout.
get_field_idx<Tvec>(gsph::names::newtonian::grad_vx) : 0;
1141 = has_grads ? ghost_layout.
get_field_idx<Tvec>(gsph::names::newtonian::grad_vy) : 0;
1143 = has_grads ? ghost_layout.
get_field_idx<Tvec>(gsph::names::newtonian::grad_vz) : 0;
1145 using InterfaceBuildInfos =
typename gsph::GSPHGhostHandler<Tvec>::InterfaceBuildInfos;
1147 gsph::GSPHGhostHandler<Tvec> &ghost_handle
1165 auto pdat_interf = ghost_handle.template build_interface_native<PatchDataLayer>(
1166 storage.ghost_patch_cache.get(),
1168 PatchDataLayer pdat(ghost_layout_ptr);
1174 ghost_handle.template modify_interface_native<PatchDataLayer>(
1175 storage.ghost_patch_cache.get(),
1179 InterfaceBuildInfos binfo,
1183 PatchDataLayer &sender_patch = scheduler().patch_data.get_pdat(sender);
1184 PatchDataField<Tscal> &sender_omega = omega.get(sender);
1185 PatchDataField<Tscal> &sender_density = density.get(sender);
1187 sender_patch.get_field<Tscal>(ihpart).append_subset_to(
1188 buf_idx, cnt, pdat.get_field<Tscal>(ihpart_interf));
1189 sender_patch.get_field<Tvec>(ivxyz).append_subset_to(
1190 buf_idx, cnt, pdat.get_field<Tvec>(ivxyz_interf));
1191 sender_omega.append_subset_to(buf_idx, cnt, pdat.get_field<Tscal>(iomega_interf));
1192 sender_density.append_subset_to(buf_idx, cnt, pdat.get_field<Tscal>(idensity_interf));
1195 sender_patch.get_field<Tscal>(iuint).append_subset_to(
1196 buf_idx, cnt, pdat.get_field<Tscal>(iuint_interf));
1201 grad_density_ptr->get(sender).append_subset_to(
1202 buf_idx, cnt, pdat.get_field<Tvec>(igrad_d_interf));
1203 grad_pressure_ptr->get(sender).append_subset_to(
1204 buf_idx, cnt, pdat.get_field<Tvec>(igrad_p_interf));
1205 grad_vx_ptr->get(sender).append_subset_to(
1206 buf_idx, cnt, pdat.get_field<Tvec>(igrad_vx_interf));
1207 grad_vy_ptr->get(sender).append_subset_to(
1208 buf_idx, cnt, pdat.get_field<Tvec>(igrad_vy_interf));
1209 grad_vz_ptr->get(sender).append_subset_to(
1210 buf_idx, cnt, pdat.get_field<Tvec>(igrad_vz_interf));
1215 ghost_handle.template modify_interface_native<PatchDataLayer>(
1216 storage.ghost_patch_cache.get(),
1220 InterfaceBuildInfos binfo,
1224 if (sycl::length(binfo.offset_speed) > 0) {
1225 pdat.get_field<Tvec>(ivxyz_interf).apply_offset(binfo.offset_speed);
1231 = ghost_handle.communicate_pdat(ghost_layout_ptr, std::move(pdat_interf));
1234 std::map<u64, u64> sz_interf_map;
1240 storage.merged_patchdata_ghost.set(
1241 ghost_handle.template merge_native<PatchDataLayer, PatchDataLayer>(
1242 std::move(interf_pdat),
1244 PatchDataLayer pdat_new(ghost_layout_ptr);
1246 u32 or_elem = pdat.get_obj_cnt();
1247 pdat_new.reserve(or_elem + sz_interf_map[p.id_patch]);
1249 PatchDataField<Tscal> &cur_omega = omega.get(p.id_patch);
1250 PatchDataField<Tscal> &cur_density = density.get(p.id_patch);
1253 pdat_new.get_field<Tscal>(ihpart_interf).insert(pdat.get_field<Tscal>(ihpart));
1254 pdat_new.get_field<Tvec>(ivxyz_interf).insert(pdat.get_field<Tvec>(ivxyz));
1255 pdat_new.get_field<Tscal>(iomega_interf).insert(cur_omega);
1256 pdat_new.get_field<Tscal>(idensity_interf).insert(cur_density);
1259 pdat_new.get_field<Tscal>(iuint_interf).insert(pdat.get_field<Tscal>(iuint));
1264 pdat_new.get_field<Tvec>(igrad_d_interf)
1265 .insert(grad_density_ptr->get(p.
id_patch));
1266 pdat_new.get_field<Tvec>(igrad_p_interf)
1267 .insert(grad_pressure_ptr->get(p.
id_patch));
1268 pdat_new.get_field<Tvec>(igrad_vx_interf).insert(grad_vx_ptr->get(p.
id_patch));
1269 pdat_new.get_field<Tvec>(igrad_vy_interf).insert(grad_vy_ptr->get(p.
id_patch));
1270 pdat_new.get_field<Tvec>(igrad_vz_interf).insert(grad_vz_ptr->get(p.
id_patch));
1273 pdat_new.check_field_obj_cnt_match();
1277 pdat.insert_elements(pdat_interf);
1280 timer_interf.
stop();
1281 storage.timings_details.interface += timer_interf.
elapsed_sec();
1284template<
class Tvec,
template<
class>
class Kern>
1285void shammodels::gsph::Solver<Tvec, Kern>::reset_merge_ghosts_fields() {
1286 storage.merged_patchdata_ghost.reset();
1289template<
class Tvec,
template<
class>
class Kern>
1290void shammodels::gsph::Solver<Tvec, Kern>::compute_eos_fields() {
1294 using namespace shamrock::patch;
1300 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1301 const Tscal gamma = solver_config.get_eos_gamma();
1302 const bool has_uint = solver_config.has_field_uint();
1307 u32 idensity_interf = ghost_layout.
get_field_idx<Tscal>(gsph::names::newtonian::density);
1309 = has_uint ? ghost_layout.
get_field_idx<Tscal>(gsph::names::newtonian::uint) : 0;
1323 storage.merged_patchdata_ghost.get().for_each([&](
u64 id,
PatchDataLayer &mpdat) {
1326 if (total_elements == 0)
1331 auto &pressure_buf = pressure_field.
get_field(
id).get_buf();
1332 auto &soundspeed_buf = soundspeed_field.
get_field(
id).get_buf();
1338 auto pressure = pressure_buf.get_write_access(depends_list);
1339 auto soundspeed = soundspeed_buf.get_write_access(depends_list);
1341 const Tscal *uint_ptr =
nullptr;
1343 uint_ptr = mpdat.get_field_buf_ref<Tscal>(iuint_interf).get_read_access(depends_list);
1346 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
1347 shambase::parallel_for(cgh, total_elements,
"compute_eos_gsph", [=](
u64 gid) {
1352 rho = sycl::max(rho, Tscal(1e-30));
1354 if (has_uint && uint_ptr !=
nullptr) {
1357 Tscal u = uint_ptr[i];
1358 u = sycl::max(u, Tscal(1e-30));
1359 Tscal P = (gamma - Tscal(1.0)) * rho * u;
1363 Tscal cs = sycl::sqrt(gamma * (gamma - Tscal(1.0)) * u);
1366 P = sycl::clamp(P, Tscal(1e-30), Tscal(1e30));
1367 cs = sycl::clamp(cs, Tscal(1e-10), Tscal(1e10));
1373 Tscal cs = Tscal(1.0);
1374 Tscal P = cs * cs * rho;
1385 mpdat.get_field_buf_ref<Tscal>(iuint_interf).complete_event_state(e);
1387 pressure_buf.complete_event_state(e);
1388 soundspeed_buf.complete_event_state(e);
1392template<
class Tvec,
template<
class>
class Kern>
1393void shammodels::gsph::Solver<Tvec, Kern>::reset_eos_fields() {
1397template<
class Tvec,
template<
class>
class Kern>
1402 using namespace shamrock::patch;
1432 auto &q = shamsys::instance::get_compute_scheduler().get_queue();
1435 auto rho_in = buf_rho_in.get_read_access(depends_list);
1439 auto P = buf_P.get_write_access(depends_list);
1440 auto cs = buf_cs.get_write_access(depends_list);
1442 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
1443 cgh.parallel_for(sycl::range<1>{npart}, [=](sycl::item<1> item) {
1444 rho[item] = rho_in[item];
1445 P[item] = P_in[item];
1446 cs[item] = cs_in[item];
1450 buf_rho_in.complete_event_state(e);
1454 buf_P.complete_event_state(e);
1455 buf_cs.complete_event_state(e);
1459template<
class Tvec,
template<
class>
class Kern>
1464 if (!solver_config.requires_gradients()) {
1469 using namespace shamrock::patch;
1471 const Tscal pmass = solver_config.gpart_mass;
1472 const Tscal gamma = solver_config.get_eos_gamma();
1474 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1479 const bool has_uint = solver_config.has_field_uint();
1503 auto &merged_xyzh = storage.merged_xyzh.get();
1504 auto &neigh_cache = storage.neigh_cache->neigh_cache;
1506 static constexpr Tscal Rkern = Kernel::Rkern;
1517 auto &mfield = merged_xyzh.get(p.
id_patch);
1518 auto &pcache = neigh_cache.get(p.
id_patch);
1521 auto &buf_xyz = mfield.template get_field_buf_ref<Tvec>(0);
1522 auto &buf_hpart = mfield.template get_field_buf_ref<Tscal>(1);
1523 auto &buf_vxyz = pdat.get_field_buf_ref<Tvec>(ivxyz);
1538 auto ploop_ptrs = pcache.get_read_access(depends_list);
1541 auto v_acc = buf_vxyz.get_read_access(depends_list);
1542 auto dens_acc = dens_field.get_buf().get_read_access(depends_list);
1543 auto grad_d_acc = grad_d_field.get_buf().get_write_access(depends_list);
1544 auto grad_p_acc = grad_p_field.get_buf().get_write_access(depends_list);
1545 auto grad_vx_acc = grad_vx_buf.get_buf().get_write_access(depends_list);
1546 auto grad_vy_acc = grad_vy_buf.get_buf().get_write_access(depends_list);
1547 auto grad_vz_acc = grad_vz_buf.get_buf().get_write_access(depends_list);
1550 const Tscal *uint_ptr =
nullptr;
1552 uint_ptr = pdat.get_field_buf_ref<Tscal>(iuint).get_read_access(depends_list);
1555 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
1558 shambase::parallel_for(cgh, cnt,
"gsph_compute_gradients", [=](
u64 gid) {
1561 Tvec xyz_a = xyz_acc[id_a];
1562 Tscal h_a = h_acc[id_a];
1563 Tvec v_a = v_acc[id_a];
1564 Tscal rho_a = sycl::max(dens_acc[id_a], Tscal(1e-30));
1565 Tscal dint = h_a * h_a * Rkern * Rkern;
1568 Tscal u_a = Tscal(0);
1569 if (uint_ptr !=
nullptr) {
1570 u_a = uint_ptr[id_a];
1574 Tvec grad_d = {0, 0, 0};
1575 Tvec grad_u = {0, 0, 0};
1576 Tvec grad_vx = {0, 0, 0};
1577 Tvec grad_vy = {0, 0, 0};
1578 Tvec grad_vz = {0, 0, 0};
1580 particle_looper.for_each_object(id_a, [&](
u32 id_b) {
1581 Tvec dr = xyz_a - xyz_acc[id_b];
1582 Tscal rab2 = sycl::dot(dr, dr);
1584 if (rab2 > dint || id_a == id_b) {
1588 Tscal rab = sycl::sqrt(rab2);
1591 Tscal dWdr = Kernel::dW_3d(rab, h_a);
1595 grad_d += gradW * pmass;
1598 Tscal u_b = (uint_ptr !=
nullptr) ? uint_ptr[id_b] : Tscal(0);
1599 grad_u += gradW * (pmass * (u_b - u_a));
1602 Tvec v_b = v_acc[id_b];
1603 grad_vx += gradW * (pmass * (v_b[0] - v_a[0]));
1604 grad_vy += gradW * (pmass * (v_b[1] - v_a[1]));
1605 grad_vz += gradW * (pmass * (v_b[2] - v_a[2]));
1609 grad_d_acc[id_a] = grad_d;
1613 Tvec grad_p = (grad_d * u_a + grad_u) * (gamma - Tscal(1));
1614 grad_p_acc[id_a] = grad_p;
1619 grad_vx_acc[id_a] = grad_vx * rho_inv;
1620 grad_vy_acc[id_a] = grad_vy * rho_inv;
1621 grad_vz_acc[id_a] = grad_vz * rho_inv;
1626 pcache.complete_event_state({e});
1629 buf_vxyz.complete_event_state(e);
1630 dens_field.get_buf().complete_event_state(e);
1631 grad_d_field.get_buf().complete_event_state(e);
1632 grad_p_field.get_buf().complete_event_state(e);
1633 grad_vx_buf.get_buf().complete_event_state(e);
1634 grad_vy_buf.get_buf().complete_event_state(e);
1635 grad_vz_buf.get_buf().complete_event_state(e);
1637 pdat.get_field_buf_ref<Tscal>(iuint).complete_event_state(e);
1642template<
class Tvec,
template<
class>
class Kern>
1643void shammodels::gsph::Solver<Tvec, Kern>::prepare_corrector() {
1655 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1657 scheduler().for_each_patchdata_nonempty(
1663 auto &axyz_field = pdat.get_field<Tvec>(iaxyz);
1664 auto &old_axyz_field = old_axyz.get_field(p.
id_patch);
1668 dev_sched->get_queue(),
1672 [](
u32 i,
const Tvec *src, Tvec *dst) {
1677 storage.old_axyz.set(std::move(old_axyz));
1679 if (solver_config.has_field_uint()) {
1680 const u32 iduint = pdl.
get_field_idx<Tscal>(gsph::names::newtonian::duint);
1681 auto old_duint = utility.make_compute_field<Tscal>(gsph::names::internal::old_duint, 1);
1683 scheduler().for_each_patchdata_nonempty(
1689 auto &duint_field = pdat.get_field<Tscal>(iduint);
1690 auto &old_duint_field = old_duint.get_field(p.
id_patch);
1694 dev_sched->get_queue(),
1698 [](
u32 i,
const Tscal *src, Tscal *dst) {
1703 storage.old_duint.set(std::move(old_duint));
1707template<
class Tvec,
template<
class>
class Kern>
1714template<
class Tvec,
template<
class>
class Kern>
1720 using namespace shamrock::patch;
1722 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1731 Tscal C_cour = solver_config.cfl_config.cfl_cour;
1732 Tscal C_force = solver_config.cfl_config.cfl_force;
1743 auto &buf_hpart = pdat.get_field_buf_ref<Tscal>(ihpart);
1744 auto &buf_axyz = pdat.get_field_buf_ref<Tvec>(iaxyz);
1745 auto &buf_cs = soundspeed_field.get_field(cur_p.
id_patch).get_buf();
1746 auto &cfl_dt_buf = cfl_dt.get_buf_check(cur_p.
id_patch);
1752 auto axyz = buf_axyz.get_read_access(depends_list);
1753 auto cs = buf_cs.get_read_access(depends_list);
1754 auto cfl_dt_acc = cfl_dt_buf.get_write_access(depends_list);
1756 auto e = q.
submit(depends_list, [&](sycl::handler &cgh) {
1757 shambase::parallel_for(cgh, cnt,
"gsph_compute_cfl_dt", [=](
u64 gid) {
1760 Tscal h_i = hpart[i];
1762 Tscal abs_a = sycl::length(axyz[i]);
1765 if (!sycl::isfinite(h_i) || h_i <= Tscal(0))
1767 if (!sycl::isfinite(cs_i) || cs_i <= Tscal(0))
1768 cs_i = Tscal(1e-10);
1769 if (!sycl::isfinite(abs_a))
1770 abs_a = Tscal(1e30);
1774 Tscal dt_c = C_cour * h_i / cs_i;
1777 Tscal dt_f = C_force * sycl::sqrt(h_i / (abs_a + Tscal(1e-30)));
1779 Tscal dt_min = sycl::min(dt_c, dt_f);
1782 if (!sycl::isfinite(dt_min) || dt_min <= Tscal(0)) {
1783 dt_min = Tscal(1e-10);
1786 cfl_dt_acc[i] = dt_min;
1791 buf_axyz.complete_event_state(e);
1792 buf_cs.complete_event_state(e);
1793 cfl_dt_buf.complete_event_state(e);
1797 Tscal rank_dt = cfl_dt.compute_rank_min();
1800 if (!std::isfinite(rank_dt) || rank_dt <= Tscal(0)) {
1801 rank_dt = Tscal(1e-6);
1805 Tscal global_min_dt = shamalgs::collective::allreduce_min(rank_dt);
1810 const Tscal dt_min_floor = Tscal(1e-6);
1811 if (!std::isfinite(global_min_dt) || global_min_dt < dt_min_floor) {
1812 global_min_dt = dt_min_floor;
1815 return global_min_dt;
1818template<
class Tvec,
template<
class>
class Kern>
1819bool shammodels::gsph::Solver<Tvec, Kern>::apply_corrector(Tscal dt,
u64 Npart_all) {
1827 Tscal half_dt = Tscal{0.5} * dt;
1831 scheduler().for_each_patchdata_nonempty(
1837 auto &vxyz = pdat.get_field<Tvec>(ivxyz);
1838 auto &axyz = pdat.get_field<Tvec>(iaxyz);
1840 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1843 dev_sched->get_queue(),
1847 [half_dt](
u32 i,
const Tvec *axyz_new, Tvec *vxyz) {
1848 vxyz[i] += half_dt * axyz_new[i];
1852 if (solver_config.has_field_uint()) {
1854 const u32 iduint = pdl.
get_field_idx<Tscal>(gsph::names::newtonian::duint);
1856 scheduler().for_each_patchdata_nonempty(
1862 auto &uint_field = pdat.get_field<Tscal>(iuint);
1863 auto &
duint = pdat.get_field<Tscal>(iduint);
1865 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
1869 dev_sched->get_queue(),
1873 [half_dt](
u32 i,
const Tscal *duint_new, Tscal *uint) {
1874 uint[i] += half_dt * duint_new[i];
1878 storage.old_duint.reset();
1881 storage.old_axyz.reset();
1886template<
class Tvec,
template<
class>
class Kern>
1887void shammodels::gsph::Solver<Tvec, Kern>::update_sync_load_values() {
1888 modules::ComputeLoadBalanceValue<Tvec, Kern>(context, solver_config, storage)
1889 .update_load_balancing();
1890 scheduler().scheduler_step(
false,
false);
1893template<
class Tvec,
template<
class>
class Kern>
1897 solver_config.check_config_runtime();
1899 Tscal t_current = get_time();
1900 Tscal dt = get_dt();
1906 sham::format(
"---------------- GSPH t = {}, dt = {} ----------------", t_current, dt));
1914 .update_load_balancing();
1915 scheduler().scheduler_step(
true,
true);
1917 .update_load_balancing();
1918 scheduler().scheduler_step(
false,
false);
1923 using namespace shamrock::patch;
1925 u64 Npart_all = scheduler().get_total_obj_count();
1948 do_predictor_leapfrog(dt);
1952 gen_serial_patch_tree();
1953 apply_position_boundary(t_current + dt);
1960 gsph_prestep(t_current, dt);
1969 init_ghost_layout();
1973 communicate_merge_ghosts_fields();
1978 compute_eos_fields();
1982 prepare_corrector();
1988 apply_corrector(dt, Npart_all);
1994 if (dt > Tscal(0)) {
1995 dt_next = sham::min(dt_next, Tscal(2) * dt);
2002 reset_neighbors_cache();
2003 reset_presteps_rint();
2004 clear_merged_pos_trees();
2005 reset_merge_ghosts_fields();
2006 storage.merged_xyzh.reset();
2007 clear_ghost_cache();
2008 reset_serial_patch_tree();
2009 reset_ghost_handler();
2010 storage.ghost_layout.reset();
2013 set_time(t_current + dt);
2014 set_next_dt(dt_next);
2016 solve_logs.step_count++;
2023 log.rate = Tscal(Npart_all) / tstep.
elapsed_sec();
2024 log.npart = Npart_all;
Constants for field names in GSPH solver, organized by physics mode.
constexpr const char * duint
Time derivative of internal energy du/dt.
constexpr const char * axyz
3-acceleration field
constexpr const char * uint
Specific internal energy u.
constexpr const char * vxyz
3-velocity field
constexpr const char * pos_merged
Position merged references (for h-iteration).
constexpr const char * old_axyz
Old acceleration (for corrector step).
constexpr const char * xyz
Position field (3D coordinates).
constexpr const char * density
Density \rho (derived from h).
constexpr const char * eps_h
Epsilon h references (for h-iteration convergence).
constexpr const char * soundspeed
Sound speed c_s (derived from EOS).
constexpr const char * pressure
Pressure P (derived from EOS).
constexpr const char * hpart
Smoothing length field.
constexpr const char * neigh_cache
Neighbor cache.
constexpr const char * omega
Grad-h correction factor \Omega.
Solvergraph nodes finding the SPH ghost interfaces, one node per boundary condition.
shambase::DistributedData< PatchDataFieldRef< T > > DDPatchDataFieldRef
Alias for a DistributedData of PatchDataFieldRefs.
Declares the IterateSmoothingLengthDensityNeighLim module for iterating smoothing length based on the...
Declares the IterateSmoothingLengthDensity module for iterating smoothing length based on the SPH den...
Declares the LoopSmoothingLengthIter module for looping over the smoothing length iteration until con...
Header file describing a Node Instance.
sycl::queue & get_compute_queue(u32 id=0)
Header file for the patch struct and related function.
Solvergraph edge holding a field defined on the nodes of the serial patch tree.
Solver graph node overwriting a field with a constant value where a mask is set.
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.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
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::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
Container for objects shared between two distributed data elements.
void for_each(std::function< void(u64, u64, T &)> &&f)
Apply a function to all stored objects.
Represents a collection of objects distributed across patches identified by a u64 id.
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.
typename sph::BasicSPHGhostHandler< Tvec >::InterfaceBuildInfos InterfaceBuildInfos
void compute_density()
Compute SPH-summation density for GSPH.
void copy_eos_to_patchdata()
Copy EOS fields from solvergraph to patchdata for persistence.
void compute_gradients()
Compute gradients for MUSCL reconstruction.
TimestepLog evolve_once()
void update_derivs()
Update derivatives using GSPH Riemann solver.
Tscal compute_dt_cfl()
Compute CFL timestep constraint.
void build_ghost_cache(Tscal time_val)
GSPH derivative update module.
void update_derivs()
Update all derivatives using GSPH Riemann solver approach.
Ghost interface finder for free boundaries: only direct neighbouring patches.
Ghost interface finder for periodic boundaries: neighbouring patches, including through the 26 period...
Ghost interface finder for shearing periodic boundaries.
Utility class used to move the objects between patches.
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
Store the information related to the size of the simulation box to convert patch integer coordinates ...
std::tuple< T, T > get_bounding_box() const
Get the stored bounding box of the domain.
PatchCoordTransform< T > get_patch_transform() const
Get a PatchCoordTransform object that describes the conversion between patch coordinates and domain c...
virtual void ensure_sizes(const shambase::DistributedData< u32 > &sizes)
Ensure that the sizes of the patches in the field match the given sizes (Can resize the underlying fi...
PatchDataField< T > & get_field(u64 id) const
Get the underlying PatchDataField at the given id.
void evaluate()
Evaluate the node.
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
A data structure representing a Karras Radix Tree Field.
constexpr Unit h
Planck constant.
Class holding the value of numerous constants generated from the following source.
This header file contains utility functions related to exception handling in the code.
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
Configuration for the Godunov SPH (GSPH) solver.
GSPH derivative update module.
VTK dump module for GSPH solver.
T inv_sat_positive(T v, T minvsat=T{1e-9}, T satval=T{0.}) noexcept
inverse saturated (positive numbers only)
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
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
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.
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
void err_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.
A class that references multiple buffers or similar objects.
Build an overload set out of several callables, for use with std::visit.
Axis-Aligned bounding box.
T lower
Lower bound of the AABB.
T upper
Upper bound of the AABB.
Patch object that contain generic patch information.
u64 id_patch
unique key that identify the patch
Functions related to the MPI communicator.