30 template<
class Tvec,
class Tgr
idVec>
31 inline void SolverConfig<Tvec, TgridVec>::set_layout(
32 shamrock::patch::PatchDataLayerLayout &pdl) {
35 pdl.
add_field<Tscal>(
"rho", AMRBlock::block_size);
36 pdl.
add_field<Tvec>(
"rhovel", AMRBlock::block_size);
37 pdl.
add_field<Tscal>(
"rhoetot", AMRBlock::block_size);
40 u32 ndust = dust_config.ndust;
41 pdl.
add_field<Tscal>(
"rho_dust", (ndust * AMRBlock::block_size));
42 pdl.
add_field<Tvec>(
"rhovel_dust", (ndust * AMRBlock::block_size));
45 if (is_gravity_on()) {
46 pdl.
add_field<Tscal>(
"phi", AMRBlock::block_size);
47 pdl.
add_field<Tscal>(
"phi_old", AMRBlock::block_size);
50 if (is_gas_passive_scalar_on()) {
51 u32 npscal_gas = npscal_gas_config.npscal_gas;
52 pdl.
add_field<Tscal>(
"rho_gas_pscal", (npscal_gas * AMRBlock::block_size));
56 template<
class Tvec,
class Tgr
idVec>
60 {
"type_id", shambase::get_type_name<Tvec>()},
61 {
"scheduler_config", p.scheduler_conf},
62 {
"courant_safety_factor", p.Csafe},
63 {
"dust_riemann_solver", p.dust_config.dust_riemann_config},
64 {
"ndust", p.dust_config.ndust},
67 {
"face_half_time_interpolation", p.face_half_time_interpolation},
68 {
"gravity_solver", p.gravity_config.gravity_mode},
69 {
"gravity_tol", p.gravity_config.tol},
70 {
"gravity_tol_happy_breakdown", p.gravity_config.tol_hp_bk},
71 {
"gravity_Niter_max", p.gravity_config.Niter_max},
72 {
"grid_coord_to_pos_fact", p.grid_coord_to_pos_fact},
73 {
"hydro_riemann_solver", p.riemann_config},
74 {
"passive_scalar_mode", p.npscal_gas_config.npscal_gas},
75 {
"slope_limiter", p.slope_config},
77 {
"drag_config", p.drag_config},
78 {
"bc_config", p.bc_config},
80 {
"amr_interp_mode", p.amr_interp_mode},
84 template<
class Tvec,
class Tgr
idVec>
88 if (j.contains(
"type_id")) {
90 std::string type_id = j.at(
"type_id").get<std::string>();
92 if (type_id != shambase::get_type_name<Tvec>()) {
94 "Invalid type to deserialize, wanted " + shambase::get_type_name<Tvec>()
95 +
" but got " + type_id);
99 bool has_used_defaults =
false;
100 bool has_updated_config =
false;
102 auto _get_to_if_contains = [&](
const std::string &key,
auto &value) {
106 _get_to_if_contains(
"scheduler_config", p.scheduler_conf);
109 _get_to_if_contains(
"courant_safety_factor", p.Csafe);
110 _get_to_if_contains(
"dust_riemann_solver", p.dust_config.dust_riemann_config);
111 _get_to_if_contains(
"ndust", p.dust_config.ndust);
115 bool is_legacy_reset_barotropic = j.contains(
"eos_config")
116 && j.at(
"eos_config").contains(
"type")
117 && j.at(
"eos_config").at(
"type") ==
"reset_barotropic";
119 if (is_legacy_reset_barotropic) {
120 using Tscal =
typename T::Tscal;
121 const nlohmann::json &j_eos = j.at(
"eos_config");
122 p.
eos_config.set_adiabatic(j_eos.at(
"gamma").get<Tscal>());
124 j_eos.at(
"rho_crit").get<Tscal>(),
125 j_eos.at(
"cs0").get<Tscal>(),
126 j_eos.at(
"gamma_baro").get<Tscal>());
127 has_updated_config =
true;
130 "Ramses::SolverConfig",
131 "Updating old [eos_config] of type [reset_barotropic] to an adiabatic "
132 "[eos_config] with an [instant_barotropic] [cooling_config] in from_json");
134 }
else if (j.contains(
"eos_config")) {
136 }
else if (j.contains(
"eos_gamma")) {
139 has_updated_config =
true;
142 "Ramses::SolverConfig",
143 "Updating old key [eos_gamma] to new key [eos_config] in from_json");
146 has_used_defaults =
true;
148 if (!is_legacy_reset_barotropic) {
151 _get_to_if_contains(
"face_half_time_interpolation", p.face_half_time_interpolation);
152 _get_to_if_contains(
"gravity_solver", p.gravity_config.gravity_mode);
153 _get_to_if_contains(
"gravity_tol", p.gravity_config.tol);
154 _get_to_if_contains(
"gravity_tol_happy_breakdown", p.gravity_config.tol_hp_bk);
155 _get_to_if_contains(
"gravity_Niter_max", p.gravity_config.Niter_max);
156 _get_to_if_contains(
"grid_coord_to_pos_fact", p.grid_coord_to_pos_fact);
157 _get_to_if_contains(
"hydro_riemann_solver", p.riemann_config);
158 _get_to_if_contains(
"passive_scalar_mode", p.npscal_gas_config.npscal_gas);
159 _get_to_if_contains(
"slope_limiter", p.slope_config);
160 _get_to_if_contains(
"unit_sys", p.
unit_sys);
161 _get_to_if_contains(
"drag_config", p.drag_config);
162 _get_to_if_contains(
"bc_config", p.bc_config);
163 _get_to_if_contains(
"amr_mode", p.
amr_mode);
164 _get_to_if_contains(
"amr_interp_mode", p.amr_interp_mode);
167 if (has_used_defaults || has_updated_config) {
170 "Ramses::SolverConfig",
176 template void to_json<f64_3, i64_3>(nlohmann::json &j,
const SolverConfig<f64_3, i64_3> &p);
177 template void from_json<f64_3, i64_3>(
const nlohmann::json &j, SolverConfig<f64_3, i64_3> &p);
std::uint32_t u32
32 bit unsigned integer
void add_field(const std::string &field_name, u32 nvar, SourceLocation loc=SourceLocation{})
add a field of type T to the layout
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
namespace for the basegodunov model
void get_to_if_contains(const nlohmann::json &j, const std::string &key, T &value, bool &has_used_defaults)
std::string log_json_changes(const nlohmann::json &j_current, const nlohmann::json &j, bool has_used_defaults, bool has_updated_config)
Shown the changes between two JSON objects to log config changes.
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 set_eos_gamma(Tscal gamma)
Set an adiabatic equation of state (kept for backward compatibility).
ExtForceConfig ext_force_config
External forces applied to the gas.
AMRMode< Tvec, TgridVec > amr_mode
AMR refinement mode.
std::optional< shamunits::UnitSystem< Tscal > > unit_sys
The unit system of the simulation.
EOSConfig< Tvec > eos_config
Equation of state of the gas.
CoolingConfig< Tvec > cooling_config
Cooling of the gas.