60 template<
class Tvec,
template<
class>
class SPHKernel>
92 using Tscal = shambase::VecComponent<Tvec>;
98 using kill_t = std::variant<Sphere>;
100 std::vector<kill_t> kill_list;
102 inline void add_kill_sphere(
const Tvec ¢er, Tscal radius) {
103 kill_list.push_back(
Sphere{center, radius});
107 template<
class Tscal>
111 std::vector<Tscal> massgrid;
112 std::vector<Tscal> tabflux_coag;
115 template<
class Tscal>
122 bool pure_diffusion_mode =
false;
124 Tscal C_1_fluid = 0.1;
126 Tscal cfl_density_threshold = shambase::get_epsilon<Tscal>();
128 bool ensure_s_j_positivity =
true;
130 bool smooth_s_positivity_limiter =
false;
133 bool dust_corrected_av =
false;
137 std::optional<Tscal> clamp_dust_frac = std::nullopt;
139 static constexpr Tscal default_clamp_dust_frac = 0.99;
141 inline bool should_clamp_dust_density()
const {
return clamp_dust_frac.has_value(); }
143 inline Tscal get_clamp_dust_frac()
const {
144 return clamp_dust_frac.value_or(default_clamp_dust_frac);
153 using Variant = std::variant<None, MonofluidTVA, MonofluidComplete>;
157 inline void set_none() { current_mode = None{}; }
158 inline void set_monofluid_tva(
160 bool pure_diffusion_mode =
false,
161 Tscal C_1_fluid = 0.1,
163 Tscal cfl_density_threshold = shambase::get_epsilon<Tscal>(),
164 bool ensure_s_j_positivity =
true,
165 bool smooth_s_positivity_limiter =
false,
166 bool dust_corrected_av =
false,
167 std::optional<Tscal> clamp_dust_frac = std::nullopt) {
168 current_mode = MonofluidTVA{
173 cfl_density_threshold,
174 ensure_s_j_positivity,
175 smooth_s_positivity_limiter,
181 inline bool is_none() {
return std::holds_alternative<None>(current_mode); }
182 inline bool is_monofluid_tva() {
return bool(std::get_if<MonofluidTVA>(¤t_mode)); }
183 inline bool is_monofluid_complete() {
184 return bool(std::get_if<MonofluidComplete>(¤t_mode));
191 inline void mode_to_json(nlohmann::json &j)
const {
192 if (
const None *cfg = std::get_if<None>(¤t_mode)) {
193 j = {{
"type",
"none"}};
194 }
else if (
const MonofluidTVA *cfg = std::get_if<MonofluidTVA>(¤t_mode)) {
196 = {{
"type",
"monofluid_tva"},
197 {
"ndust", cfg->ndust},
198 {
"pure_diffusion_mode", cfg->pure_diffusion_mode},
199 {
"C_1_fluid", cfg->C_1_fluid},
200 {
"C_drift", cfg->C_drift},
201 {
"cfl_density_threshold", cfg->cfl_density_threshold},
202 {
"ensure_s_j_positivity", cfg->ensure_s_j_positivity},
203 {
"smooth_s_positivity_limiter", cfg->smooth_s_positivity_limiter},
204 {
"dust_corrected_av", cfg->dust_corrected_av},
205 {
"clamp_dust_frac", cfg->clamp_dust_frac}};
208 j = {{
"type",
"monofluid_complete"}, {
"ndust", cfg->ndust}};
214 inline void mode_from_json(
const nlohmann::json &j) {
215 const std::string type = j.at(
"type").get<std::string>();
216 if (type ==
"none") {
218 }
else if (type ==
"monofluid_tva") {
220 j.at(
"ndust").get<
u32>(),
221 j.at(
"pure_diffusion_mode").get<
bool>(),
222 j.at(
"C_1_fluid").get<Tscal>(),
223 j.at(
"C_drift").get<Tscal>(),
224 j.at(
"cfl_density_threshold").get<Tscal>(),
225 j.at(
"ensure_s_j_positivity").get<
bool>(),
226 j.value(
"smooth_s_positivity_limiter",
false),
227 j.value(
"dust_corrected_av",
false),
228 j.value(
"clamp_dust_frac", std::optional<Tscal>{}));
229 }
else if (type ==
"monofluid_complete") {
230 set_monofluid_complete(j.at(
"ndust").get<
u32>());
236 inline bool has_s_j_field() {
237 return is_monofluid_tva();
240 inline bool should_use_dust_av() {
241 if (!is_monofluid_tva()) {
244 return get_monofluid_tva().dust_corrected_av;
247 inline bool has_epsilon_field() {
248 return bool(std::get_if<MonofluidComplete>(¤t_mode));
251 inline bool has_deltav_field() {
252 return bool(std::get_if<MonofluidComplete>(¤t_mode));
255 inline u32 get_dust_nvar() {
256 if (
None *cfg = std::get_if<None>(¤t_mode)) {
258 "Querying a dust nvar with no dust as config is ... discutable ...");
260 }
else if (
MonofluidTVA *cfg = std::get_if<MonofluidTVA>(¤t_mode)) {
262 }
else if (
MonofluidComplete *cfg = std::get_if<MonofluidComplete>(¤t_mode)) {
271 std::vector<Tscal> stopping_times;
275 static constexpr bool supersonic_correction =
false;
277 std::vector<Tscal> grains_sizes;
278 std::vector<Tscal> grains_densities;
281 std::variant<None, ConstantStoppingTimes, EpsteinDrag> dust_drag_mode =
None{};
283 bool ballabio_ts_limiter =
false;
285 inline void drag_mode_to_json(nlohmann::json &j)
const {
286 if (std::holds_alternative<None>(dust_drag_mode)) {
287 j = {{
"type",
"none"}};
290 = std::get_if<ConstantStoppingTimes>(&dust_drag_mode)) {
291 j = {{
"type",
"constant_stopping_times"}, {
"stopping_times", cfg->stopping_times}};
292 }
else if (
const EpsteinDrag *cfg = std::get_if<EpsteinDrag>(&dust_drag_mode)) {
294 = {{
"type",
"epstein_drag"},
295 {
"gamma", cfg->gamma},
296 {
"grains_sizes", cfg->grains_sizes},
297 {
"grains_densities", cfg->grains_densities}};
303 inline void drag_mode_from_json(
const nlohmann::json &j) {
304 if (j.at(
"type").get<std::string>() ==
"none") {
305 dust_drag_mode =
None{};
306 }
else if (j.at(
"type").get<std::string>() ==
"constant_stopping_times") {
309 }
else if (j.at(
"type").get<std::string>() ==
"epstein_drag") {
311 j.at(
"gamma").get<Tscal>(),
312 j.at(
"grains_sizes").get<std::vector<Tscal>>(),
313 j.at(
"grains_densities").get<std::vector<Tscal>>()};
321 inline void set_drag_epstein(
EpsteinDrag in) { dust_drag_mode = std::move(in); }
323 std::variant<None, DustEvolCoalaCoag<Tscal>> dust_evol_config =
None{};
325 inline void evol_mode_to_json(nlohmann::json &j)
const {
329 j = {{
"type",
"none"}};
331 [&](
const DustEvolCoalaCoag<Tscal> &cfg) {
333 = {{
"type",
"coala_coag"},
334 {
"rhodust_eps", cfg.rhodust_eps},
335 {
"dv_max", cfg.dv_max},
336 {
"massgrid", cfg.massgrid},
337 {
"tabflux_coag", cfg.tabflux_coag}};
343 inline void evol_mode_from_json(
const nlohmann::json &j) {
344 if (j.at(
"type").get<std::string>() ==
"none") {
345 dust_evol_config =
None{};
346 }
else if (j.at(
"type").get<std::string>() ==
"coala_coag") {
347 dust_evol_config = DustEvolCoalaCoag<Tscal>{
348 .rhodust_eps = j.at(
"rhodust_eps").get<Tscal>(),
349 .dv_max = j.at(
"dv_max").get<Tscal>(),
350 .massgrid = j.at(
"massgrid").get<std::vector<Tscal>>(),
351 .tabflux_coag = j.at(
"tabflux_coag").get<std::vector<Tscal>>()};
357 inline void set_dust_evol_coala(DustEvolCoalaCoag<Tscal> cfg) { dust_evol_config = cfg; }
359 inline void check_config() {
360 bool is_not_none = !is_none();
365 "Dust config != None is experimental");
370 "Dust config != None is work in progress, use it at your own risk"));
373 if (std::holds_alternative<None>(dust_drag_mode)) {
375 "you must select a drag mode for the dust if the dust is on !");
378 = std::get_if<ConstantStoppingTimes>(&dust_drag_mode)) {
379 if (get_dust_nvar() != cfg->stopping_times.size()) {
381 "stopping_times size does not match the number of dust bins");
383 }
else if (
EpsteinDrag *cfg = std::get_if<EpsteinDrag>(&dust_drag_mode)) {
384 if (get_dust_nvar() != cfg->grains_densities.size()) {
386 "grains_densities size does not match the number of dust bins");
389 if (get_dust_nvar() != cfg->grains_sizes.size()) {
391 "grains_sizes size does not match the number of dust bins");
396 if (!std::holds_alternative<None>(dust_evol_config) && is_not_none) {
398 if (DustEvolCoalaCoag<Tscal> *cfg
399 = std::get_if<DustEvolCoalaCoag<Tscal>>(&dust_evol_config)) {
401 u32 ndust = get_dust_nvar();
403 if (cfg->massgrid.size() - 1 != ndust) {
405 "massgrid must have ndust + 1 = " + std::to_string(ndust + 1)
406 +
" entries for ndust = " + std::to_string(ndust) +
", got "
407 + std::to_string(cfg->massgrid.size()));
410 if (cfg->tabflux_coag.size() != ndust * ndust * ndust) {
412 "tabflux_coag must have ndust^3 = "
413 + std::to_string(ndust * ndust * ndust)
414 +
" entries for ndust = " + std::to_string(ndust) +
", got "
415 + std::to_string(cfg->tabflux_coag.size()));
418 if (cfg->rhodust_eps <= 0) {
420 "rhodust_eps must be positive, got "
421 + std::to_string(cfg->rhodust_eps));
424 if (cfg->dv_max <= 0) {
426 "dv_max must be positive, got " + std::to_string(cfg->dv_max));
433 }
else if (!std::holds_alternative<None>(dust_evol_config) && is_none()) {
435 "cannot enable dust evolution because the dust mode is 'none', call "
436 "set_dust_mode_* before set_dust_evol_coala");
444 u32 max_neigh_count = 500;
447 using mode = std::variant<DensityBased, DensityBasedNeighLim>;
451 void set_density_based() { config = DensityBased{}; }
452 void set_density_based_neigh_lim(
u32 max_neigh_count) {
453 config = DensityBasedNeighLim{max_neigh_count};
456 bool is_density_based_neigh_lim()
const {
457 return std::holds_alternative<DensityBasedNeighLim>(config);
483 bool reference_mode =
false;
488 using mode = std::variant<SFMM, FMM, MM, Direct, None>;
490 mode config =
None{};
492 void set_none() { config = None{}; }
493 void set_direct(
bool reference_mode =
false) { config = Direct{reference_mode}; }
494 void set_mm(
u32 mm_order,
f64 opening_angle,
u32 reduction_level) {
497 .opening_angle = opening_angle,
498 .reduction_level = reduction_level};
500 void set_fmm(
u32 order,
f64 opening_angle,
u32 reduction_level) {
502 .order = order, .opening_angle = opening_angle, .reduction_level = reduction_level};
504 void set_sfmm(
u32 order,
f64 opening_angle,
bool leaf_lowering,
u32 reduction_level) {
507 .opening_angle = opening_angle,
508 .leaf_lowering = leaf_lowering,
509 .reduction_level = reduction_level};
512 bool is_none()
const {
return std::holds_alternative<None>(config); }
513 bool is_direct()
const {
return std::holds_alternative<Direct>(config); }
514 bool is_mm()
const {
return std::holds_alternative<MM>(config); }
515 bool is_fmm()
const {
return std::holds_alternative<FMM>(config); }
516 bool is_sfmm()
const {
return std::holds_alternative<SFMM>(config); }
518 bool is_sg_on()
const {
return !is_none(); }
519 bool is_sg_off()
const {
return is_none(); }
525 using mode_soft = std::variant<SofteningPlummer>;
528 void set_softening_plummer(
f64 epsilon) { softening_mode = SofteningPlummer{epsilon}; }
529 void set_softening_none() { set_softening_plummer(0.); }
531 bool is_softening_plummer()
const {
532 return std::holds_alternative<SofteningPlummer>(softening_mode);
538template<
class Tvec,
template<
class>
class SPHKernel>
542 using Tscal = shambase::VecComponent<Tvec>;
544 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
557 bool track_particles_id =
false;
559 inline void set_particle_tracking(
bool state) { track_particles_id = state; }
568 std::optional<shamunits::UnitSystem<Tscal>>
unit_sys = {};
634 bool show_cfl_detail =
false;
650 mhd_config.set(Tmp{});
668 using DustConfig = DustConfig<Tscal>;
669 DustConfig dust_config = {};
679 SelfGravConfig self_grav_config = SelfGravConfig{};
709 "set_two_stage_search() is deprecated,\n"
710 " -> use set_neigh_cache_strategy(NeighCacheStrategy.TwoStage) or\n"
711 " set_neigh_cache_strategy(NeighCacheStrategy.SingleStage) instead"););
715 bool show_neigh_stats =
false;
716 inline void set_show_neigh_stats(
bool enable) { show_neigh_stats = enable; }
737 inline void set_smoothing_length_density_based() {
738 smoothing_length_config.set_density_based();
740 inline void set_smoothing_length_density_based_neigh_lim(
u32 max_neigh_count) {
741 smoothing_length_config.set_density_based_neigh_lim(max_neigh_count);
744 bool enable_particle_reordering =
false;
745 inline void set_enable_particle_reordering(
bool enable) { enable_particle_reordering = enable; }
746 u64 particle_reordering_step_freq = 1000;
747 inline void set_particle_reordering_step_freq(
u64 freq) {
750 "particle_reordering_step_freq cannot be zero");
752 particle_reordering_step_freq = freq;
755 bool save_dt_to_fields =
false;
756 inline void set_save_dt_to_fields(
bool enable) { save_dt_to_fields = enable; }
757 inline bool should_save_dt_to_fields()
const {
return save_dt_to_fields; }
759 bool show_ghost_zone_graph =
false;
760 inline void set_show_ghost_zone_graph(
bool enable) { show_ghost_zone_graph = enable; }
779 return bool(std::get_if<T>(&
eos_config.config));
785 return bool(std::get_if<T>(&
eos_config.config));
791 return bool(std::get_if<T>(&
eos_config.config));
797 return bool(std::get_if<T>(&
eos_config.config));
803 return bool(std::get_if<T>(&
eos_config.config));
841 eos_config.set_locally_isothermalLP07(cs0, q, r0);
852 eos_config.set_locally_isothermalFA2014(h_over_r);
866 eos_config.set_locally_isothermalFA2014_extended(cs0, q, r0, n_sinks);
904 using Tmp =
typename AVConfig::None;
1024 Tscal central_mass,
Tscal Racc, Tvec central_pos = Tvec{}) {
1048 Tscal central_mass,
Tscal Racc,
Tscal a_spin, Tvec dir_spin, Tvec central_pos = Tvec{}) {
1049 ext_force_config.add_lense_thirring(central_mass, Racc, a_spin, dir_spin, central_pos);
1082 this->do_debug_dump = _do_debug_dump;
1083 this->debug_dump_filename = _debug_dump_filename;
1145 inline void use_GW(
bool enable) {
1160 inline void check_config() {
1161 dust_config.check_config();
1163 if (track_particles_id &&
false ) {
1165 "particle injection is not yet compatible with particle id tracking");
1168 if (track_particles_id) {
1172 if (!self_grav_config.is_none()) {
1174 "Self gravity is experimental, please enable experimental features to use it");
1178 void set_layout(shamrock::patch::PatchDataLayerLayout &pdl);
1179 void set_ghost_layout(shamrock::patch::PatchDataLayerLayout &ghost_layout);
1190 template<
class Tscal>
1193 {
"cfl_cour", p.cfl_cour},
1194 {
"cfl_force", p.cfl_force},
1195 {
"cfl_multiplier_stiffness", p.cfl_multiplier_stiffness},
1196 {
"eta_sink", p.eta_sink}};
1205 template<
class Tscal>
1207 j.at(
"cfl_cour").get_to<Tscal>(p.cfl_cour);
1208 j.at(
"cfl_force").get_to<Tscal>(p.cfl_force);
1209 j.at(
"cfl_multiplier_stiffness").get_to<Tscal>(p.cfl_multiplier_stiffness);
1211 if (j.contains(
"eta_sink")) {
1212 j.at(
"eta_sink").get_to<Tscal>(p.eta_sink);
1216 "SPHConfig",
"eta_sink not found when deserializing, defaulting to", p.eta_sink));
1221 template<
class Tvec>
1222 inline void to_json(nlohmann::json &j,
const ParticleKillingConfig<Tvec> &p) {
1223 j = nlohmann::json::array();
1224 for (
const auto &kill : p.kill_list) {
1225 if (std::holds_alternative<
typename ParticleKillingConfig<Tvec>::Sphere>(kill)) {
1226 const auto &sphere = std::get<typename ParticleKillingConfig<Tvec>::Sphere>(kill);
1228 {{
"type",
"sphere"}, {
"center", sphere.center}, {
"radius", sphere.radius}});
1234 template<
class Tvec>
1236 p.kill_list.clear();
1237 for (
const auto &item : j) {
1238 std::string type = item.at(
"type").get<std::string>();
1239 if (type ==
"sphere") {
1241 item.at(
"center").get_to(sphere.center);
1242 item.at(
"radius").get_to(sphere.radius);
1243 p.kill_list.push_back(sphere);
1252 = std::get_if<SmoothingLengthConfig::DensityBased>(&p.config)) {
1254 {
"type",
"density_based"},
1259 = std::get_if<SmoothingLengthConfig::DensityBasedNeighLim>(&p.config)) {
1262 {
"type",
"density_based_neigh_lim"},
1263 {
"max_neigh_count", conf->max_neigh_count},
1271 if (j.at(
"type").get<std::string>() ==
"density_based") {
1273 }
else if (j.at(
"type").get<std::string>() ==
"density_based_neigh_lim") {
1286 {
"order", conf->order},
1287 {
"opening_angle", conf->opening_angle},
1288 {
"reduction_level", conf->reduction_level},
1289 {
"leaf_lowering", conf->leaf_lowering},
1291 }
else if (
const SelfGravConfig::FMM *conf = std::get_if<SelfGravConfig::FMM>(&p.config)) {
1294 {
"order", conf->order},
1295 {
"opening_angle", conf->opening_angle},
1296 {
"reduction_level", conf->reduction_level},
1298 }
else if (
const SelfGravConfig::MM *conf = std::get_if<SelfGravConfig::MM>(&p.config)) {
1301 {
"order", conf->order},
1302 {
"opening_angle", conf->opening_angle},
1303 {
"reduction_level", conf->reduction_level},
1309 {
"reference_mode", conf->reference_mode},
1319 = std::get_if<SelfGravConfig::SofteningPlummer>(&p.softening_mode)) {
1320 j[
"softening_mode"] =
"plummer";
1321 j[
"softening_length"] = conf->epsilon;
1329 if (j.at(
"type").get<std::string>() ==
"sfmm") {
1331 .order = j.at(
"order").get<
u32>(),
1332 .opening_angle = j.at(
"opening_angle").get<
f64>(),
1333 .leaf_lowering = j.at(
"leaf_lowering").get<
bool>(),
1334 .reduction_level = j.at(
"reduction_level").get<
u32>()};
1335 }
else if (j.at(
"type").get<std::string>() ==
"fmm") {
1337 .order = j.at(
"order").get<
u32>(),
1338 .opening_angle = j.at(
"opening_angle").get<
f64>(),
1339 .reduction_level = j.at(
"reduction_level").get<
u32>()};
1340 }
else if (j.at(
"type").get<std::string>() ==
"mm") {
1342 .order = j.at(
"order").get<
u32>(),
1343 .opening_angle = j.at(
"opening_angle").get<
f64>(),
1344 .reduction_level = j.at(
"reduction_level").get<
u32>()};
1345 }
else if (j.at(
"type").get<std::string>() ==
"direct") {
1347 }
else if (j.at(
"type").get<std::string>() ==
"none") {
1351 "Invalid self gravity type: " + j.at(
"type").get<std::string>());
1354 if (j.contains(
"softening_mode")) {
1355 std::string softening_mode = j.at(
"softening_mode").get<std::string>();
1356 if (softening_mode ==
"plummer") {
1361 "Invalid softening mode: " + softening_mode);
1367 template<
class Tvec>
1368 inline void to_json(nlohmann::json &j,
const DustConfig<Tvec> &p) {
1371 p.mode_to_json(j[
"mode"]);
1372 p.drag_mode_to_json(j[
"drag_mode"]);
1373 p.evol_mode_to_json(j[
"evol_mode"]);
1374 j[
"ballabio_ts_limiter"] = p.ballabio_ts_limiter;
1377 template<
class Tvec>
1379 p.mode_from_json(j.at(
"mode"));
1380 p.drag_mode_from_json(j.at(
"drag_mode"));
1381 if (j.contains(
"evol_mode")) {
1382 p.evol_mode_from_json(j.at(
"evol_mode"));
1384 p.ballabio_ts_limiter = j.value(
"ballabio_ts_limiter",
false);
1393 template<
class Tvec,
template<
class>
class SPHKernel>
1396 using Tkernel =
typename T::Kernel;
1398 std::string kernel_id = shambase::get_type_name<Tkernel>();
1399 std::string type_id = shambase::get_type_name<Tvec>();
1403 {
"kernel_id", kernel_id},
1404 {
"type_id", type_id},
1406 {
"scheduler_config", p.scheduler_conf},
1408 {
"gpart_mass", p.gpart_mass},
1409 {
"cfl_config", p.cfl_config},
1410 {
"unit_sys", p.unit_sys},
1411 {
"show_cfl_detail", p.show_cfl_detail},
1413 {
"mhd_config", p.mhd_config},
1415 {
"dust_config", p.dust_config},
1417 {
"self_grav_config", p.self_grav_config},
1419 {
"tree_reduction_level", p.tree_reduction_level},
1421 {
"show_neigh_stats", p.show_neigh_stats},
1423 {
"combined_dtdiv_divcurlv_compute", p.combined_dtdiv_divcurlv_compute},
1424 {
"htol_up_coarse_cycle", p.htol_up_coarse_cycle},
1425 {
"htol_up_fine_cycle", p.htol_up_fine_cycle},
1426 {
"epsilon_h", p.epsilon_h},
1427 {
"smoothing_length_config", p.smoothing_length_config},
1428 {
"h_iter_per_subcycles", p.h_iter_per_subcycles},
1429 {
"h_max_subcycles_count", p.h_max_subcycles_count},
1431 {
"enable_particle_reordering", p.enable_particle_reordering},
1432 {
"particle_reordering_step_freq", p.particle_reordering_step_freq},
1434 {
"save_dt_to_fields", p.save_dt_to_fields},
1435 {
"show_ghost_zone_graph", p.show_ghost_zone_graph},
1437 {
"eos_config", p.eos_config},
1439 {
"artif_viscosity", p.artif_viscosity},
1440 {
"boundary_config", p.boundary_config},
1441 {
"ext_force_config", p.ext_force_config},
1443 {
"do_debug_dump", p.do_debug_dump},
1444 {
"debug_dump_filename", p.debug_dump_filename},
1446 {
"particle_killing", p.particle_killing},
1456 template<
class Tvec,
template<
class>
class SPHKernel>
1459 using Tkernel =
typename T::Kernel;
1462 if (j.contains(
"kernel_id")) {
1464 std::string kernel_id = j.at(
"kernel_id").get<std::string>();
1466 if (kernel_id != shambase::get_type_name<Tkernel>()) {
1468 "Invalid type to deserialize, wanted " + shambase::get_type_name<Tvec>()
1469 +
" but got " + kernel_id);
1473 if (j.contains(
"type_id")) {
1475 std::string type_id = j.at(
"type_id").get<std::string>();
1477 if (type_id != shambase::get_type_name<Tvec>()) {
1479 "Invalid type to deserialize, wanted " + shambase::get_type_name<Tvec>()
1480 +
" but got " + type_id);
1484 bool has_used_defaults =
false;
1485 bool has_updated_config =
false;
1487 auto _get_to_if_contains = [&](
const std::string &key,
auto &value) {
1491 auto _get_to_if_contains_fallbacks = [&](
const std::string &key,
1493 std::initializer_list<const char *> fallbacks) {
1495 j, key, value, fallbacks, has_used_defaults, has_updated_config);
1498 _get_to_if_contains(
"scheduler_config", p.scheduler_conf);
1501 _get_to_if_contains(
"gpart_mass", p.gpart_mass);
1502 _get_to_if_contains(
"cfl_config", p.cfl_config);
1503 _get_to_if_contains(
"unit_sys", p.unit_sys);
1504 _get_to_if_contains(
"show_cfl_detail", p.show_cfl_detail);
1505 _get_to_if_contains(
"mhd_config", p.mhd_config);
1506 _get_to_if_contains(
"dust_config", p.dust_config);
1507 _get_to_if_contains(
"self_grav_config", p.self_grav_config);
1508 _get_to_if_contains(
"tree_reduction_level", p.tree_reduction_level);
1511 j, p.neigh_cache_strategy,
"SPH::SolverConfig", has_used_defaults, has_updated_config);
1512 _get_to_if_contains(
"show_neigh_stats", p.show_neigh_stats);
1513 _get_to_if_contains(
"combined_dtdiv_divcurlv_compute", p.combined_dtdiv_divcurlv_compute);
1516 _get_to_if_contains_fallbacks(
1517 "htol_up_coarse_cycle", p.htol_up_coarse_cycle, {
"htol_up_tol"});
1518 _get_to_if_contains_fallbacks(
"htol_up_fine_cycle", p.htol_up_fine_cycle, {
"htol_up_iter"});
1520 _get_to_if_contains(
"epsilon_h", p.epsilon_h);
1521 _get_to_if_contains(
"smoothing_length_config", p.smoothing_length_config);
1522 _get_to_if_contains(
"h_iter_per_subcycles", p.h_iter_per_subcycles);
1523 _get_to_if_contains(
"h_max_subcycles_count", p.h_max_subcycles_count);
1524 _get_to_if_contains(
"enable_particle_reordering", p.enable_particle_reordering);
1525 _get_to_if_contains(
"particle_reordering_step_freq", p.particle_reordering_step_freq);
1526 _get_to_if_contains(
"save_dt_to_fields", p.save_dt_to_fields);
1527 _get_to_if_contains(
"show_ghost_zone_graph", p.show_ghost_zone_graph);
1528 _get_to_if_contains(
"eos_config", p.eos_config);
1529 _get_to_if_contains(
"artif_viscosity", p.artif_viscosity);
1530 _get_to_if_contains(
"boundary_config", p.boundary_config);
1531 _get_to_if_contains(
"ext_force_config", p.ext_force_config);
1532 _get_to_if_contains(
"do_debug_dump", p.do_debug_dump);
1533 _get_to_if_contains(
"debug_dump_filename", p.debug_dump_filename);
1534 _get_to_if_contains(
"particle_killing", p.particle_killing);
1536 if (has_used_defaults || has_updated_config) {
1539 "SPH::SolverConfig",
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
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
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.
The configuration for the CFL condition.
Tscal eta_sink
eta sink to control the sink integrator
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).
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.
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.
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_field_dtdivB()
Whether the solver has a field for dt divB.
bool has_axyz_in_ghost()
Whether the solver has a field for ax, ay, az in ghost cells.
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.
bool has_field_divB()
Whether the solver has a field for divB.
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.
bool has_field_curlB()
Whether the solver has a field for curlB.
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...
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_IdealMHD(typename MHDConfig::IdealMHD_constrained_hyper_para v)
Enable the ideal MHD hydro solver.
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.
bool has_field_B_on_rho()
Whether the solver has a field for B_on_rho.
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.
EOSConfig eos_config
EOS configuration.
shammodels::EOSConfig< Tvec > EOSConfig
Alias to EOSConfig type.
bool has_field_soundspeed()
Whether the solver has a field for sound speed.
void set_noMHD()
disable MHD in the SPH solver
ExtForceConfig ext_force_config
External force configuration.
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.
constexpr T c()
get c in the current unit system units (m.s-1)
constexpr T G()
get the value of G in the current unit system units
constexpr T mu_0()
get the value of mu_0 in the current unit system units
Functions related to the MPI communicator.
#define ON_RANK_0(x)
Macro to execute code only on rank 0.