40template<
class Tvec,
template<
class>
class SPHKernel>
43 if (solver.solver_config.scheduler_conf.split_load_value == 0) {
45 "Scheduler load value should be greater than 0");
48 solver.init_required_fields();
50 solver.solver_config.scheduler_conf.split_load_value,
51 solver.solver_config.scheduler_conf.merge_load_value);
53 using namespace shamrock::patch;
59 shamlog_debug_ln(
"Sys",
"build local scheduler tables");
65 solver.init_ghost_layout();
67 solver.init_solver_graph();
69 solver.ensure_time_state_edges();
78 auto [m, M] = sched.get_box_tranform<Tvec>();
86 reatrib.reatribute_patch_objects(sptree,
"xyz");
87 sched.check_patchdata_locality_correctness();
99 reatrib.reatribute_patch_objects(sptree,
"xyz");
100 sched.check_patchdata_locality_correctness();
103 std::string log =
"";
105 using namespace shamrock::patch;
108 u32 largest_count = 0;
112 smallest_count = sham::min(tmp, smallest_count);
113 largest_count = sham::max(tmp, largest_count);
116 smallest_count = shamalgs::collective::allreduce_min(smallest_count);
117 largest_count = shamalgs::collective::allreduce_max(largest_count);
121 "Model",
"current particle counts : min = ", smallest_count,
"max = ", largest_count);
125template<
class Tvec,
template<
class>
class SPHKernel>
126u64 shammodels::gsph::Model<Tvec, SPHKernel>::get_total_part_count() {
128 return shamalgs::collective::allreduce_sum(sched.get_rank_count());
131template<
class Tvec,
template<
class>
class SPHKernel>
132f64 shammodels::gsph::Model<Tvec, SPHKernel>::total_mass_to_part_mass(
f64 totmass) {
133 return totmass / get_total_part_count();
136template<
class Tvec,
template<
class>
class SPHKernel>
137auto shammodels::gsph::Model<Tvec, SPHKernel>::get_ideal_fcc_box(
138 Tscal dr, std::pair<Tvec, Tvec> box) -> std::pair<Tvec, Tvec> {
140 auto [a, b] = generic::setup::generators::get_ideal_fcc_box<Tscal>(
141 dr, std::make_tuple(box.first, box.second));
145template<
class Tvec,
template<
class>
class SPHKernel>
146auto shammodels::gsph::Model<Tvec, SPHKernel>::get_ideal_hcp_box(
147 Tscal dr, std::pair<Tvec, Tvec> box) -> std::pair<Tvec, Tvec> {
149 auto [a, b] = generic::setup::generators::get_ideal_fcc_box<Tscal>(
150 dr, std::make_tuple(box.first, box.second));
154template<
class Tvec,
template<
class>
class SPHKernel>
155void shammodels::gsph::Model<Tvec, SPHKernel>::add_cube_fcc_3d(
156 Tscal dr, std::pair<Tvec, Tvec> _box) {
161 using namespace shamrock::patch;
165 std::string log =
"";
167 auto make_sliced = [&]() {
168 std::vector<Tvec> vec_lst;
169 generic::setup::generators::add_particles_fcc(
171 std::make_tuple(box.lower, box.upper),
173 return box.contain_pos(r);
175 [&](Tvec r, Tscal h) {
176 vec_lst.push_back(r);
179 std::vector<std::vector<Tvec>> sliced_buf;
183 std::vector<Tvec> cur_buf;
184 for (
u32 i = 0; i < vec_lst.size(); i++) {
185 cur_buf.push_back(vec_lst[i]);
187 if (cur_buf.size() > sz_buf) {
188 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
192 if (cur_buf.size() > 0) {
193 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
199 std::vector<std::vector<Tvec>> sliced_buf = make_sliced();
201 for (std::vector<Tvec> to_ins : sliced_buf) {
205 = sched.get_sim_box().template get_patch_transform<Tvec>();
209 std::vector<Tvec> vec_acc;
210 for (Tvec r : to_ins) {
211 if (patch_coord.contain_pos(r)) {
212 vec_acc.push_back(r);
216 if (vec_acc.size() == 0) {
221 "\n rank = {} patch id={}, add N={} particles, coords = {} {}",
229 tmp.resize(vec_acc.size());
233 u32 len = vec_acc.size();
235 sched.pdl_old().template get_field_idx<Tvec>(
"xyz"));
236 sycl::buffer<Tvec> buf(vec_acc.data(), len);
237 f.override(buf, len);
242 sched.pdl_old().template get_field_idx<Tscal>(
"hpart"));
243 using Kernel = SPHKernel<Tscal>;
244 f.override(Kernel::hfactd * dr);
247 pdat.insert_elements(tmp);
250 sched.check_patchdata_locality_correctness();
251 modules::ComputeLoadBalanceValue<Tvec, SPHKernel>(ctx, solver.solver_config, solver.storage)
252 .update_load_balancing();
253 post_insert_data<Tvec>(sched);
256 shamlog_debug_ln(
"setup", log);
259template<
class Tvec,
template<
class>
class SPHKernel>
260void shammodels::gsph::Model<Tvec, SPHKernel>::add_cube_hcp_3d(
261 Tscal dr, std::pair<Tvec, Tvec> _box) {
266 using namespace shamrock::patch;
270 std::string log =
"";
272 auto make_sliced = [&]() {
273 std::vector<Tvec> vec_lst;
274 generic::setup::generators::add_particles_fcc(
276 std::make_tuple(box.lower, box.upper),
278 return box.contain_pos(r);
280 [&](Tvec r, Tscal h) {
281 vec_lst.push_back(r);
284 std::vector<std::vector<Tvec>> sliced_buf;
288 std::vector<Tvec> cur_buf;
289 for (
u32 i = 0; i < vec_lst.size(); i++) {
290 cur_buf.push_back(vec_lst[i]);
292 if (cur_buf.size() > sz_buf) {
293 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
297 if (cur_buf.size() > 0) {
298 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
304 std::vector<std::vector<Tvec>> sliced_buf = make_sliced();
306 for (std::vector<Tvec> to_ins : sliced_buf) {
310 = sched.get_sim_box().template get_patch_transform<Tvec>();
314 std::vector<Tvec> vec_acc;
315 for (Tvec r : to_ins) {
316 if (patch_coord.contain_pos(r)) {
317 vec_acc.push_back(r);
321 if (vec_acc.size() == 0) {
326 "\n rank = {} patch id={}, add N={} particles, coords = {} {}",
334 tmp.resize(vec_acc.size());
338 u32 len = vec_acc.size();
340 sched.pdl_old().template get_field_idx<Tvec>(
"xyz"));
341 sycl::buffer<Tvec> buf(vec_acc.data(), len);
342 f.override(buf, len);
347 sched.pdl_old().template get_field_idx<Tscal>(
"hpart"));
348 using Kernel = SPHKernel<Tscal>;
349 f.override(Kernel::hfactd * dr);
352 pdat.insert_elements(tmp);
355 sched.check_patchdata_locality_correctness();
356 modules::ComputeLoadBalanceValue<Tvec, SPHKernel>(ctx, solver.solver_config, solver.storage)
357 .update_load_balancing();
358 post_insert_data<Tvec>(sched);
361 shamlog_debug_ln(
"setup", log);
Header file describing a Node Instance.
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
SchedulerPatchData patch_data
handle the data of the patches of the scheduler
u64 crit_patch_split
splitting limit (if load value > crit_patch_split => patch split)
PatchTree patch_tree
handle the tree structure of the patches
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())
void add_root_patch()
add patch to the scheduler
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
void init()
Initialise the model and all the related data structures (patch scheduler in particular).
Utility class used to move the objects between patches.
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
PatchCoordTransform< T > get_patch_transform() const
Get a PatchCoordTransform object that describes the conversion between patch coordinates and domain c...
shambase::DistributedData< PatchData > owned_data
map container for patchdata owned by the current node (layout : id_patch,data)
This header file contains utility functions related to exception handling in the code.
GSPH Model class - high-level interface for GSPH simulations.
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...
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
constexpr u32 u32_max
u32 max value
void info_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
Patch object that contain generic patch information.