Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SolverConfig.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
20
23#include "config/AVConfig.hpp"
24#include "config/BCConfig.hpp"
26#include "shambackends/math.hpp"
29#include "shambackends/vec.hpp"
49#include <stdexcept>
50#include <variant>
51#include <vector>
52
53namespace shammodels::sph {
54
61 template<class Tvec, template<class> class SPHKernel>
62 struct SolverConfig;
63
69 template<class Tscal>
70 struct CFLConfig {
71
75 Tscal cfl_cour = 0.3;
76
80 Tscal cfl_force = 0.25;
81
85 Tscal cfl_NIMHD = 1. / (2 * shambase::constants::pi<Tscal>); // as in phantom
86
91
93 Tscal eta_sink = 0.05;
94 };
95
96 template<class Tvec>
98 using Tscal = shambase::VecComponent<Tvec>;
99 struct Sphere {
100 Tvec center;
101 Tscal radius;
102 };
103
104 using kill_t = std::variant<Sphere>;
105
106 std::vector<kill_t> kill_list;
107
108 inline void add_kill_sphere(const Tvec &center, Tscal radius) {
109 kill_list.push_back(Sphere{center, radius});
110 }
111 };
112
113 template<class Tscal>
115 Tscal rhodust_eps;
116
120 Tscal tau_frac;
121
126 std::vector<Tscal> massgrid;
127 std::vector<Tscal> tabflux_coag;
128 };
129
130 template<class Tscal>
131 struct DustConfig {
132
133 struct None {};
134
136 u32 ndust;
137 bool pure_diffusion_mode = false;
138
139 Tscal C_1_fluid = 0.1;
140 Tscal C_drift = 1.0;
141 Tscal cfl_density_threshold = shambase::get_epsilon<Tscal>();
142
143 bool ensure_s_j_positivity = true;
144
145 bool smooth_s_positivity_limiter = false;
146
147 // use the corrected q_AV from Hutchison 2018 & Price Laibe 15
148 bool dust_corrected_av = false;
149
150 // Fraction of rho(h) that the dust density (per-species and summed) is clamped to.
151 // The clamp runs only when this is set.
152 std::optional<Tscal> clamp_dust_frac = std::nullopt;
153
154 static constexpr Tscal default_clamp_dust_frac = 0.99;
155
156 inline bool should_clamp_dust_density() const { return clamp_dust_frac.has_value(); }
157
158 inline Tscal get_clamp_dust_frac() const {
159 return clamp_dust_frac.value_or(default_clamp_dust_frac);
160 }
161
162 // Symmetrized per-pair (upwind) positivity gate on the TVA flux: the flux of a pair is
163 // switched off when its upwind (donor) particle has s_j < 0.
164 // With smooth_s_positivity_limiter it replaces the per-particle xi switch (which breaks
165 // dust mass conservation when s_j < 0), only the restoring term phi being kept.
166 bool pair_gate_s_positivity_limiter = false;
167 };
168
170 u32 ndust;
171 };
172
174 using Variant = std::variant<None, MonofluidTVA, MonofluidComplete>;
175
176 Variant current_mode = None{};
177
178 inline void set_none() { current_mode = None{}; }
179 inline void set_monofluid_tva(
180 u32 nvar,
181 bool pure_diffusion_mode = false,
182 Tscal C_1_fluid = 0.1,
183 Tscal C_drift = 1.0,
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{
191 nvar,
192 pure_diffusion_mode,
193 C_1_fluid,
194 C_drift,
195 cfl_density_threshold,
196 ensure_s_j_positivity,
197 smooth_s_positivity_limiter,
198 dust_corrected_av,
199 clamp_dust_frac,
200 pair_gate_s_positivity_limiter};
201 }
202 inline void set_monofluid_complete(u32 nvar) { current_mode = MonofluidComplete{nvar}; }
203
204 inline bool is_none() { return std::holds_alternative<None>(current_mode); }
205 inline bool is_monofluid_tva() { return bool(std::get_if<MonofluidTVA>(&current_mode)); }
206 inline bool is_monofluid_complete() {
207 return bool(std::get_if<MonofluidComplete>(&current_mode));
208 }
209
210 inline MonofluidTVA &get_monofluid_tva() {
211 return shambase::get_check_ref(std::get_if<MonofluidTVA>(&current_mode));
212 }
213
214 inline void mode_to_json(nlohmann::json &j) const {
215 if (const None *cfg = std::get_if<None>(&current_mode)) {
216 j = {{"type", "none"}};
217 } else if (const MonofluidTVA *cfg = std::get_if<MonofluidTVA>(&current_mode)) {
218 j
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}};
230 } else if (
231 const MonofluidComplete *cfg = std::get_if<MonofluidComplete>(&current_mode)) {
232 j = {{"type", "monofluid_complete"}, {"ndust", cfg->ndust}};
233 } else {
235 }
236 }
237
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") {
241 set_none();
242 } else if (type == "monofluid_tva") {
243 set_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>());
256 } else {
258 }
259 }
260
261 inline bool has_s_j_field() {
262 return is_monofluid_tva(); // S_j = sqrt(\rho \epsilon_j)
263 }
264
265 inline bool should_use_dust_av() {
266 if (!is_monofluid_tva()) {
267 return false;
268 }
269 return get_monofluid_tva().dust_corrected_av;
270 }
271
272 inline bool has_epsilon_field() {
273 return bool(std::get_if<MonofluidComplete>(&current_mode));
274 }
275
276 inline bool has_deltav_field() {
277 return bool(std::get_if<MonofluidComplete>(&current_mode));
278 }
279
280 inline u32 get_dust_nvar() {
281 if (None *cfg = std::get_if<None>(&current_mode)) {
283 "Querying a dust nvar with no dust as config is ... discutable ...");
284 return 0;
285 } else if (MonofluidTVA *cfg = std::get_if<MonofluidTVA>(&current_mode)) {
286 return cfg->ndust;
287 } else if (MonofluidComplete *cfg = std::get_if<MonofluidComplete>(&current_mode)) {
288 return cfg->ndust;
289 } else {
290 shambase::throw_unimplemented("How did you get here ???");
291 }
292 return 0;
293 }
294
296 std::vector<Tscal> stopping_times;
297 };
298
299 struct EpsteinDrag {
300 static constexpr bool supersonic_correction = false;
301 Tscal gamma;
302 std::vector<Tscal> grains_sizes;
303 std::vector<Tscal> grains_densities;
304 };
305
306 std::variant<None, ConstantStoppingTimes, EpsteinDrag> dust_drag_mode = None{};
307
308 bool ballabio_ts_limiter = false;
309
310 inline void drag_mode_to_json(nlohmann::json &j) const {
311 if (std::holds_alternative<None>(dust_drag_mode)) {
312 j = {{"type", "none"}};
313 } else if (
314 const ConstantStoppingTimes *cfg
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)) {
318 j
319 = {{"type", "epstein_drag"},
320 {"gamma", cfg->gamma},
321 {"grains_sizes", cfg->grains_sizes},
322 {"grains_densities", cfg->grains_densities}};
323 } else {
325 }
326 }
327
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") {
332 dust_drag_mode
333 = ConstantStoppingTimes{j.at("stopping_times").get<std::vector<Tscal>>()};
334 } else if (j.at("type").get<std::string>() == "epstein_drag") {
335 dust_drag_mode = EpsteinDrag{
336 j.at("gamma").get<Tscal>(),
337 j.at("grains_sizes").get<std::vector<Tscal>>(),
338 j.at("grains_densities").get<std::vector<Tscal>>()};
339 } else {
341 }
342 }
343
344 inline void set_drag_constant(ConstantStoppingTimes in) { dust_drag_mode = std::move(in); }
345
346 inline void set_drag_epstein(EpsteinDrag in) { dust_drag_mode = std::move(in); }
347
348 std::variant<None, DustEvolCoalaCoag<Tscal>> dust_evol_config = None{};
349
350 inline void evol_mode_to_json(nlohmann::json &j) const {
351 std::visit(
353 [&](const None &) {
354 j = {{"type", "none"}};
355 },
356 [&](const DustEvolCoalaCoag<Tscal> &cfg) {
357 j
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}};
364 },
365 },
366 dust_evol_config);
367 }
368
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>(),
375 // older dumps predate tau_frac, use the python default
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>>()};
380 } else {
382 }
383 }
384
385 inline void set_dust_evol_coala(DustEvolCoalaCoag<Tscal> cfg) { dust_evol_config = cfg; }
386
387 inline void check_config() {
388 bool is_not_none = !is_none();
389 if (is_not_none) {
390
393 "Dust config != None is experimental");
394 } else {
395 ON_RANK_0(
396 logger::warn_ln(
397 "SPH::config",
398 "Dust config != None is work in progress, use it at your own risk"));
399 }
400
401 if (std::holds_alternative<None>(dust_drag_mode)) {
403 "you must select a drag mode for the dust if the dust is on !");
404 } else if (
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");
410 }
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");
415 }
416
417 if (get_dust_nvar() != cfg->grains_sizes.size()) {
419 "grains_sizes size does not match the number of dust bins");
420 }
421 }
422 }
423
424 if (!std::holds_alternative<None>(dust_evol_config) && is_not_none) {
425
426 if (DustEvolCoalaCoag<Tscal> *cfg
427 = std::get_if<DustEvolCoalaCoag<Tscal>>(&dust_evol_config)) {
428
429 u32 ndust = get_dust_nvar();
430
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()));
436 }
437
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()));
444 }
445
446 if (cfg->rhodust_eps <= 0) {
448 "rhodust_eps must be positive, got "
449 + std::to_string(cfg->rhodust_eps));
450 }
451
452 if (!(cfg->tau_frac > 0)) {
454 "tau_frac must be positive, got " + std::to_string(cfg->tau_frac));
455 }
456
457 if (cfg->vfrag_threshold <= 0) {
459 "vfrag_threshold must be positive, got "
460 + std::to_string(cfg->vfrag_threshold));
461 }
462
463 } else {
465 }
466
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");
471 }
472 }
473 };
474
476 struct DensityBased {};
478 u32 max_neigh_count = 500;
479 };
481
482 using mode = std::variant<DensityBased, DensityBasedNeighLim, DensityBasedBisectingNR>;
483
484 mode config = DensityBased{};
485
486 void set_density_based() { config = DensityBased{}; }
487 void set_density_based_neigh_lim(u32 max_neigh_count) {
488 config = DensityBasedNeighLim{max_neigh_count};
489 }
490 void set_density_based_bisecting_nr() { config = DensityBasedBisectingNR{}; }
491
492 bool is_density_based_neigh_lim() const {
493 return std::holds_alternative<DensityBasedNeighLim>(config);
494 }
495 bool is_density_based_bisecting_nr() const {
496 return std::holds_alternative<DensityBasedBisectingNR>(config);
497 }
498 };
499
501
502 struct SFMM {
503 u32 order;
504 f64 opening_angle;
505 bool leaf_lowering;
506 u32 reduction_level;
507 };
508
509 struct FMM {
510 u32 order;
511 f64 opening_angle;
512 u32 reduction_level;
513 };
514
515 struct MM {
516 u32 order;
517 f64 opening_angle;
518 u32 reduction_level;
519 };
520
521 struct Direct {
522 bool reference_mode = false;
523 };
524
525 struct None {};
526
527 using mode = std::variant<SFMM, FMM, MM, Direct, None>;
528
529 mode config = None{};
530
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) {
534 config = MM{
535 .order = mm_order,
536 .opening_angle = opening_angle,
537 .reduction_level = reduction_level};
538 }
539 void set_fmm(u32 order, f64 opening_angle, u32 reduction_level) {
540 config = FMM{
541 .order = order, .opening_angle = opening_angle, .reduction_level = reduction_level};
542 }
543 void set_sfmm(u32 order, f64 opening_angle, bool leaf_lowering, u32 reduction_level) {
544 config = SFMM{
545 .order = order,
546 .opening_angle = opening_angle,
547 .leaf_lowering = leaf_lowering,
548 .reduction_level = reduction_level};
549 }
550
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); }
556
557 bool is_sg_on() const { return !is_none(); }
558 bool is_sg_off() const { return is_none(); }
559
561 f64 epsilon;
562 };
563
564 using mode_soft = std::variant<SofteningPlummer>;
565 mode_soft softening_mode = SofteningPlummer{1e-9};
566
567 void set_softening_plummer(f64 epsilon) { softening_mode = SofteningPlummer{epsilon}; }
568 void set_softening_none() { set_softening_plummer(0.); }
569
570 bool is_softening_plummer() const {
571 return std::holds_alternative<SofteningPlummer>(softening_mode);
572 }
573 };
574
575} // namespace shammodels::sph
576
577template<class Tvec, template<class> class SPHKernel>
579
581 using Tscal = shambase::VecComponent<Tvec>;
583 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
585 using Kernel = SPHKernel<Tscal>;
587 using u_morton = u32;
588
590
592 static constexpr Tscal Rkern = Kernel::Rkern;
593
595
596 bool track_particles_id = false;
597
598 inline void set_particle_tracking(bool state) { track_particles_id = state; }
599
602 inline void set_filter_empty_patch_gz(bool state) { filter_empty_patch_gz = state; }
603
604 inline bool has_filter_empty_patch_gz() { return filter_empty_patch_gz; }
605
606 PatchSchedulerConfig scheduler_conf = {};
607
609 // Units Config
611
613 std::optional<shamunits::UnitSystem<Tscal>> unit_sys = {};
614
616 inline void set_units(shamunits::UnitSystem<Tscal> new_sys) { unit_sys = new_sys; }
617
620 if (!unit_sys) {
621 ON_RANK_0(logger::warn_ln("sph::Config", "the unit system is not set"));
623 } else {
624 return *unit_sys;
625 }
626 }
627
629 inline Tscal get_constant_G() { return get_unit_sys().template get<shamunits::constants::G>(); }
630
632 inline Tscal get_constant_c() { return get_unit_sys().template get<shamunits::constants::c>(); }
633
636 return get_unit_sys().template get<shamunits::constants::mu_0>();
637 }
638
640 // Units Config (END)
642
644 // Particle killing config
646
647 ParticleKillingConfig<Tvec> particle_killing;
648
650 // Particle killing config (END)
652
654 // CFL Configuration (config)
656
658
660 inline void set_cfl_mult_stiffness(Tscal cstiff) {
661 cfl_config.cfl_multiplier_stiffness = cstiff;
662 }
663
665 inline Tscal get_cfl_mult_stiffness() { return cfl_config.cfl_multiplier_stiffness; }
666
667 bool show_cfl_detail = false;
668
670 // CFL Configuration (END)
672
674 // MHD Config
676
678 MHDConfig mhd_config = {};
679
681 inline void set_noMHD() {
682 using Tmp = typename MHDConfig::None;
683 mhd_config.set(Tmp{});
684 }
685
688 mhd_config.set(v);
689 }
690
691 inline void set_non_ideal_mhd(typename MHDConfig::NonIdealMHD v) {
692 logger::raw_ln("$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$");
693 logger::raw_ln(" ______ _______ __ _ _______ _______ ______ ");
694 logger::raw_ln("| | | _ || | | || || || _ | ");
695 logger::raw_ln("| _ || |_| || |_| || ___|| ___|| | ||");
696 logger::raw_ln("| | | || || || | __ | |___ | |_||_");
697 logger::raw_ln("| |_| || || _ || || || ___|| __ |");
698 logger::raw_ln("| || _ || | | || |_| || |___ | | | |");
699 logger::raw_ln("|______| |__| |__||_| |__||_______||_______||___| |_|");
700 logger::raw_ln("$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$DANGER$");
701 logger::raw_ln("The Non-ideal MHD solver is UNDER DEVELOPMENT.");
702 logger::raw_ln("It is. NOT. FULLY. TESTED. YET.");
703 logger::raw_ln("Use at your own risk.");
705 "Non-ideal MHD is experimental, please enable experimental features to use it");
706 mhd_config.set(v);
707 }
708
710 // MHD Config (END)
712
714 // Dust config
716
717 using DustConfig = DustConfig<Tscal>;
718 DustConfig dust_config = {};
719
721 // Dust config (END)
723
725 // Self gravity config
727
728 SelfGravConfig self_grav_config = SelfGravConfig{};
729
731 // Self gravity config (END)
733
735 // Tree config
737
739
742
744 inline void set_tree_reduction_level(u32 level) { tree_reduction_level = level; }
745
748 neigh_cache_strategy = strategy;
749 }
750
755 inline void set_two_stage_search(bool enable) {
756 ON_RANK_0(shamlog_warn_ln(
757 "SPH::SolverConfig",
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"););
762 }
763
764 bool show_neigh_stats = false;
765 inline void set_show_neigh_stats(bool enable) { show_neigh_stats = enable; }
767 // Tree config (END)
769
771 // Solver behavior config
773
783
784 SmoothingLengthConfig smoothing_length_config;
785
786 inline void set_smoothing_length_density_based() {
787 smoothing_length_config.set_density_based();
788 }
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);
791 }
792 inline void set_smoothing_length_density_based_bisecting_nr() {
793 smoothing_length_config.set_density_based_bisecting_nr();
794 }
795
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) {
800 if (freq == 0) {
802 "particle_reordering_step_freq cannot be zero");
803 }
804 particle_reordering_step_freq = freq;
805 }
806
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; }
810
811 bool show_ghost_zone_graph = false;
812 inline void set_show_ghost_zone_graph(bool enable) { show_ghost_zone_graph = enable; }
813
815 bool show_ghost_stats = false;
816 inline void set_show_ghost_stats(bool enable) { show_ghost_stats = enable; }
817
819 // Solver behavior config (END)
821
823 // EOS Config
825
828
831
834 using T = typename EOSConfig::LocallyIsothermal;
835 return bool(std::get_if<T>(&eos_config.config));
836 }
837
839 inline bool is_eos_adiabatic() {
840 using T = typename EOSConfig::Adiabatic;
841 return bool(std::get_if<T>(&eos_config.config));
842 }
843
845 inline bool is_eos_polytropic() {
846 using T = typename EOSConfig::Polytropic;
847 return bool(std::get_if<T>(&eos_config.config));
848 }
849
851 inline bool is_eos_isothermal() {
852 using T = typename EOSConfig::Isothermal;
853 return bool(std::get_if<T>(&eos_config.config));
854 }
855
857 inline bool is_eos_fermi() {
858 using T = typename EOSConfig::Fermi;
859 return bool(std::get_if<T>(&eos_config.config));
860 }
861
863 inline bool is_eos_barotropic() {
864 using T = typename EOSConfig::Barotropic;
865 return bool(std::get_if<T>(&eos_config.config));
866 }
867
873 inline void set_eos_isothermal(Tscal cs) { eos_config.set_isothermal(cs); }
874
880 inline void set_eos_adiabatic(Tscal gamma) { eos_config.set_adiabatic(gamma); }
881
887 inline void set_eos_polytropic(Tscal K, Tscal gamma) { eos_config.set_polytropic(K, gamma); }
888
892 inline void set_eos_locally_isothermal() { eos_config.set_locally_isothermal(); }
893
903 eos_config.set_locally_isothermalLP07(cs0, q, r0);
904 }
905
914 eos_config.set_locally_isothermalFA2014(h_over_r);
915 }
916
927 Tscal cs0, Tscal q, Tscal r0, u32 n_sinks) {
928 eos_config.set_locally_isothermalFA2014_extended(cs0, q, r0, n_sinks);
929 }
930
936 inline void set_eos_fermi(Tscal mu_e) { eos_config.set_fermi(mu_e); }
937
948 inline void set_eos_barotropic(Tscal cs0, Tscal rho0, Tscal gamma0) {
949 eos_config.set_barotropic(cs0, rho0, gamma0);
950 }
951
953 // EOS Config (END)
955
957 // Artificial viscosity Config
959
972
975
980 using Tmp = typename AVConfig::None;
981 artif_viscosity.set(Tmp{});
982 }
983
989 inline void set_artif_viscosity_Constant(typename AVConfig::Constant v) {
990 artif_viscosity.set(v);
991 }
992
999 inline void set_artif_viscosity_VaryingMM97(typename AVConfig::VaryingMM97 v) {
1000 artif_viscosity.set(v);
1001 }
1002
1009 inline void set_artif_viscosity_VaryingCD10(typename AVConfig::VaryingCD10 v) {
1010 artif_viscosity.set(v);
1011 }
1012
1017 inline void set_artif_viscosity_ConstantDisc(typename AVConfig::ConstantDisc v) {
1018 artif_viscosity.set(v);
1019 }
1020
1022 // Artificial viscosity Config (END)
1024
1026 // Boundary Config
1028
1033
1040
1044 inline void set_boundary_free() { boundary_config.set_free(); }
1045
1049 inline void set_boundary_periodic() { boundary_config.set_periodic(); }
1050
1062 inline void set_boundary_shearing_periodic(i32_3 shear_base, i32_3 shear_dir, Tscal speed) {
1063 boundary_config.set_shearing_periodic(shear_base, shear_dir, speed);
1064 }
1065
1067 // Boundary Config (END)
1069
1071 // Ext force Config
1073
1086
1091
1100 Tscal central_mass, Tscal Racc, Tvec central_pos = Tvec{}) {
1101 ext_force_config.add_point_mass(central_mass, Racc, central_pos);
1102 }
1103
1110 inline void add_ext_force_paczynski_wiita(Tscal central_mass, Tvec central_pos, Tscal Racc) {
1111 ext_force_config.add_paczynski_wiita(central_mass, central_pos, Racc);
1112 }
1113
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);
1126 }
1127
1135 inline void add_ext_force_shearing_box(Tscal Omega_0, Tscal eta, Tscal q) {
1136 ext_force_config.add_shearing_box(Omega_0, eta, q);
1137 }
1138
1140 // Ext force Config (END)
1142
1144 // Debug dump config
1146
1148 bool do_debug_dump = false;
1149
1151 std::string debug_dump_filename = "";
1152
1157 inline void set_debug_dump(bool _do_debug_dump, std::string _debug_dump_filename) {
1158 this->do_debug_dump = _do_debug_dump;
1159 this->debug_dump_filename = _debug_dump_filename;
1160 }
1161
1163 inline constexpr bool do_MHD_debug() { return false; }
1164
1166 // Debug dump config (END)
1168
1171
1178 inline bool has_field_uint() { return true; }
1179
1181 inline bool has_field_alphaAV() { return artif_viscosity.has_alphaAV_field(); }
1182
1184 inline bool has_field_divv() { return artif_viscosity.has_alphaAV_field(); }
1185
1187 inline bool has_field_dtdivv() { return artif_viscosity.has_dtdivv_field(); }
1188
1190 inline bool has_field_curlv() { return artif_viscosity.has_curlv_field() && (dim == 3); }
1191
1193 inline bool has_axyz_in_ghost() { return has_field_dtdivv(); }
1194
1196 inline bool has_field_soundspeed() {
1197 return artif_viscosity.has_field_soundspeed() || is_eos_locally_isothermal();
1198 }
1199
1201 inline bool do_nimhd() { return mhd_config.do_nimhd(); }
1202
1204 inline bool has_field_b_on_rho() { return mhd_config.has_b_field() && (dim == 3); }
1205
1207 inline bool has_field_psi_on_ch() { return mhd_config.has_psi_field(); }
1208
1210 inline bool has_field_div_b() { return mhd_config.has_div_b_field(); }
1211
1213 inline bool has_field_curl_b() { return mhd_config.has_curl_b_field() && (dim == 3); }
1214
1216 inline bool has_field_dtdiv_b() { return mhd_config.has_dtdiv_b_field(); }
1217
1220 inline void use_luminosity(bool enable) { compute_luminosity = enable; }
1221
1223 bool compute_gw = false;
1224 inline void use_GW(bool enable) {
1225 shamrock::experimental_feature_check("GW computation is experimental.");
1226 compute_gw = enable;
1227 }
1228
1230 inline void print_status() {
1231 if (shamcomm::world_rank() != 0) {
1232 return;
1233 }
1234 logger::raw_ln("----- SPH Solver configuration -----");
1235 logger::raw_ln(nlohmann::json{*this}.dump(4));
1236 logger::raw_ln("------------------------------------");
1237 }
1238
1239 inline void check_config() {
1240 dust_config.check_config();
1241 mhd_config.check_config();
1242
1243 if (track_particles_id && false /*particle injection when added*/) {
1245 "particle injection is not yet compatible with particle id tracking");
1246 }
1247
1248 if (track_particles_id) {
1249 shamrock::experimental_feature_check("Particle tracking is experimental");
1250 }
1251
1252 if (!self_grav_config.is_none()) {
1254 "Self gravity is experimental, please enable experimental features to use it");
1255 }
1256
1257 if (mhd_config.do_nimhd()) {
1259 "Non-ideal MHD is experimental, please enable experimental features to use it");
1260 }
1261
1262 using EOSBarotropic = typename EOSConfig::Barotropic;
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 = {}",
1268 eos->cs0,
1269 eos->rho0,
1270 eos->gamma0));
1271 }
1272 }
1273 }
1274
1275 void set_layout(shamrock::patch::PatchDataLayerLayout &pdl);
1276 void set_ghost_layout(shamrock::patch::PatchDataLayerLayout &ghost_layout);
1277};
1278
1279namespace shammodels::sph {
1280
1287 template<class Tscal>
1288 inline void to_json(nlohmann::json &j, const CFLConfig<Tscal> &p) {
1289 j = nlohmann::json{
1290 {"cfl_cour", p.cfl_cour},
1291 {"cfl_force", p.cfl_force},
1292 {"cfl_multiplier_stiffness", p.cfl_multiplier_stiffness},
1293 {"eta_sink", p.eta_sink}};
1294 }
1295
1302 template<class Tscal>
1303 inline void from_json(const nlohmann::json &j, CFLConfig<Tscal> &p) {
1304 j.at("cfl_cour").get_to<Tscal>(p.cfl_cour);
1305 j.at("cfl_force").get_to<Tscal>(p.cfl_force);
1306 j.at("cfl_multiplier_stiffness").get_to<Tscal>(p.cfl_multiplier_stiffness);
1307
1308 if (j.contains("eta_sink")) {
1309 j.at("eta_sink").get_to<Tscal>(p.eta_sink);
1310 } else {
1311 // Already set to default value
1312 ON_RANK_0(shamlog_warn_ln(
1313 "SPHConfig", "eta_sink not found when deserializing, defaulting to", p.eta_sink));
1314 }
1315 }
1316
1317 // JSON serialization for ParticleKillingConfig
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);
1324 j.push_back(
1325 {{"type", "sphere"}, {"center", sphere.center}, {"radius", sphere.radius}});
1326 }
1327 // If more types are added to kill_t, handle them here
1328 }
1329 }
1330
1331 template<class Tvec>
1332 inline void from_json(const nlohmann::json &j, ParticleKillingConfig<Tvec> &p) {
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);
1341 }
1342 // If more types are added to kill_t, handle them here
1343 }
1344 }
1345
1346 // JSON serialization for SmoothingLengthConfig
1347 inline void to_json(nlohmann::json &j, const SmoothingLengthConfig &p) {
1349 = std::get_if<SmoothingLengthConfig::DensityBased>(&p.config)) {
1350 j = {
1351 {"type", "density_based"},
1352 };
1353
1354 } else if (
1356 = std::get_if<SmoothingLengthConfig::DensityBasedNeighLim>(&p.config)) {
1357
1358 j = {
1359 {"type", "density_based_neigh_lim"},
1360 {"max_neigh_count", conf->max_neigh_count},
1361 };
1362 } else if (
1364 = std::get_if<SmoothingLengthConfig::DensityBasedBisectingNR>(&p.config)) {
1365 j = {
1366 {"type", "density_based_bisecting_nr"},
1367 };
1368 } else {
1370 }
1371 }
1372
1373 inline void from_json(const nlohmann::json &j, SmoothingLengthConfig &p) {
1374 if (j.at("type").get<std::string>() == "density_based") {
1376 } else if (j.at("type").get<std::string>() == "density_based_neigh_lim") {
1377 p.config
1378 = SmoothingLengthConfig::DensityBasedNeighLim{j.at("max_neigh_count").get<u32>()};
1379 } else if (j.at("type").get<std::string>() == "density_based_bisecting_nr") {
1381 } else {
1383 }
1384 }
1385
1387 inline void to_json(nlohmann::json &j, const SelfGravConfig &p) {
1388 if (const SelfGravConfig::SFMM *conf = std::get_if<SelfGravConfig::SFMM>(&p.config)) {
1389 j = {
1390 {"type", "sfmm"},
1391 {"order", conf->order},
1392 {"opening_angle", conf->opening_angle},
1393 {"reduction_level", conf->reduction_level},
1394 {"leaf_lowering", conf->leaf_lowering},
1395 };
1396 } else if (const SelfGravConfig::FMM *conf = std::get_if<SelfGravConfig::FMM>(&p.config)) {
1397 j = {
1398 {"type", "fmm"},
1399 {"order", conf->order},
1400 {"opening_angle", conf->opening_angle},
1401 {"reduction_level", conf->reduction_level},
1402 };
1403 } else if (const SelfGravConfig::MM *conf = std::get_if<SelfGravConfig::MM>(&p.config)) {
1404 j = {
1405 {"type", "mm"},
1406 {"order", conf->order},
1407 {"opening_angle", conf->opening_angle},
1408 {"reduction_level", conf->reduction_level},
1409 };
1410 } else if (
1411 const SelfGravConfig::Direct *conf = std::get_if<SelfGravConfig::Direct>(&p.config)) {
1412 j = {
1413 {"type", "direct"},
1414 {"reference_mode", conf->reference_mode},
1415 };
1416 } else if (
1417 const SelfGravConfig::None *conf = std::get_if<SelfGravConfig::None>(&p.config)) {
1418 j = {
1419 {"type", "none"},
1420 };
1421 }
1422
1423 if (const SelfGravConfig::SofteningPlummer *conf
1424 = std::get_if<SelfGravConfig::SofteningPlummer>(&p.softening_mode)) {
1425 j["softening_mode"] = "plummer";
1426 j["softening_length"] = conf->epsilon;
1427 } else {
1429 }
1430 }
1431
1433 inline void from_json(const nlohmann::json &j, SelfGravConfig &p) {
1434 if (j.at("type").get<std::string>() == "sfmm") {
1435 p.config = SelfGravConfig::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") {
1441 p.config = SelfGravConfig::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") {
1446 p.config = SelfGravConfig::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") {
1451 p.config = SelfGravConfig::Direct{j.at("reference_mode").get<bool>()};
1452 } else if (j.at("type").get<std::string>() == "none") {
1453 p.config = SelfGravConfig::None{};
1454 } else {
1456 "Invalid self gravity type: " + j.at("type").get<std::string>());
1457 }
1458
1459 if (j.contains("softening_mode")) {
1460 std::string softening_mode = j.at("softening_mode").get<std::string>();
1461 if (softening_mode == "plummer") {
1462 p.softening_mode
1463 = SelfGravConfig::SofteningPlummer{j.at("softening_length").get<f64>()};
1464 } else {
1466 "Invalid softening mode: " + softening_mode);
1467 }
1468 }
1469 }
1470
1471 // JSON serialization for DustConfig
1472 template<class Tvec>
1473 inline void to_json(nlohmann::json &j, const DustConfig<Tvec> &p) {
1474 j = {};
1475
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;
1480 }
1481
1482 template<class Tvec>
1483 inline void from_json(const nlohmann::json &j, DustConfig<Tvec> &p) {
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"));
1488 }
1489 p.ballabio_ts_limiter = j.value("ballabio_ts_limiter", false);
1490 }
1491
1498 template<class Tvec, template<class> class SPHKernel>
1499 inline void to_json(nlohmann::json &j, const SolverConfig<Tvec, SPHKernel> &p) {
1501 using Tkernel = typename T::Kernel;
1502
1503 std::string kernel_id = shambase::get_type_name<Tkernel>();
1504 std::string type_id = shambase::get_type_name<Tvec>();
1505
1506 j = nlohmann::json{
1507 // used for type checking
1508 {"kernel_id", kernel_id},
1509 {"type_id", type_id},
1510 // scheduler config
1511 {"scheduler_config", p.scheduler_conf},
1512 // actual data stored in the json
1513 {"gpart_mass", p.gpart_mass},
1514 {"cfl_config", p.cfl_config},
1515 {"unit_sys", p.unit_sys},
1516 {"show_cfl_detail", p.show_cfl_detail},
1517 // mhd config
1518 {"mhd_config", p.mhd_config},
1519 // dust config
1520 {"dust_config", p.dust_config},
1521 // self gravity config
1522 {"self_grav_config", p.self_grav_config},
1523 // tree config
1524 {"tree_reduction_level", p.tree_reduction_level},
1526 {"show_neigh_stats", p.show_neigh_stats},
1527 // solver behavior config
1528 {"combined_dtdiv_divcurlv_compute", p.combined_dtdiv_divcurlv_compute},
1529 {"htol_up_coarse_cycle", p.htol_up_coarse_cycle},
1530 {"htol_up_fine_cycle", p.htol_up_fine_cycle},
1531 {"epsilon_h", p.epsilon_h},
1532 {"smoothing_length_config", p.smoothing_length_config},
1533 {"h_iter_per_subcycles", p.h_iter_per_subcycles},
1534 {"h_max_subcycles_count", p.h_max_subcycles_count},
1535
1536 {"enable_particle_reordering", p.enable_particle_reordering},
1537 {"particle_reordering_step_freq", p.particle_reordering_step_freq},
1538
1539 {"save_dt_to_fields", p.save_dt_to_fields},
1540 {"show_ghost_zone_graph", p.show_ghost_zone_graph},
1541 {"show_ghost_stats", p.show_ghost_stats},
1542
1543 {"eos_config", p.eos_config},
1544
1545 {"artif_viscosity", p.artif_viscosity},
1546 {"boundary_config", p.boundary_config},
1547 {"ext_force_config", p.ext_force_config},
1548
1549 {"do_debug_dump", p.do_debug_dump},
1550 {"debug_dump_filename", p.debug_dump_filename},
1551 // particle killing config
1552 {"particle_killing", p.particle_killing},
1553 };
1554 }
1555
1562 template<class Tvec, template<class> class SPHKernel>
1563 inline void from_json(const nlohmann::json &j, SolverConfig<Tvec, SPHKernel> &p) {
1565 using Tkernel = typename T::Kernel;
1566
1567 // type checking
1568 if (j.contains("kernel_id")) {
1569
1570 std::string kernel_id = j.at("kernel_id").get<std::string>();
1571
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);
1576 }
1577 }
1578
1579 if (j.contains("type_id")) {
1580
1581 std::string type_id = j.at("type_id").get<std::string>();
1582
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);
1587 }
1588 }
1589
1590 bool has_used_defaults = false;
1591 bool has_updated_config = false;
1592
1593 auto _get_to_if_contains = [&](const std::string &key, auto &value) {
1594 shamrock::get_to_if_contains(j, key, value, has_used_defaults);
1595 };
1596
1597 auto _get_to_if_contains_fallbacks = [&](const std::string &key,
1598 auto &value,
1599 std::initializer_list<const char *> fallbacks) {
1601 j, key, value, fallbacks, has_used_defaults, has_updated_config);
1602 };
1603
1604 _get_to_if_contains("scheduler_config", p.scheduler_conf);
1605
1606 // actual data stored in the json
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);
1614 _get_to_if_contains("tree_reduction_level", p.tree_reduction_level);
1615 // Reads the new enum key, falling back on the legacy `use_two_stage_search` boolean
1617 j, p.neigh_cache_strategy, "SPH::SolverConfig", has_used_defaults, has_updated_config);
1618 _get_to_if_contains("show_neigh_stats", p.show_neigh_stats);
1619 _get_to_if_contains("combined_dtdiv_divcurlv_compute", p.combined_dtdiv_divcurlv_compute);
1620
1621 // Try new names first, fall back to old names for backward compatibility
1622 _get_to_if_contains_fallbacks(
1623 "htol_up_coarse_cycle", p.htol_up_coarse_cycle, {"htol_up_tol"});
1624 _get_to_if_contains_fallbacks("htol_up_fine_cycle", p.htol_up_fine_cycle, {"htol_up_iter"});
1625
1626 _get_to_if_contains("epsilon_h", p.epsilon_h);
1627 _get_to_if_contains("smoothing_length_config", p.smoothing_length_config);
1628 _get_to_if_contains("h_iter_per_subcycles", p.h_iter_per_subcycles);
1629 _get_to_if_contains("h_max_subcycles_count", p.h_max_subcycles_count);
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);
1634 _get_to_if_contains("show_ghost_stats", p.show_ghost_stats);
1635 _get_to_if_contains("eos_config", p.eos_config);
1636 _get_to_if_contains("artif_viscosity", p.artif_viscosity);
1637 _get_to_if_contains("boundary_config", p.boundary_config);
1638 _get_to_if_contains("ext_force_config", p.ext_force_config);
1639 _get_to_if_contains("do_debug_dump", p.do_debug_dump);
1640 _get_to_if_contains("debug_dump_filename", p.debug_dump_filename);
1641 _get_to_if_contains("particle_killing", p.particle_killing);
1642
1643 if (has_used_defaults || has_updated_config) {
1644 if (shamcomm::world_rank() == 0) {
1646 "SPH::SolverConfig",
1647 shamrock::log_json_changes(p, j, has_used_defaults, has_updated_config));
1648 }
1649 }
1650 }
1651
1652} // namespace shammodels::sph
Header file describing a Node Instance.
MPI scheduler.
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.
Core formatting functions: format, vformat, and format_printf.
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...
Definition memory.hpp:112
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.
Definition worldInfo.cpp:41
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.
Definition logs.hpp:89
void info_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
sph kernels
Locally isothermal equation of state configuration.
Definition EOSConfig.hpp:61
Configuration struct for the equation of state used in the hydrodynamic models.
Definition EOSConfig.hpp:42
shamphys::EOS_Config_Polytropic< Tscal > Polytropic
Polytropic equation of state configuration.
Definition EOSConfig.hpp:55
shamphys::EOS_Config_Isothermal< Tscal > Isothermal
Isothermal equation of state configuration.
Definition EOSConfig.hpp:58
shamphys::EOS_Config_Fermi< Tscal > Fermi
Fermi equation of state configuration.
Definition EOSConfig.hpp:73
shamphys::EOS_Config_Adiabatic< Tscal > Adiabatic
Adiabatic equation of state configuration.
Definition EOSConfig.hpp:52
shamphys::EOS_Config_Barotropic< Tscal > Barotropic
Barotropic equation of state configuration.
Definition EOSConfig.hpp:76
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...
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.
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.
Definition worldInfo.hpp:73