50#include <nlohmann/json.hpp>
56namespace shammodels::gsph {
64 template<
class Tvec,
template<
class>
class SPHKernel>
80template<
class Tvec,
template<
class>
class SPHKernel>
83 using Tscal = shambase::VecComponent<Tvec>;
84 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
85 using Kernel = SPHKernel<Tscal>;
90 static constexpr Tscal Rkern = Kernel::Rkern;
102 std::optional<shamunits::UnitSystem<Tscal>> unit_sys = {};
106 inline Tscal get_constant_G()
const {
112 return shamunits::Constants<Tscal>{*unit_sys}.G();
124 using RiemannConfig = RiemannConfig<Tvec>;
125 RiemannConfig riemann_config;
127 inline void set_riemann_iterative(Tscal tol = Tscal{1e-6},
u32 max_iter = 20) {
128 riemann_config.set_iterative(tol, max_iter);
131 inline void set_riemann_hllc() { riemann_config.set_hllc(); }
133 inline void set_riemann_exact(Tscal tol = Tscal{1e-8},
u32 max_iter = 100) {
134 riemann_config.set_exact(tol, max_iter);
145 using ReconstructConfig = ReconstructConfig<Tvec>;
146 ReconstructConfig reconstruct_config;
148 inline void set_reconstruct_piecewise_constant() {
149 reconstruct_config.set_piecewise_constant();
152 inline void set_reconstruct_muscl(
154 reconstruct_config.set_muscl(limiter);
157 inline bool requires_gradients()
const {
return reconstruct_config.requires_gradients(); }
167 using ForceFormulationConfig = ForceFormulationConfig<Tvec>;
168 ForceFormulationConfig force_formulation_config;
170 inline void set_force_cha_whitworth() { force_formulation_config.set_cha_whitworth(); }
172 inline void set_force_inutsuka_v2() { force_formulation_config.set_inutsuka_v2(); }
174 inline bool is_force_inutsuka_v2()
const {
return force_formulation_config.is_inutsuka_v2(); }
184 using EOSConfig = shammodels::EOSConfig<Tvec>;
185 EOSConfig eos_config;
187 inline bool is_eos_adiabatic()
const {
189 return bool(std::get_if<T>(&eos_config.config));
192 inline bool is_eos_isothermal()
const {
194 return bool(std::get_if<T>(&eos_config.config));
205 if (
const auto *eos = std::get_if<Adiabatic>(&eos_config.config)) {
207 }
else if (
const auto *eos = std::get_if<Polytropic>(&eos_config.config)) {
213 inline void set_eos_adiabatic(Tscal gamma) { eos_config.set_adiabatic(gamma); }
215 inline void set_eos_isothermal(Tscal cs) { eos_config.set_isothermal(cs); }
226 BCConfig boundary_config;
228 inline void set_boundary_free() { boundary_config.
set_free(); }
229 inline void set_boundary_periodic() { boundary_config.set_periodic(); }
242 boundary_config.set_shearing_periodic(shear_base, shear_dir, speed);
256 inline void add_ext_force_point_mass(Tscal central_mass, Tscal Racc) {
257 ext_force_config.add_point_mass(central_mass, Racc);
268 u32 tree_reduction_level = 3;
269 bool use_two_stage_search =
true;
271 inline void set_tree_reduction_level(
u32 level) { tree_reduction_level = level; }
272 inline void set_two_stage_search(
bool enable) { use_two_stage_search = enable; }
292 inline bool has_field_uint()
const {
return is_eos_adiabatic(); }
294 inline void print_status() {
300 riemann_config.print_status();
301 reconstruct_config.print_status();
302 force_formulation_config.print_status();
303 eos_config.print_status();
307 inline void check_config()
const {
316 if (force_formulation_config.is_inutsuka_v2() && riemann_config.is_hllc()) {
318 "InutsukaV2 force formulation is not yet supported with the HLLC Riemann "
319 "solver. Use set_riemann_iterative() or set_riemann_exact() instead.");
323 inline void check_config_runtime()
const {
327 "gpart_mass must be positive. Call set_particle_mass() before evolving.");
332 void set_layout(shamrock::patch::PatchDataLayerLayout &pdl);
333 void set_ghost_layout(shamrock::patch::PatchDataLayerLayout &ghost_layout);
336namespace shammodels::gsph {
338 template<
class Tscal>
341 {
"cfl_cour", p.cfl_cour},
342 {
"cfl_force", p.cfl_force},
346 template<
class Tscal>
348 j.at(
"cfl_cour").get_to(p.cfl_cour);
349 j.at(
"cfl_force").get_to(p.cfl_force);
352 template<
class Tvec,
template<
class>
class SPHKernel>
355 using Tkernel =
typename T::Kernel;
357 std::string kernel_id = shambase::get_type_name<Tkernel>();
358 std::string type_id = shambase::get_type_name<Tvec>();
361 {
"solver_type",
"gsph"},
362 {
"kernel_id", kernel_id},
363 {
"type_id", type_id},
364 {
"scheduler_config", p.scheduler_conf},
365 {
"gpart_mass", p.gpart_mass},
366 {
"cfl_config", p.cfl_config},
367 {
"unit_sys", p.unit_sys},
368 {
"riemann_config", p.riemann_config},
369 {
"reconstruct_config", p.reconstruct_config},
370 {
"force_formulation_config", p.force_formulation_config},
371 {
"eos_config", p.eos_config},
372 {
"boundary_config", p.boundary_config},
373 {
"tree_reduction_level", p.tree_reduction_level},
374 {
"use_two_stage_search", p.use_two_stage_search},
375 {
"htol_up_coarse_cycle", p.htol_up_coarse_cycle},
376 {
"htol_up_fine_cycle", p.htol_up_fine_cycle},
377 {
"epsilon_h", p.epsilon_h},
378 {
"h_iter_per_subcycles", p.h_iter_per_subcycles},
379 {
"h_max_subcycles_count", p.h_max_subcycles_count},
383 template<
class Tvec,
template<
class>
class SPHKernel>
386 using Tkernel =
typename T::Kernel;
388 std::string kernel_id = j.at(
"kernel_id").get<std::string>();
389 if (kernel_id != shambase::get_type_name<Tkernel>()) {
391 "Invalid kernel type: expected " + shambase::get_type_name<Tkernel>() +
" but got "
395 std::string type_id = j.at(
"type_id").get<std::string>();
396 if (type_id != shambase::get_type_name<Tvec>()) {
398 "Invalid vector type: expected " + shambase::get_type_name<Tvec>() +
" but got "
402 bool has_used_defaults =
false;
403 bool has_updated_config =
false;
405 auto _get_to_if_contains = [&](
const std::string &key,
auto &value) {
409 _get_to_if_contains(
"scheduler_config", p.scheduler_conf);
410 _get_to_if_contains(
"gpart_mass", p.gpart_mass);
411 _get_to_if_contains(
"cfl_config", p.cfl_config);
412 _get_to_if_contains(
"unit_sys", p.unit_sys);
413 _get_to_if_contains(
"riemann_config", p.riemann_config);
414 _get_to_if_contains(
"reconstruct_config", p.reconstruct_config);
415 _get_to_if_contains(
"force_formulation_config", p.force_formulation_config);
416 _get_to_if_contains(
"eos_config", p.eos_config);
417 _get_to_if_contains(
"boundary_config", p.boundary_config);
418 _get_to_if_contains(
"tree_reduction_level", p.tree_reduction_level);
419 _get_to_if_contains(
"use_two_stage_search", p.use_two_stage_search);
420 _get_to_if_contains(
"htol_up_coarse_cycle", p.htol_up_coarse_cycle);
421 _get_to_if_contains(
"htol_up_fine_cycle", p.htol_up_fine_cycle);
422 _get_to_if_contains(
"epsilon_h", p.epsilon_h);
423 _get_to_if_contains(
"h_iter_per_subcycles", p.h_iter_per_subcycles);
424 _get_to_if_contains(
"h_max_subcycles_count", p.h_max_subcycles_count);
426 if (has_used_defaults || has_updated_config) {
429 "GSPH::SolverConfig",
Header file describing a Node Instance.
Configuration for reconstruction methods in GSPH.
Configuration for Riemann solvers in GSPH.
std::uint32_t u32
32 bit unsigned integer
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
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.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
void get_to_if_contains(const nlohmann::json &j, const std::string &key, T &value, bool &has_used_defaults)
std::string log_json_changes(const nlohmann::json &j_current, const nlohmann::json &j, bool has_used_defaults, bool has_updated_config)
Shown the changes between two JSON objects to log config changes.
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 warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
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_Adiabatic< Tscal > Adiabatic
Adiabatic equation of state configuration.
The configuration for the CFL condition in GSPH.
Tscal cfl_force
CFL condition for the force.
Tscal cfl_cour
CFL condition for the courant factor.
Limiter
Slope limiter types for MUSCL reconstruction.
@ VanLeer
van Leer limiter (smooth)
The configuration for a GSPH solver.
u32 h_iter_per_subcycles
Max iterations per subcycle.
void set_boundary_shearing_periodic(i32_3 shear_base, i32_3 shear_dir, Tscal speed)
Set shearing periodic boundary conditions.
Tscal get_eos_gamma() const
Get the adiabatic index (gamma) from the EOS config.
Tscal htol_up_coarse_cycle
Factor for neighbors search.
Tscal gpart_mass
The mass of each gas particle (must be set before use).
u32 h_max_subcycles_count
Max subcycles before crash.
Tscal htol_up_fine_cycle
Max smoothing length evolution per subcycle.
CFLConfig< Tscal > cfl_config
CFL configuration.
Tscal epsilon_h
Convergence criteria for smoothing length.
Boundary conditions configuration.
void set_free()
Set the boundary condition to free boundaries.
constexpr T G()
get the value of G 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.