61 template<
class Tvec,
template<
class>
class SPHKernel>
85 Tscal
cfl_NIMHD = 1. / (2 * shambase::constants::pi<Tscal>);
98 using Tscal = shambase::VecComponent<Tvec>;
104 using kill_t = std::variant<Sphere>;
106 std::vector<kill_t> kill_list;
108 inline void add_kill_sphere(
const Tvec ¢er, Tscal radius) {
109 kill_list.push_back(
Sphere{center, radius});
113 template<
class Tscal>
126 std::vector<Tscal> massgrid;
127 std::vector<Tscal> tabflux_coag;
130 template<
class Tscal>
137 bool pure_diffusion_mode =
false;
139 Tscal C_1_fluid = 0.1;
141 Tscal cfl_density_threshold = shambase::get_epsilon<Tscal>();
143 bool ensure_s_j_positivity =
true;
145 bool smooth_s_positivity_limiter =
false;
148 bool dust_corrected_av =
false;
152 std::optional<Tscal> clamp_dust_frac = std::nullopt;
154 static constexpr Tscal default_clamp_dust_frac = 0.99;
156 inline bool should_clamp_dust_density()
const {
return clamp_dust_frac.has_value(); }
158 inline Tscal get_clamp_dust_frac()
const {
159 return clamp_dust_frac.value_or(default_clamp_dust_frac);
166 bool pair_gate_s_positivity_limiter =
false;
174 using Variant = std::variant<None, MonofluidTVA, MonofluidComplete>;
178 inline void set_none() { current_mode = None{}; }
179 inline void set_monofluid_tva(
181 bool pure_diffusion_mode =
false,
182 Tscal C_1_fluid = 0.1,
184 Tscal cfl_density_threshold = shambase::get_epsilon<Tscal>(),
185 bool ensure_s_j_positivity =
true,
186 bool smooth_s_positivity_limiter =
false,
187 bool dust_corrected_av =
false,
188 std::optional<Tscal> clamp_dust_frac = std::nullopt,
189 bool pair_gate_s_positivity_limiter =
false) {
190 current_mode = MonofluidTVA{
195 cfl_density_threshold,
196 ensure_s_j_positivity,
197 smooth_s_positivity_limiter,
200 pair_gate_s_positivity_limiter};
204 inline bool is_none() {
return std::holds_alternative<None>(current_mode); }
205 inline bool is_monofluid_tva() {
return bool(std::get_if<MonofluidTVA>(¤t_mode)); }
206 inline bool is_monofluid_complete() {
207 return bool(std::get_if<MonofluidComplete>(¤t_mode));
214 inline void mode_to_json(nlohmann::json &j)
const {
215 if (
const None *cfg = std::get_if<None>(¤t_mode)) {
216 j = {{
"type",
"none"}};
217 }
else if (
const MonofluidTVA *cfg = std::get_if<MonofluidTVA>(¤t_mode)) {
219 = {{
"type",
"monofluid_tva"},
220 {
"ndust", cfg->ndust},
221 {
"pure_diffusion_mode", cfg->pure_diffusion_mode},
222 {
"C_1_fluid", cfg->C_1_fluid},
223 {
"C_drift", cfg->C_drift},
224 {
"cfl_density_threshold", cfg->cfl_density_threshold},
225 {
"ensure_s_j_positivity", cfg->ensure_s_j_positivity},
226 {
"smooth_s_positivity_limiter", cfg->smooth_s_positivity_limiter},
227 {
"dust_corrected_av", cfg->dust_corrected_av},
228 {
"clamp_dust_frac", cfg->clamp_dust_frac},
229 {
"pair_gate_s_positivity_limiter", cfg->pair_gate_s_positivity_limiter}};
232 j = {{
"type",
"monofluid_complete"}, {
"ndust", cfg->ndust}};
238 inline void mode_from_json(
const nlohmann::json &j) {
239 const std::string type = j.at(
"type").get<std::string>();
240 if (type ==
"none") {
242 }
else if (type ==
"monofluid_tva") {
244 j.at(
"ndust").get<
u32>(),
245 j.at(
"pure_diffusion_mode").get<
bool>(),
246 j.at(
"C_1_fluid").get<Tscal>(),
247 j.at(
"C_drift").get<Tscal>(),
248 j.at(
"cfl_density_threshold").get<Tscal>(),
249 j.at(
"ensure_s_j_positivity").get<
bool>(),
250 j.value(
"smooth_s_positivity_limiter",
false),
251 j.value(
"dust_corrected_av",
false),
252 j.value(
"clamp_dust_frac", std::optional<Tscal>{}),
253 j.value(
"pair_gate_s_positivity_limiter",
false));
254 }
else if (type ==
"monofluid_complete") {
255 set_monofluid_complete(j.at(
"ndust").get<
u32>());
261 inline bool has_s_j_field() {
262 return is_monofluid_tva();
265 inline bool should_use_dust_av() {
266 if (!is_monofluid_tva()) {
269 return get_monofluid_tva().dust_corrected_av;
272 inline bool has_epsilon_field() {
273 return bool(std::get_if<MonofluidComplete>(¤t_mode));
276 inline bool has_deltav_field() {
277 return bool(std::get_if<MonofluidComplete>(¤t_mode));
280 inline u32 get_dust_nvar() {
281 if (
None *cfg = std::get_if<None>(¤t_mode)) {
283 "Querying a dust nvar with no dust as config is ... discutable ...");
285 }
else if (
MonofluidTVA *cfg = std::get_if<MonofluidTVA>(¤t_mode)) {
287 }
else if (
MonofluidComplete *cfg = std::get_if<MonofluidComplete>(¤t_mode)) {
296 std::vector<Tscal> stopping_times;
300 static constexpr bool supersonic_correction =
false;
302 std::vector<Tscal> grains_sizes;
303 std::vector<Tscal> grains_densities;
306 std::variant<None, ConstantStoppingTimes, EpsteinDrag> dust_drag_mode =
None{};
308 bool ballabio_ts_limiter =
false;
310 inline void drag_mode_to_json(nlohmann::json &j)
const {
311 if (std::holds_alternative<None>(dust_drag_mode)) {
312 j = {{
"type",
"none"}};
315 = std::get_if<ConstantStoppingTimes>(&dust_drag_mode)) {
316 j = {{
"type",
"constant_stopping_times"}, {
"stopping_times", cfg->stopping_times}};
317 }
else if (
const EpsteinDrag *cfg = std::get_if<EpsteinDrag>(&dust_drag_mode)) {
319 = {{
"type",
"epstein_drag"},
320 {
"gamma", cfg->gamma},
321 {
"grains_sizes", cfg->grains_sizes},
322 {
"grains_densities", cfg->grains_densities}};
328 inline void drag_mode_from_json(
const nlohmann::json &j) {
329 if (j.at(
"type").get<std::string>() ==
"none") {
330 dust_drag_mode =
None{};
331 }
else if (j.at(
"type").get<std::string>() ==
"constant_stopping_times") {
334 }
else if (j.at(
"type").get<std::string>() ==
"epstein_drag") {
336 j.at(
"gamma").get<Tscal>(),
337 j.at(
"grains_sizes").get<std::vector<Tscal>>(),
338 j.at(
"grains_densities").get<std::vector<Tscal>>()};
346 inline void set_drag_epstein(
EpsteinDrag in) { dust_drag_mode = std::move(in); }
348 std::variant<None, DustEvolCoalaCoag<Tscal>> dust_evol_config =
None{};
350 inline void evol_mode_to_json(nlohmann::json &j)
const {
354 j = {{
"type",
"none"}};
356 [&](
const DustEvolCoalaCoag<Tscal> &cfg) {
358 = {{
"type",
"coala_coag"},
359 {
"rhodust_eps", cfg.rhodust_eps},
360 {
"tau_frac", cfg.tau_frac},
361 {
"vfrag_threshold", cfg.vfrag_threshold},
362 {
"massgrid", cfg.massgrid},
363 {
"tabflux_coag", cfg.tabflux_coag}};
369 inline void evol_mode_from_json(
const nlohmann::json &j) {
370 if (j.at(
"type").get<std::string>() ==
"none") {
371 dust_evol_config =
None{};
372 }
else if (j.at(
"type").get<std::string>() ==
"coala_coag") {
373 dust_evol_config = DustEvolCoalaCoag<Tscal>{
374 .rhodust_eps = j.at(
"rhodust_eps").get<Tscal>(),
376 .tau_frac = j.value(
"tau_frac", Tscal(10)),
377 .vfrag_threshold = j.at(
"vfrag_threshold").get<Tscal>(),
378 .massgrid = j.at(
"massgrid").get<std::vector<Tscal>>(),
379 .tabflux_coag = j.at(
"tabflux_coag").get<std::vector<Tscal>>()};
385 inline void set_dust_evol_coala(DustEvolCoalaCoag<Tscal> cfg) { dust_evol_config = cfg; }
387 inline void check_config() {
388 bool is_not_none = !is_none();
393 "Dust config != None is experimental");
398 "Dust config != None is work in progress, use it at your own risk"));
401 if (std::holds_alternative<None>(dust_drag_mode)) {
403 "you must select a drag mode for the dust if the dust is on !");
406 = std::get_if<ConstantStoppingTimes>(&dust_drag_mode)) {
407 if (get_dust_nvar() != cfg->stopping_times.size()) {
409 "stopping_times size does not match the number of dust bins");
411 }
else if (
EpsteinDrag *cfg = std::get_if<EpsteinDrag>(&dust_drag_mode)) {
412 if (get_dust_nvar() != cfg->grains_densities.size()) {
414 "grains_densities size does not match the number of dust bins");
417 if (get_dust_nvar() != cfg->grains_sizes.size()) {
419 "grains_sizes size does not match the number of dust bins");
424 if (!std::holds_alternative<None>(dust_evol_config) && is_not_none) {
426 if (DustEvolCoalaCoag<Tscal> *cfg
427 = std::get_if<DustEvolCoalaCoag<Tscal>>(&dust_evol_config)) {
429 u32 ndust = get_dust_nvar();
431 if (cfg->massgrid.size() - 1 != ndust) {
433 "massgrid must have ndust + 1 = " + std::to_string(ndust + 1)
434 +
" entries for ndust = " + std::to_string(ndust) +
", got "
435 + std::to_string(cfg->massgrid.size()));
438 if (cfg->tabflux_coag.size() != ndust * ndust * ndust) {
440 "tabflux_coag must have ndust^3 = "
441 + std::to_string(ndust * ndust * ndust)
442 +
" entries for ndust = " + std::to_string(ndust) +
", got "
443 + std::to_string(cfg->tabflux_coag.size()));
446 if (cfg->rhodust_eps <= 0) {
448 "rhodust_eps must be positive, got "
449 + std::to_string(cfg->rhodust_eps));
452 if (!(cfg->tau_frac > 0)) {
454 "tau_frac must be positive, got " + std::to_string(cfg->tau_frac));
457 if (cfg->vfrag_threshold <= 0) {
459 "vfrag_threshold must be positive, got "
460 + std::to_string(cfg->vfrag_threshold));
467 }
else if (!std::holds_alternative<None>(dust_evol_config) && is_none()) {
469 "cannot enable dust evolution because the dust mode is 'none', call "
470 "set_dust_mode_* before set_dust_evol_coala");
478 u32 max_neigh_count = 500;
482 using mode = std::variant<DensityBased, DensityBasedNeighLim, DensityBasedBisectingNR>;
486 void set_density_based() { config = DensityBased{}; }
487 void set_density_based_neigh_lim(
u32 max_neigh_count) {
488 config = DensityBasedNeighLim{max_neigh_count};
492 bool is_density_based_neigh_lim()
const {
493 return std::holds_alternative<DensityBasedNeighLim>(config);
495 bool is_density_based_bisecting_nr()
const {
496 return std::holds_alternative<DensityBasedBisectingNR>(config);
522 bool reference_mode =
false;
527 using mode = std::variant<SFMM, FMM, MM, Direct, None>;
529 mode config =
None{};
531 void set_none() { config = None{}; }
532 void set_direct(
bool reference_mode =
false) { config = Direct{reference_mode}; }
533 void set_mm(
u32 mm_order,
f64 opening_angle,
u32 reduction_level) {
536 .opening_angle = opening_angle,
537 .reduction_level = reduction_level};
539 void set_fmm(
u32 order,
f64 opening_angle,
u32 reduction_level) {
541 .order = order, .opening_angle = opening_angle, .reduction_level = reduction_level};
543 void set_sfmm(
u32 order,
f64 opening_angle,
bool leaf_lowering,
u32 reduction_level) {
546 .opening_angle = opening_angle,
547 .leaf_lowering = leaf_lowering,
548 .reduction_level = reduction_level};
551 bool is_none()
const {
return std::holds_alternative<None>(config); }
552 bool is_direct()
const {
return std::holds_alternative<Direct>(config); }
553 bool is_mm()
const {
return std::holds_alternative<MM>(config); }
554 bool is_fmm()
const {
return std::holds_alternative<FMM>(config); }
555 bool is_sfmm()
const {
return std::holds_alternative<SFMM>(config); }
557 bool is_sg_on()
const {
return !is_none(); }
558 bool is_sg_off()
const {
return is_none(); }
564 using mode_soft = std::variant<SofteningPlummer>;
567 void set_softening_plummer(
f64 epsilon) { softening_mode = SofteningPlummer{epsilon}; }
568 void set_softening_none() { set_softening_plummer(0.); }
570 bool is_softening_plummer()
const {
571 return std::holds_alternative<SofteningPlummer>(softening_mode);
577template<
class Tvec,
template<
class>
class SPHKernel>
581 using Tscal = shambase::VecComponent<Tvec>;
583 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
596 bool track_particles_id =
false;
598 inline void set_particle_tracking(
bool state) { track_particles_id = state; }
613 std::optional<shamunits::UnitSystem<Tscal>>
unit_sys = {};
636 return get_unit_sys().template get<shamunits::constants::mu_0>();
667 bool show_cfl_detail =
false;
683 mhd_config.set(Tmp{});
692 logger::raw_ln(
"$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$");
699 logger::raw_ln(
"|______| |__| |__||_| |__||_______||_______||___| |_|");
700 logger::raw_ln(
"$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$");
705 "Non-ideal MHD is experimental, please enable experimental features to use it");
717 using DustConfig = DustConfig<Tscal>;
718 DustConfig dust_config = {};
728 SelfGravConfig self_grav_config = SelfGravConfig{};
758 "set_two_stage_search() is deprecated,\n"
759 " -> use set_neigh_cache_strategy(NeighCacheStrategy.TwoStage) or\n"
760 " set_neigh_cache_strategy(NeighCacheStrategy.SingleStage) instead"););
764 bool show_neigh_stats =
false;
765 inline void set_show_neigh_stats(
bool enable) { show_neigh_stats = enable; }
786 inline void set_smoothing_length_density_based() {
787 smoothing_length_config.set_density_based();
789 inline void set_smoothing_length_density_based_neigh_lim(
u32 max_neigh_count) {
790 smoothing_length_config.set_density_based_neigh_lim(max_neigh_count);
792 inline void set_smoothing_length_density_based_bisecting_nr() {
793 smoothing_length_config.set_density_based_bisecting_nr();
796 bool enable_particle_reordering =
false;
797 inline void set_enable_particle_reordering(
bool enable) { enable_particle_reordering = enable; }
798 u64 particle_reordering_step_freq = 1000;
799 inline void set_particle_reordering_step_freq(
u64 freq) {
802 "particle_reordering_step_freq cannot be zero");
804 particle_reordering_step_freq = freq;
807 bool save_dt_to_fields =
false;
808 inline void set_save_dt_to_fields(
bool enable) { save_dt_to_fields = enable; }
809 inline bool should_save_dt_to_fields()
const {
return save_dt_to_fields; }
811 bool show_ghost_zone_graph =
false;
812 inline void set_show_ghost_zone_graph(
bool enable) { show_ghost_zone_graph = enable; }
816 inline void set_show_ghost_stats(
bool enable) {
show_ghost_stats = enable; }
835 return bool(std::get_if<T>(&
eos_config.config));
841 return bool(std::get_if<T>(&
eos_config.config));
847 return bool(std::get_if<T>(&
eos_config.config));
853 return bool(std::get_if<T>(&
eos_config.config));
859 return bool(std::get_if<T>(&
eos_config.config));
865 return bool(std::get_if<T>(&
eos_config.config));
903 eos_config.set_locally_isothermalLP07(cs0, q, r0);
914 eos_config.set_locally_isothermalFA2014(h_over_r);
928 eos_config.set_locally_isothermalFA2014_extended(cs0, q, r0, n_sinks);
980 using Tmp =
typename AVConfig::None;
1100 Tscal central_mass,
Tscal Racc, Tvec central_pos = Tvec{}) {
1124 Tscal central_mass,
Tscal Racc,
Tscal a_spin, Tvec dir_spin, Tvec central_pos = Tvec{}) {
1125 ext_force_config.add_lense_thirring(central_mass, Racc, a_spin, dir_spin, central_pos);
1158 this->do_debug_dump = _do_debug_dump;
1159 this->debug_dump_filename = _debug_dump_filename;
1201 inline bool do_nimhd() {
return mhd_config.do_nimhd(); }
1224 inline void use_GW(
bool enable) {
1239 inline void check_config() {
1240 dust_config.check_config();
1241 mhd_config.check_config();
1243 if (track_particles_id &&
false ) {
1245 "particle injection is not yet compatible with particle id tracking");
1248 if (track_particles_id) {
1252 if (!self_grav_config.is_none()) {
1254 "Self gravity is experimental, please enable experimental features to use it");
1257 if (mhd_config.do_nimhd()) {
1259 "Non-ideal MHD is experimental, please enable experimental features to use it");
1263 if (
const EOSBarotropic *eos = std::get_if<EOSBarotropic>(&
eos_config.config)) {
1264 if (!(eos->cs0 > 0) || !(eos->rho0 > 0) || !(eos->gamma0 > 1)) {
1266 "barotropic EOS requires cs0 > 0, rho0 > 0 and gamma0 > 1, got cs0 = {}, "
1267 "rho0 = {}, gamma0 = {}",
1275 void set_layout(shamrock::patch::PatchDataLayerLayout &pdl);
1276 void set_ghost_layout(shamrock::patch::PatchDataLayerLayout &ghost_layout);
1287 template<
class Tscal>
1302 template<
class Tscal>
1304 j.at(
"cfl_cour").get_to<Tscal>(p.
cfl_cour);
1305 j.at(
"cfl_force").get_to<Tscal>(p.
cfl_force);
1308 if (j.contains(
"eta_sink")) {
1309 j.at(
"eta_sink").get_to<Tscal>(p.
eta_sink);
1313 "SPHConfig",
"eta_sink not found when deserializing, defaulting to", p.
eta_sink));
1318 template<
class Tvec>
1319 inline void to_json(nlohmann::json &j,
const ParticleKillingConfig<Tvec> &p) {
1320 j = nlohmann::json::array();
1321 for (
const auto &kill : p.kill_list) {
1322 if (std::holds_alternative<
typename ParticleKillingConfig<Tvec>::Sphere>(kill)) {
1323 const auto &sphere = std::get<typename ParticleKillingConfig<Tvec>::Sphere>(kill);
1325 {{
"type",
"sphere"}, {
"center", sphere.center}, {
"radius", sphere.radius}});
1331 template<
class Tvec>
1333 p.kill_list.clear();
1334 for (
const auto &item : j) {
1335 std::string type = item.at(
"type").get<std::string>();
1336 if (type ==
"sphere") {
1338 item.at(
"center").get_to(sphere.center);
1339 item.at(
"radius").get_to(sphere.radius);
1340 p.kill_list.push_back(sphere);
1349 = std::get_if<SmoothingLengthConfig::DensityBased>(&p.config)) {
1351 {
"type",
"density_based"},
1356 = std::get_if<SmoothingLengthConfig::DensityBasedNeighLim>(&p.config)) {
1359 {
"type",
"density_based_neigh_lim"},
1360 {
"max_neigh_count", conf->max_neigh_count},
1364 = std::get_if<SmoothingLengthConfig::DensityBasedBisectingNR>(&p.config)) {
1366 {
"type",
"density_based_bisecting_nr"},
1374 if (j.at(
"type").get<std::string>() ==
"density_based") {
1376 }
else if (j.at(
"type").get<std::string>() ==
"density_based_neigh_lim") {
1379 }
else if (j.at(
"type").get<std::string>() ==
"density_based_bisecting_nr") {
1391 {
"order", conf->order},
1392 {
"opening_angle", conf->opening_angle},
1393 {
"reduction_level", conf->reduction_level},
1394 {
"leaf_lowering", conf->leaf_lowering},
1396 }
else if (
const SelfGravConfig::FMM *conf = std::get_if<SelfGravConfig::FMM>(&p.config)) {
1399 {
"order", conf->order},
1400 {
"opening_angle", conf->opening_angle},
1401 {
"reduction_level", conf->reduction_level},
1403 }
else if (
const SelfGravConfig::MM *conf = std::get_if<SelfGravConfig::MM>(&p.config)) {
1406 {
"order", conf->order},
1407 {
"opening_angle", conf->opening_angle},
1408 {
"reduction_level", conf->reduction_level},
1414 {
"reference_mode", conf->reference_mode},
1424 = std::get_if<SelfGravConfig::SofteningPlummer>(&p.softening_mode)) {
1425 j[
"softening_mode"] =
"plummer";
1426 j[
"softening_length"] = conf->epsilon;
1434 if (j.at(
"type").get<std::string>() ==
"sfmm") {
1436 .order = j.at(
"order").get<
u32>(),
1437 .opening_angle = j.at(
"opening_angle").get<
f64>(),
1438 .leaf_lowering = j.at(
"leaf_lowering").get<
bool>(),
1439 .reduction_level = j.at(
"reduction_level").get<
u32>()};
1440 }
else if (j.at(
"type").get<std::string>() ==
"fmm") {
1442 .order = j.at(
"order").get<
u32>(),
1443 .opening_angle = j.at(
"opening_angle").get<
f64>(),
1444 .reduction_level = j.at(
"reduction_level").get<
u32>()};
1445 }
else if (j.at(
"type").get<std::string>() ==
"mm") {
1447 .order = j.at(
"order").get<
u32>(),
1448 .opening_angle = j.at(
"opening_angle").get<
f64>(),
1449 .reduction_level = j.at(
"reduction_level").get<
u32>()};
1450 }
else if (j.at(
"type").get<std::string>() ==
"direct") {
1452 }
else if (j.at(
"type").get<std::string>() ==
"none") {
1456 "Invalid self gravity type: " + j.at(
"type").get<std::string>());
1459 if (j.contains(
"softening_mode")) {
1460 std::string softening_mode = j.at(
"softening_mode").get<std::string>();
1461 if (softening_mode ==
"plummer") {
1466 "Invalid softening mode: " + softening_mode);
1472 template<
class Tvec>
1473 inline void to_json(nlohmann::json &j,
const DustConfig<Tvec> &p) {
1476 p.mode_to_json(j[
"mode"]);
1477 p.drag_mode_to_json(j[
"drag_mode"]);
1478 p.evol_mode_to_json(j[
"evol_mode"]);
1479 j[
"ballabio_ts_limiter"] = p.ballabio_ts_limiter;
1482 template<
class Tvec>
1484 p.mode_from_json(j.at(
"mode"));
1485 p.drag_mode_from_json(j.at(
"drag_mode"));
1486 if (j.contains(
"evol_mode")) {
1487 p.evol_mode_from_json(j.at(
"evol_mode"));
1489 p.ballabio_ts_limiter = j.value(
"ballabio_ts_limiter",
false);
1498 template<
class Tvec,
template<
class>
class SPHKernel>
1501 using Tkernel =
typename T::Kernel;
1503 std::string kernel_id = shambase::get_type_name<Tkernel>();
1504 std::string type_id = shambase::get_type_name<Tvec>();
1508 {
"kernel_id", kernel_id},
1509 {
"type_id", type_id},
1511 {
"scheduler_config", p.scheduler_conf},
1516 {
"show_cfl_detail", p.show_cfl_detail},
1518 {
"mhd_config", p.mhd_config},
1520 {
"dust_config", p.dust_config},
1522 {
"self_grav_config", p.self_grav_config},
1526 {
"show_neigh_stats", p.show_neigh_stats},
1532 {
"smoothing_length_config", p.smoothing_length_config},
1536 {
"enable_particle_reordering", p.enable_particle_reordering},
1537 {
"particle_reordering_step_freq", p.particle_reordering_step_freq},
1539 {
"save_dt_to_fields", p.save_dt_to_fields},
1540 {
"show_ghost_zone_graph", p.show_ghost_zone_graph},
1552 {
"particle_killing", p.particle_killing},
1562 template<
class Tvec,
template<
class>
class SPHKernel>
1565 using Tkernel =
typename T::Kernel;
1568 if (j.contains(
"kernel_id")) {
1570 std::string kernel_id = j.at(
"kernel_id").get<std::string>();
1572 if (kernel_id != shambase::get_type_name<Tkernel>()) {
1574 "Invalid type to deserialize, wanted " + shambase::get_type_name<Tvec>()
1575 +
" but got " + kernel_id);
1579 if (j.contains(
"type_id")) {
1581 std::string type_id = j.at(
"type_id").get<std::string>();
1583 if (type_id != shambase::get_type_name<Tvec>()) {
1585 "Invalid type to deserialize, wanted " + shambase::get_type_name<Tvec>()
1586 +
" but got " + type_id);
1590 bool has_used_defaults =
false;
1591 bool has_updated_config =
false;
1593 auto _get_to_if_contains = [&](
const std::string &key,
auto &value) {
1597 auto _get_to_if_contains_fallbacks = [&](
const std::string &key,
1599 std::initializer_list<const char *> fallbacks) {
1601 j, key, value, fallbacks, has_used_defaults, has_updated_config);
1604 _get_to_if_contains(
"scheduler_config", p.scheduler_conf);
1607 _get_to_if_contains(
"gpart_mass", p.
gpart_mass);
1608 _get_to_if_contains(
"cfl_config", p.
cfl_config);
1609 _get_to_if_contains(
"unit_sys", p.
unit_sys);
1610 _get_to_if_contains(
"show_cfl_detail", p.show_cfl_detail);
1611 _get_to_if_contains(
"mhd_config", p.mhd_config);
1612 _get_to_if_contains(
"dust_config", p.dust_config);
1613 _get_to_if_contains(
"self_grav_config", p.self_grav_config);
1618 _get_to_if_contains(
"show_neigh_stats", p.show_neigh_stats);
1622 _get_to_if_contains_fallbacks(
1624 _get_to_if_contains_fallbacks(
"htol_up_fine_cycle", p.
htol_up_fine_cycle, {
"htol_up_iter"});
1626 _get_to_if_contains(
"epsilon_h", p.
epsilon_h);
1627 _get_to_if_contains(
"smoothing_length_config", p.smoothing_length_config);
1630 _get_to_if_contains(
"enable_particle_reordering", p.enable_particle_reordering);
1631 _get_to_if_contains(
"particle_reordering_step_freq", p.particle_reordering_step_freq);
1632 _get_to_if_contains(
"save_dt_to_fields", p.save_dt_to_fields);
1633 _get_to_if_contains(
"show_ghost_zone_graph", p.show_ghost_zone_graph);
1635 _get_to_if_contains(
"eos_config", p.
eos_config);
1641 _get_to_if_contains(
"particle_killing", p.particle_killing);
1643 if (has_used_defaults || has_updated_config) {
1646 "SPH::SolverConfig",
Header file describing a Node Instance.
A unit system: the values of the seven SI base units in code units.
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
A unit system, defined by the SI value of its base units.
The table of physical constants: each constant is a Unit (its SI value and dimension).
Neighbour cache build strategy 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.
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...
overloaded(Ts...) -> overloaded< Ts... >
Deduction guide so overloaded{lambda1, lambda2, ...} deduces Ts... from the lambdas.
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.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
namespace for the sph model
constexpr const char * neigh_cache_strategy_json_key
Json key holding the neighbour cache strategy.
void get_to_neigh_cache_strategy(const nlohmann::json &j, NeighCacheStrategy &value, const std::string &log_ctx, bool &has_used_defaults, bool &has_updated_config)
Deserialize the neighbour cache strategy, falling back on the legacy boolean key.
NeighCacheStrategy neigh_cache_strategy_from_two_stage_search(bool use_two_stage_search)
Map the legacy use_two_stage_search boolean onto the strategy enum.
NeighCacheStrategy
Strategy used to build the neighbour cache out of the tree traversal.
@ TwoStage
Two stage neighbours search (see shamrock paper).
void get_to_if_contains(const nlohmann::json &j, const std::string &key, T &value, bool &has_used_defaults)
void experimental_feature_check(const std::string &message, SourceLocation loc=SourceLocation{})
Check if experimental features are enabled, if not throw with the given message.
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.
bool are_experimental_features_allowed()
Allow the use of experimental features.
void get_to_if_contains_fallbacks(const nlohmann::json &j, const std::string &key, T &value, std::initializer_list< const char * > fallbacks, bool &has_used_defaults, bool &has_updated_config)
Contains traits and utilities for backend related types.
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
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.
Locally isothermal equation of state configuration.
Configuration struct for the equation of state used in the hydrodynamic models.
shamphys::EOS_Config_Polytropic< Tscal > Polytropic
Polytropic equation of state configuration.
shamphys::EOS_Config_Isothermal< Tscal > Isothermal
Isothermal equation of state configuration.
shamphys::EOS_Config_Fermi< Tscal > Fermi
Fermi equation of state configuration.
shamphys::EOS_Config_Adiabatic< Tscal > Adiabatic
Adiabatic equation of state configuration.
shamphys::EOS_Config_Barotropic< Tscal > Barotropic
Barotropic equation of state configuration.
The configuration for the CFL condition.
Tscal eta_sink
eta sink to control the sink integrator
Tscal cfl_NIMHD
The CFL condition for the non-ideal MHD terms.
Tscal cfl_cour
The CFL condition for the courant factor.
Tscal cfl_multiplier_stiffness
The CFL multiplier stiffness.
Tscal cfl_force
The CFL condition for the force.
std::variant< None, MonofluidTVA, MonofluidComplete > Variant
Variant type to store the EOS configuration.
The configuration for a sph solver.
bool ghost_has_soundspeed()
Whether the ghost cells have a sound speed (i.e. the eos is locally isothermal).
AVConfig artif_viscosity
Configuration for the Artificial Viscosity (AV).
bool has_field_dtdiv_b()
Whether the solver has a field for dt divB.
void set_eos_isothermal(Tscal cs)
Set the EOS configuration to an isothermal equation of state.
Tscal gpart_mass
The mass of each gas particle (must be set before use).
u32 h_max_subcycles_count
Maximum number of subcycles before solver crash.
bool compute_luminosity
Whether to store luminosity.
void print_status()
Print the current status of the solver config.
void set_eos_adiabatic(Tscal gamma)
Set the EOS configuration to an adiabatic equation of state.
bool has_field_uint()
Whether the solver has a field for the particle's uint.
bool is_eos_isothermal()
Check if the EOS is an isothermal equation of state.
void set_ideal_mhd(typename MHDConfig::IdealMhdConstrainedHyperPara v)
Enable the ideal MHD hydro solver.
BCConfig boundary_config
Boundary condition configuration.
bool has_field_psi_on_ch()
Whether the solver has a field for psi_on_ch.
void set_cfl_mult_stiffness(Tscal cstiff)
Set the CFL multiplier for the stiffness.
bool has_axyz_in_ghost()
Whether the solver has a field for ax, ay, az in ghost cells.
void set_eos_barotropic(Tscal cs0, Tscal rho0, Tscal gamma0)
Set the EOS configuration to a barotropic equation of state.
void set_eos_locally_isothermalLP07(Tscal cs0, Tscal q, Tscal r0)
Set the EOS configuration to a locally isothermal equation of state from Lodato Price 2007.
CFLConfig< Tscal > cfl_config
The configuration for the CFL condition.
void set_artif_viscosity_VaryingMM97(typename AVConfig::VaryingMM97 v)
Set the artificial viscosity configuration to a varying value using the prescription of Monaghan & Gi...
bool combined_dtdiv_divcurlv_compute
void add_ext_force_lense_thirring(Tscal central_mass, Tscal Racc, Tscal a_spin, Tvec dir_spin, Tvec central_pos=Tvec{})
Add a Lense-Thirring external force.
Tscal epsilon_h
Convergence criteria for the smoothing length.
SPHKernel< Tscal > Kernel
The type of the kernel used for the SPH interactions.
shamunits::UnitSystem< Tscal > get_unit_sys()
The unit system of the config, or the default one (SI) if it is not set.
bool show_ghost_stats
Show the ghost particle count (and ratio to the particle count) in the timestep perf report.
Tscal htol_up_coarse_cycle
bool do_debug_dump
Whether to dump debug information to file.
bool has_field_divv()
Whether the solver has a field for divv.
bool compute_gw
Whether to compute GW.
shambase::VecComponent< Tvec > Tscal
The type of the scalar used to represent the quantities.
Tscal get_cfl_mult_stiffness()
Get the CFL multiplier for the stiffness.
bool has_field_alphaAV()
Whether the solver has a field for alpha AV.
void set_debug_dump(bool _do_debug_dump, std::string _debug_dump_filename)
Set whether to dump debug information to file.
u32 h_iter_per_subcycles
Maximum number of iterations per subcycle.
shammodels::ExtForceConfig< Tvec > ExtForceConfig
External force configuration.
bool is_eos_adiabatic()
Check if the EOS is an adiabatic equation of state.
void set_artif_viscosity_VaryingCD10(typename AVConfig::VaryingCD10 v)
Set the artificial viscosity configuration to a varying value using the prescription of Cullen & Dehn...
bool filter_empty_patch_gz
Skip the ghost interfaces whose sender or receiver patch is empty.
void add_ext_force_point_mass(Tscal central_mass, Tscal Racc, Tvec central_pos=Tvec{})
Add a point mass external force.
void set_neigh_cache_strategy(NeighCacheStrategy strategy)
Setter for the neighbours cache strategy.
void set_two_stage_search(bool enable)
Setter for the two stage search.
void set_boundary_free()
Set the boundary condition to free boundary.
bool has_field_curlv()
Whether the solver has a field for curlv.
bool has_field_dtdivv()
Whether the solver has a field for dt divv.
std::string debug_dump_filename
The filename to dump debug information in.
void add_ext_force_paczynski_wiita(Tscal central_mass, Tvec central_pos, Tscal Racc)
Add a post-newtonian Paczynski-Wiita potential.
bool is_eos_locally_isothermal()
Check if the EOS is a locally isothermal equation of state.
static constexpr Tscal Rkern
The radius of the sph kernel.
void set_eos_locally_isothermalFA2014_extended(Tscal cs0, Tscal q, Tscal r0, u32 n_sinks)
Set the EOS configuration to a locally isothermal equation of state from Farris 2014 extended to q !...
void set_eos_locally_isothermal()
Set the EOS configuration to a locally isothermal equation of state.
Tscal get_constant_G()
Retrieves the value of the constant G based on the unit system.
void set_eos_locally_isothermalFA2014(Tscal h_over_r)
Set the EOS configuration to a locally isothermal equation of state fromFarris 2014.
u32 u_morton
The type of the Morton code for the tree.
Tscal get_constant_mu_0()
Retrieves the value of the constant mu_0 based on the unit system.
void set_units(shamunits::UnitSystem< Tscal > new_sys)
Set the unit system of the simulation.
void set_artif_viscosity_None()
Set the artificial viscosity configuration to None.
bool is_eos_fermi()
Check if the EOS is a Fermi equation of state.
void set_tree_reduction_level(u32 level)
Setter for the tree reduction level.
NeighCacheStrategy neigh_cache_strategy
Strategy used to build the neighbours cache out of the tree traversal.
static constexpr u32 dim
The dimension of the problem.
void set_eos_polytropic(Tscal K, Tscal gamma)
Set the EOS configuration to an polytropic equation of state.
Tscal get_constant_c()
Retrieves the value of the constant c based on the unit system.
void set_artif_viscosity_Constant(typename AVConfig::Constant v)
Set the artificial viscosity configuration to a constant value.
bool is_eos_polytropic()
Check if the EOS is a polytropic equation of state.
AVConfig< Tvec > AVConfig
Configuration for the Artificial Viscosity (AV).
BCConfig< Tvec > BCConfig
Configuration of the boundary conditions.
void set_boundary_shearing_periodic(i32_3 shear_base, i32_3 shear_dir, Tscal speed)
Set the boundary condition to shearing periodic boundary.
Tscal htol_up_fine_cycle
Maximum factor of the smoothing length evolution per subcycles.
void set_boundary_periodic()
Set the boundary condition to periodic boundary.
u32 tree_reduction_level
Reduction level to be used in the tree build.
constexpr bool do_MHD_debug()
Whether to add debug fields to the pdl.
std::optional< shamunits::UnitSystem< Tscal > > unit_sys
The unit system of the simulation.
bool has_field_curl_b()
Whether the solver has a field for curlB.
EOSConfig eos_config
EOS configuration.
bool has_field_b_on_rho()
Whether the solver has a field for B_on_rho.
shammodels::EOSConfig< Tvec > EOSConfig
Alias to EOSConfig type.
bool has_field_soundspeed()
Whether the solver has a field for sound speed.
bool is_eos_barotropic()
Check if the EOS is a barotropic equation of state.
void set_noMHD()
disable MHD in the SPH solver
ExtForceConfig ext_force_config
External force configuration.
bool do_nimhd()
Whether the solver is set for non ideal MHD.
void add_ext_force_shearing_box(Tscal Omega_0, Tscal eta, Tscal q)
Add a shearing box external force.
void set_artif_viscosity_ConstantDisc(typename AVConfig::ConstantDisc v)
Set the artificial viscosity configuration to a constant value in the disc plane.
void set_eos_fermi(Tscal mu_e)
Set the EOS configuration to a Fermi equation of state.
bool has_field_div_b()
Whether the solver has a field for divB.
Functions related to the MPI communicator.
#define ON_RANK_0(x)
Macro to execute code only on rank 0.