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();
76 auto [m, M] = sched.get_box_tranform<Tvec>();
84 reatrib.reatribute_patch_objects(sptree,
"xyz");
85 sched.check_patchdata_locality_correctness();
97 reatrib.reatribute_patch_objects(sptree,
"xyz");
98 sched.check_patchdata_locality_correctness();
101 std::string log =
"";
103 using namespace shamrock::patch;
106 u32 largest_count = 0;
110 smallest_count = sham::min(tmp, smallest_count);
111 largest_count = sham::max(tmp, largest_count);
114 smallest_count = shamalgs::collective::allreduce_min(smallest_count);
115 largest_count = shamalgs::collective::allreduce_max(largest_count);
119 "Model",
"current particle counts : min = ", smallest_count,
"max = ", largest_count);
123template<
class Tvec,
template<
class>
class SPHKernel>
124u64 shammodels::gsph::Model<Tvec, SPHKernel>::get_total_part_count() {
126 return shamalgs::collective::allreduce_sum(sched.get_rank_count());
129template<
class Tvec,
template<
class>
class SPHKernel>
130f64 shammodels::gsph::Model<Tvec, SPHKernel>::total_mass_to_part_mass(
f64 totmass) {
131 return totmass / get_total_part_count();
134template<
class Tvec,
template<
class>
class SPHKernel>
135auto shammodels::gsph::Model<Tvec, SPHKernel>::get_ideal_fcc_box(
136 Tscal dr, std::pair<Tvec, Tvec> box) -> std::pair<Tvec, Tvec> {
138 auto [a, b] = generic::setup::generators::get_ideal_fcc_box<Tscal>(
139 dr, std::make_tuple(box.first, box.second));
143template<
class Tvec,
template<
class>
class SPHKernel>
144auto shammodels::gsph::Model<Tvec, SPHKernel>::get_ideal_hcp_box(
145 Tscal dr, std::pair<Tvec, Tvec> box) -> std::pair<Tvec, Tvec> {
147 auto [a, b] = generic::setup::generators::get_ideal_fcc_box<Tscal>(
148 dr, std::make_tuple(box.first, box.second));
152template<
class Tvec,
template<
class>
class SPHKernel>
153void shammodels::gsph::Model<Tvec, SPHKernel>::add_cube_fcc_3d(
154 Tscal dr, std::pair<Tvec, Tvec> _box) {
159 using namespace shamrock::patch;
163 std::string log =
"";
165 auto make_sliced = [&]() {
166 std::vector<Tvec> vec_lst;
167 generic::setup::generators::add_particles_fcc(
169 std::make_tuple(box.lower, box.upper),
171 return box.contain_pos(r);
173 [&](Tvec r, Tscal h) {
174 vec_lst.push_back(r);
177 std::vector<std::vector<Tvec>> sliced_buf;
181 std::vector<Tvec> cur_buf;
182 for (
u32 i = 0; i < vec_lst.size(); i++) {
183 cur_buf.push_back(vec_lst[i]);
185 if (cur_buf.size() > sz_buf) {
186 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
190 if (cur_buf.size() > 0) {
191 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
197 std::vector<std::vector<Tvec>> sliced_buf = make_sliced();
199 for (std::vector<Tvec> to_ins : sliced_buf) {
203 = sched.get_sim_box().template get_patch_transform<Tvec>();
207 std::vector<Tvec> vec_acc;
208 for (Tvec r : to_ins) {
209 if (patch_coord.contain_pos(r)) {
210 vec_acc.push_back(r);
214 if (vec_acc.size() == 0) {
219 "\n rank = {} patch id={}, add N={} particles, coords = {} {}",
227 tmp.resize(vec_acc.size());
231 u32 len = vec_acc.size();
233 sched.pdl_old().template get_field_idx<Tvec>(
"xyz"));
234 f.override(vec_acc, len);
239 sched.pdl_old().template get_field_idx<Tscal>(
"hpart"));
240 using Kernel = SPHKernel<Tscal>;
241 f.override(Kernel::hfactd * dr);
244 pdat.insert_elements(tmp);
247 sched.check_patchdata_locality_correctness();
248 modules::ComputeLoadBalanceValue<Tvec, SPHKernel>(ctx, solver.solver_config, solver.storage)
249 .update_load_balancing();
250 post_insert_data<Tvec>(sched);
253 shamlog_debug_ln(
"setup", log);
256template<
class Tvec,
template<
class>
class SPHKernel>
257void shammodels::gsph::Model<Tvec, SPHKernel>::add_cube_hcp_3d(
258 Tscal dr, std::pair<Tvec, Tvec> _box) {
263 using namespace shamrock::patch;
267 std::string log =
"";
269 auto make_sliced = [&]() {
270 std::vector<Tvec> vec_lst;
271 generic::setup::generators::add_particles_fcc(
273 std::make_tuple(box.lower, box.upper),
275 return box.contain_pos(r);
277 [&](Tvec r, Tscal h) {
278 vec_lst.push_back(r);
281 std::vector<std::vector<Tvec>> sliced_buf;
285 std::vector<Tvec> cur_buf;
286 for (
u32 i = 0; i < vec_lst.size(); i++) {
287 cur_buf.push_back(vec_lst[i]);
289 if (cur_buf.size() > sz_buf) {
290 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
294 if (cur_buf.size() > 0) {
295 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
301 std::vector<std::vector<Tvec>> sliced_buf = make_sliced();
303 for (std::vector<Tvec> to_ins : sliced_buf) {
307 = sched.get_sim_box().template get_patch_transform<Tvec>();
311 std::vector<Tvec> vec_acc;
312 for (Tvec r : to_ins) {
313 if (patch_coord.contain_pos(r)) {
314 vec_acc.push_back(r);
318 if (vec_acc.size() == 0) {
323 "\n rank = {} patch id={}, add N={} particles, coords = {} {}",
331 tmp.resize(vec_acc.size());
335 u32 len = vec_acc.size();
337 sched.pdl_old().template get_field_idx<Tvec>(
"xyz"));
338 f.override(vec_acc, len);
343 sched.pdl_old().template get_field_idx<Tscal>(
"hpart"));
344 using Kernel = SPHKernel<Tscal>;
345 f.override(Kernel::hfactd * dr);
348 pdat.insert_elements(tmp);
351 sched.check_patchdata_locality_correctness();
352 modules::ComputeLoadBalanceValue<Tvec, SPHKernel>(ctx, solver.solver_config, solver.storage)
353 .update_load_balancing();
354 post_insert_data<Tvec>(sched);
357 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.
u64 id_patch
unique key that identify the patch