37#include <nlohmann/json.hpp>
50 DragSolverMode drag_solver_config = NoDrag;
51 std::vector<f64> alphas;
52 bool enable_frictional_heating
60 inline bool is_dust_on() {
61 if (dust_riemann_config !=
NoDust) {
65 "Dust is on with ndust == 0");
78 inline bool is_gas_passive_scalar_on() {
return npscal_gas > 0; }
83 using Tscal = shambase::VecComponent<Tvec>;
84 GravityMode gravity_mode = NoGravity;
85 bool analytical_gravity =
false;
87 inline Tscal get_tolerance() {
return tol; }
88 inline bool is_gravity_on() {
return gravity_mode != NoGravity; }
91 template<
class Tvec,
class Tgr
idVec>
94 using Tscal = shambase::VecComponent<Tvec>;
117 = std::variant<None, DensityBased, PseudoGradientBased, JeansLengthBased, ShearBased>;
119 mode config =
None{};
123 void set_refine_none() { config = None{}; }
124 void set_refine_density_based(Tscal crit_mass) { config = DensityBased{crit_mass}; }
125 void set_refine_pseudo_gradient_based(Tscal error_min, Tscal error_max) {
129 void set_refine_jeans_length_based(
u32 N_J, Tscal T_0) {
133 void set_refine_shear_based(Tscal thresh) { config =
ShearBased{thresh}; }
135 bool need_level_zero_compute() {
return !old_amr; }
136 bool need_amr_level_compute() {
return !old_amr; }
140 enum class GhostType { Periodic = 0, Reflective = 1, Outflow = 2 };
142 GhostType ghost_type_x = GhostType::Periodic;
143 GhostType ghost_type_y = GhostType::Periodic;
144 GhostType ghost_type_z = GhostType::Periodic;
146 GhostType get_x()
const {
return ghost_type_x; }
147 GhostType get_y()
const {
return ghost_type_y; }
148 GhostType get_z()
const {
return ghost_type_z; }
150 void set_x(GhostType ghost_type) { ghost_type_x = ghost_type; }
151 void set_y(GhostType ghost_type) { ghost_type_y = ghost_type; }
152 void set_z(GhostType ghost_type) { ghost_type_z = ghost_type; }
155 template<
class Tvec,
class Tgr
idVec>
160template<
class Tvec,
class Tgr
idVec>
163 using Tscal = shambase::VecComponent<Tvec>;
165 Tscal eos_gamma = 5. / 3.;
167 Tscal grid_coord_to_pos_fact = 1;
169 static constexpr u32 NsideBlockPow = 1;
172 inline void set_eos_gamma(Tscal gamma) { eos_gamma = gamma; }
174 RiemannSolverMode riemann_config = HLL;
176 bool face_half_time_interpolation =
true;
178 inline bool should_compute_rho_mean() {
return is_gravity_on() && is_boundary_periodic(); }
187 inline bool is_dust_on() {
return dust_config.is_dust_on(); }
190 inline void set_alphas_static(
f32 alpha_values) {
192 drag_config.alphas.push_back(alpha_values);
207 inline bool is_gas_passive_scalar_on() {
return npscal_gas_config.is_gas_passive_scalar_on(); }
215 inline Tscal get_constant_G() {
224 inline bool is_boundary_periodic() {
return true; }
226 inline Tscal get_constant_4piG() {
227 auto scal_G = get_constant_G();
228 return 4 * M_PI * scal_G;
230 inline Tscal get_grav_tol() {
return gravity_config.get_tolerance(); }
231 inline bool is_gravity_on() {
return gravity_config.is_gravity_on(); }
232 inline bool is_coordinate_field_required() {
return gravity_config.analytical_gravity; }
246 std::optional<shamunits::UnitSystem<Tscal>>
unit_sys = {};
266 inline void check_config() {
267 if (grid_coord_to_pos_fact <= 0) {
269 "grid_coord_to_pos_fact must be > 0, got {}", grid_coord_to_pos_fact));
276 if (is_gravity_on()) {
277 ON_RANK_0(logger::warn_ln(
"Ramses::SolverConfig",
"Self gravity is experimental"));
278 u32 mode = gravity_config.gravity_mode;
282 "self gravity mode is not enabled but gravity mode is set to {} (> 0 whith 0 "
288 if (!(eos_gamma > 1.0)) {
290 shambase::format(
"Gamma must be > 1, currently Gamma = {}", eos_gamma));
293 if (is_gas_passive_scalar_on()) {
294 ON_RANK_0(logger::warn_ln(
"Ramses::SolverConfig",
"Passive scalars are experimental"));
297 "gas passive scalars mode is not enabled but gas passive scalars mode is set "
300 npscal_gas_config.npscal_gas));
308 void set_layout(shamrock::patch::PatchDataLayerLayout &pdl);
313 inline void to_json(nlohmann::json &j,
const BCConfig::GhostType &e) {
315 case BCConfig::GhostType::Periodic : j =
"periodic";
break;
316 case BCConfig::GhostType::Reflective: j =
"reflective";
break;
317 case BCConfig::GhostType::Outflow : j =
"outflow";
break;
320 "Invalid BCConfig::GhostType value: " + std::to_string(
static_cast<int>(e)));
324 inline void from_json(
const nlohmann::json &j, BCConfig::GhostType &e) {
325 const std::string type = j.get<std::string>();
326 if (type ==
"periodic") {
327 e = BCConfig::GhostType::Periodic;
328 }
else if (type ==
"reflective") {
329 e = BCConfig::GhostType::Reflective;
330 }
else if (type ==
"outflow") {
331 e = BCConfig::GhostType::Outflow;
334 "Invalid BCConfig::GhostType value: " + type);
338 inline void to_json(nlohmann::json &j,
const BCConfig &p) {
340 {
"ghost_type_x", p.ghost_type_x},
341 {
"ghost_type_y", p.ghost_type_y},
342 {
"ghost_type_z", p.ghost_type_z}};
345 inline void from_json(
const nlohmann::json &j,
BCConfig &p) {
346 j.at(
"ghost_type_x").get_to(p.ghost_type_x);
347 j.at(
"ghost_type_y").get_to(p.ghost_type_y);
348 j.at(
"ghost_type_z").get_to(p.ghost_type_z);
351 inline void to_json(nlohmann::json &j,
const DragConfig &p) {
353 {
"drag_solver", p.drag_solver_config},
354 {
"alphas", p.alphas},
355 {
"enable_frictional_heating", p.enable_frictional_heating}};
358 inline void from_json(
const nlohmann::json &j,
DragConfig &p) {
359 j.at(
"drag_solver").get_to(p.drag_solver_config);
360 j.at(
"alphas").get_to(p.alphas);
361 j.at(
"enable_frictional_heating").get_to(p.enable_frictional_heating);
364 template<
class Tvec,
class Tgr
idVec>
368 if (std::holds_alternative<typename AMR::None>(p.config)) {
369 j = {{
"type",
"none"}};
370 }
else if (
const auto *cfg = std::get_if<typename AMR::DensityBased>(&p.config)) {
371 j = {{
"type",
"density_based"}, {
"crit_mass", cfg->crit_mass}};
372 }
else if (
const auto *cfg = std::get_if<typename AMR::PseudoGradientBased>(&p.config)) {
374 = {{
"type",
"pseudo_gradient_based"},
375 {
"error_min", cfg->error_min},
376 {
"error_max", cfg->error_max}};
377 }
else if (
const auto *cfg = std::get_if<typename AMR::JeansLengthBased>(&p.config)) {
378 j = {{
"type",
"jeans_length_based"}, {
"N_J", cfg->N_J}, {
"T_0", cfg->T_0}};
379 }
else if (
const auto *cfg = std::get_if<typename AMR::ShearBased>(&p.config)) {
380 j = {{
"type",
"shear_based"}, {
"threshold", cfg->threshold}};
386 template<
class Tvec,
class Tgr
idVec>
388 using Tscal = shambase::VecComponent<Tvec>;
390 const std::string type = j.at(
"type").get<std::string>();
391 if (type ==
"none") {
393 }
else if (type ==
"density_based") {
394 p.set_refine_density_based(j.at(
"crit_mass").get<Tscal>());
395 }
else if (type ==
"pseudo_gradient_based") {
396 p.set_refine_pseudo_gradient_based(
397 j.at(
"error_min").get<Tscal>(), j.at(
"error_max").get<Tscal>());
398 }
else if (type ==
"jeans_length_based") {
399 p.set_refine_jeans_length_based(j.at(
"N_J").get<
u32>(), j.at(
"T_0").get<Tscal>());
400 }
else if (type ==
"shear_based") {
401 p.set_refine_shear_based(j.at(
"threshold").get<Tscal>());
407 template<
class Tvec,
class Tgr
idVec>
409 nlohmann::json config_j;
410 amr_config_to_json(config_j, p);
411 j = nlohmann::json{{
"old_amr", p.old_amr}, {
"config", config_j}};
414 template<
class Tvec,
class Tgr
idVec>
416 j.at(
"old_amr").get_to(p.old_amr);
417 amr_config_from_json(j.at(
"config"), p);
426 template<
class Tvec,
class Tgr
idVec>
434 template<
class Tvec,
class Tgr
idVec>
utility to manipulate AMR blocks
float f32
Alias for float.
std::uint32_t u32
32 bit unsigned integer
Drag solver mode enum + json serialization/deserialization.
Dust Riemann solver mode enum + json serialization/deserialization.
Gravity mode enum + json serialization/deserialization.
Riemann solver mode enum + json serialization/deserialization.
Slope mode enum + json serialization/deserialization.
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
namespace for the basegodunov model
DustRiemannSolverMode
Dust Riemann solver mode enum.
@ NoDust
No dust, so no Riemann solver is used.
SlopeMode
Slope limiter modes.
void experimental_feature_check(const std::string &message, SourceLocation loc=SourceLocation{})
Check if experimental features are enabled, if not throw with the given message.
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.
utility class to handle AMR blocks
alphas is the dust collision rate (the inverse of the stopping time)
Npscal_gas is the number of gas passive scalars.
AMRMode< Tvec, TgridVec > amr_mode
AMR refinement mode.
std::optional< shamunits::UnitSystem< Tscal > > unit_sys
The unit system of the simulation.
void set_units(shamunits::UnitSystem< Tscal > new_sys)
Set the unit system of the simulation.
constexpr T G()
get the value of G in the current unit system units
#define ON_RANK_0(x)
Macro to execute code only on rank 0.