Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Model.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
17#include "shambase/memory.hpp"
23
24template<class Tvec, class TgridVec>
26
27 if (solver.solver_config.scheduler_conf.split_load_value == 0) {
29 "Scheduler load value should be greater than 0");
30 }
31
32 solver.init_required_fields();
33 // solver.init_ghost_layout();
34 ctx.init_sched(
35 solver.solver_config.scheduler_conf.split_load_value,
36 solver.solver_config.scheduler_conf.merge_load_value);
37
38 using namespace shamrock::patch;
39
40 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
41
42 // sched.add_root_patch();
43
44 // std::cout << "build local" << std::endl;
45 // sched.owned_patch_id = sched.patch_list.build_local();
46 // sched.patch_list.build_local_idx_map();
47 // sched.update_local_dtcnt_value();
48 // sched.update_local_load_value();
49}
50
51template<class Tvec, class TgridVec>
53 TgridVec bmin, TgridVec cell_size, u32_3 cell_count) {
55 grid.make_base_grid(bmin, cell_size, {cell_count.x(), cell_count.y(), cell_count.z()});
56
57 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
58
61 sched.update_local_load_value([&](shamrock::patch::Patch p) {
62 return sched.patch_data.owned_data.get(p.id_patch).get_obj_cnt();
63 });
64 sched.scheduler_step(true, true);
65}
66
67template<class Tvec, class TgridVec>
69
70 StackEntry stack_loc{};
71 shamrock::LegacyVtkWriter writer(filename, true, shamrock::UnstructuredGrid);
72
73 PatchScheduler &sched = shambase::get_check_ref(ctx.sched);
74
75 u32 block_size = Solver::AMRBlock::block_size;
76
77 u64 num_obj = sched.get_rank_count();
78
79 std::unique_ptr<sycl::buffer<TgridVec>> pos1 = sched.rankgather_field<TgridVec>(0);
80 std::unique_ptr<sycl::buffer<TgridVec>> pos2 = sched.rankgather_field<TgridVec>(1);
81
82 sycl::buffer<Tvec> pos_min_cell(num_obj * block_size);
83 sycl::buffer<Tvec> pos_max_cell(num_obj * block_size);
84
85 shamsys::instance::get_compute_queue().submit([&, block_size](sycl::handler &cgh) {
86 sycl::accessor acc_p1{shambase::get_check_ref(pos1), cgh, sycl::read_only};
87 sycl::accessor acc_p2{shambase::get_check_ref(pos2), cgh, sycl::read_only};
88 sycl::accessor cell_min{pos_min_cell, cgh, sycl::write_only, sycl::no_init};
89 sycl::accessor cell_max{pos_max_cell, cgh, sycl::write_only, sycl::no_init};
90
91 using Block = typename Solver::AMRBlock;
92
93 shambase::parallel_for(cgh, num_obj, "rescale cells", [=](u64 id_a) {
94 Tvec block_min = acc_p1[id_a].template convert<Tscal>();
95 Tvec block_max = acc_p2[id_a].template convert<Tscal>();
96
97 Tvec delta_cell = (block_max - block_min) / Block::side_size;
98#pragma unroll
99 for (u32 ix = 0; ix < Block::side_size; ix++) {
100#pragma unroll
101 for (u32 iy = 0; iy < Block::side_size; iy++) {
102#pragma unroll
103 for (u32 iz = 0; iz < Block::side_size; iz++) {
104 u32 i = Block::get_index({ix, iy, iz});
105 Tvec delta_val = delta_cell * Tvec{ix, iy, iz};
106 cell_min[id_a * block_size + i] = block_min + delta_val;
107 cell_max[id_a * block_size + i] = block_min + (delta_cell) + delta_val;
108 }
109 }
110 }
111 });
112 });
113
114 writer.write_voxel_cells(pos_min_cell, pos_max_cell, num_obj * block_size);
115
116 writer.add_cell_data_section();
117 writer.add_field_data_section(3);
118
119 std::unique_ptr<sycl::buffer<Tscal>> fields_rho = sched.rankgather_field<Tscal>(2);
120 writer.write_field("rho", fields_rho, num_obj * block_size);
121
122 std::unique_ptr<sycl::buffer<Tscal>> fields_eint = sched.rankgather_field<Tscal>(3);
123 writer.write_field("eint", fields_eint, num_obj * block_size);
124
125 std::unique_ptr<sycl::buffer<Tvec>> fields_vel = sched.rankgather_field<Tvec>(4);
126 writer.write_field("vel", fields_vel, num_obj * block_size);
127}
128
129template<class Tvec, class TgridVec>
130auto shammodels::zeus::Model<Tvec, TgridVec>::evolve_once(Tscal t_current, Tscal dt_input)
131 -> Tscal {
132 return solver.evolve_once(t_current, dt_input);
133}
134
Header file describing a Node Instance.
sycl::queue & get_compute_queue(u32 id=0)
MPI scheduler.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
The MPI scheduler.
SchedulerPatchData patch_data
handle the data of the patches of the scheduler
void scheduler_step(bool do_split_merge, bool do_load_balancing)
scheduler step
SchedulerPatchList patch_list
handle the list of the patches of the scheduler
std::unordered_set< u64 > owned_patch_id
(owned_patch_id = patch_list.build_local())
std::unordered_set< u64 > build_local()
select owned patches owned by the node to rebuild local
void build_local_idx_map()
recompute id_patch_to_local_idx
Zeus scheme implementation in Shamrock (WIP)
Definition Model.hpp:38
void init()
Initialise the model and all the related data structures (patch scheduler in particular)
Definition Model.cpp:25
The AMR grid only sees the grid as an integer map.
Definition AMRGrid.hpp:44
shambase::DistributedData< PatchData > owned_data
map container for patchdata owned by the current node (layout : id_patch,data)
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...
Definition memory.hpp:110
Patch object that contain generic patch information.
Definition Patch.hpp:33