33 template<
class Tvec,
class Tgr
idVec>
36 using Tscal = shambase::VecComponent<Tvec>;
37 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
40 using Solver = Solver<Tvec, TgridVec>;
55 solver.solver_config.scheduler_conf.split_load_value = crit_split;
56 solver.solver_config.scheduler_conf.merge_load_value = crit_merge;
60 void make_base_grid(TgridVec bmin, TgridVec cell_size, u32_3 cell_count);
62 void dump_vtk(std::string filename);
65 inline void set_field_value_lambda(
66 std::string field_name,
67 const std::function<T(Tvec, Tvec)> pos_to_val,
72 using Block =
typename Solver::Config::AMRBlock;
81 = pdat.template get_field<T>(sched.pdl_old().
get_field_idx<T>(field_name));
83 auto acc = f.get_buf().copy_to_stdvec();
85 auto f_nvar = f.get_nvar() / Block::block_size;
88 auto cell_max = buf_cell_max.copy_to_stdvec();
90 Tscal scale_factor = solver.solver_config.grid_coord_to_pos_fact;
91 for (
u32 i = 0; i < pdat.get_obj_cnt(); i++) {
92 Tvec block_min = cell_min[i].template convert<Tscal>() * scale_factor;
93 Tvec block_max = cell_max[i].template convert<Tscal>() * scale_factor;
94 Tvec delta_cell = (block_max - block_min) / Block::side_size;
96 Block::for_each_cell_in_block(delta_cell, [&](
u32 lid, Tvec delta) {
97 Tvec bmin = block_min + delta;
98 acc[(i * Block::block_size + lid) * f_nvar + offset]
99 = pos_to_val(bmin, bmin + delta_cell);
103 f.get_buf().copy_from_stdvec(acc);
107 inline std::pair<Tvec, Tvec> get_cell_coords(
108 std::pair<TgridVec, TgridVec> block_coords,
u32 lid) {
109 using Block =
typename Solver::Config::AMRBlock;
110 auto tmp = Block::utils_get_cell_coords(block_coords, lid);
111 tmp.first *= solver.solver_config.grid_coord_to_pos_fact;
112 tmp.second *= solver.solver_config.grid_coord_to_pos_fact;
116 inline f64 evolve_once_time_expl(
f64 t_curr,
f64 dt_input) {
117 return solver.evolve_once_time_expl(t_curr, dt_input);
120 inline void timestep() { solver.evolve_once(); }
122 inline void evolve_once() {
123 solver.evolve_once();
124 solver.print_timestep_logs();
127 inline bool evolve_until(Tscal target_time,
i32 niter_max) {
128 return solver.evolve_until(target_time, niter_max);
135 inline void dump(std::string fname) {
137 logger::info_ln(
"Godunov",
"Dumping state to", fname);
140 nlohmann::json metadata;
141 metadata[
"solver_config"] = solver.solver_config;
158 std::string metadata_user{};
161 nlohmann::json j = nlohmann::json::parse(metadata_user);
162 j.at(
"solver_config").get_to(solver.solver_config);
174 = std::find(sync_names.begin(), sync_names.end(),
"time") != sync_names.end();
177 solver.ensure_time_state_edges();
179 if (!had_time_edge) {
180 if (j.at(
"solver_config").contains(
"time_state")) {
184 "Migrated time/dt from solver_config.time_state into scheduler "
186 const auto &ts = j.at(
"solver_config").at(
"time_state");
187 solver.set_time(ts.at(
"time").get<Tscal>());
188 solver.set_next_dt(ts.at(
"dt").get<Tscal>());
191 "this should never happen: dump has neither time edges nor "
192 "solver_config.time_state");
196 shamlog_debug_ln(
"Sys",
"build local scheduler tables");
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::int32_t i32
32 bit integer
SchedulerPatchData patch_data
handle the data of the patches of the scheduler
SynchronizedData synchronized_data
data that is synchroneous across all ranks
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
void build_global_idx_map()
recompute id_patch_to_global_idx
A buffer allocated in USM (Unified Shared Memory).
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
void init_scheduler(u32 crit_split, u32 crit_merge)
void init()
Initialise the model and all the related data structures (patch scheduler in particular).
void load_from_dump(std::string fname)
Load the state of the Godunov model from a dump file.
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.
shambase::DistributedData< PatchData > owned_data
map container for patchdata owned by the current node (layout : id_patch,data)
std::vector< std::string > get_edge_names() const
Returns edge registration keys in lexicographic order (deterministic).
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.
namespace for the basegodunov model
void load_shamrock_dump(std::string fname, std::string &metadata_user, ShamrockCtx &ctx)
Load a Shamrock dump file and restore the state of the patches and retreive user metadata.
void write_shamrock_dump(std::string fname, std::string metadata_user, PatchScheduler &sched)
Write a Shamrock dump file containing the current state of the patches and user supplied metadata.
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.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
Patch object that contain generic patch information.
#define ON_RANK_0(x)
Macro to execute code only on rank 0.