27#include <nlohmann/json.hpp>
30namespace shammodels::gsph {
42 struct ReconstructConfig;
49 using Tscal = shambase::VecComponent<Tvec>;
81 using Variant = std::variant<PiecewiseConstant, MUSCL>;
85 void set(Variant v) { config = v; }
87 void set_piecewise_constant() { set(PiecewiseConstant{}); }
91 inline bool is_piecewise_constant()
const {
92 return std::holds_alternative<PiecewiseConstant>(config);
95 inline bool is_muscl()
const {
return std::holds_alternative<MUSCL>(config); }
97 inline bool requires_gradients()
const {
return is_muscl(); }
99 inline void print_status()
const {
100 logger::raw_ln(
"--- Reconstruction config");
102 if (std::get_if<PiecewiseConstant>(&config)) {
103 logger::raw_ln(
" Type : PiecewiseConstant (1st order)");
104 }
else if (
const MUSCL *v = std::get_if<MUSCL>(&config)) {
105 logger::raw_ln(
" Type : MUSCL (2nd order)");
106 switch (v->limiter) {
110 case Limiter::MC : logger::raw_ln(
" Limiter : MC");
break;
116 logger::raw_ln(
"-------------");
120namespace shammodels::gsph {
123 inline void to_json(nlohmann::json &j,
const ReconstructConfig<Tvec> &p) {
124 using T = ReconstructConfig<Tvec>;
125 using PiecewiseConstant =
typename T::PiecewiseConstant;
126 using MUSCL =
typename T::MUSCL;
127 using Limiter =
typename T::Limiter;
129 if (std::get_if<PiecewiseConstant>(&p.config)) {
131 {
"reconstruct_type",
"piecewise_constant"},
133 }
else if (
const MUSCL *v = std::get_if<MUSCL>(&p.config)) {
134 std::string limiter_str;
135 switch (v->limiter) {
136 case Limiter::VanLeer : limiter_str =
"vanleer";
break;
137 case Limiter::Minmod : limiter_str =
"minmod";
break;
138 case Limiter::Superbee: limiter_str =
"superbee";
break;
139 case Limiter::MC : limiter_str =
"mc";
break;
142 {
"reconstruct_type",
"muscl"},
143 {
"limiter", limiter_str},
151 inline void from_json(
const nlohmann::json &j, ReconstructConfig<Tvec> &p) {
152 using T = ReconstructConfig<Tvec>;
153 using PiecewiseConstant =
typename T::PiecewiseConstant;
154 using MUSCL =
typename T::MUSCL;
155 using Limiter =
typename T::Limiter;
157 if (!j.contains(
"reconstruct_type")) {
159 "no field reconstruct_type is found in this json");
162 std::string reconstruct_type;
163 j.at(
"reconstruct_type").get_to(reconstruct_type);
165 if (reconstruct_type ==
"piecewise_constant") {
166 p.set(PiecewiseConstant{});
167 }
else if (reconstruct_type ==
"muscl") {
168 std::string limiter_str;
169 j.at(
"limiter").get_to(limiter_str);
172 if (limiter_str ==
"vanleer") {
173 limiter = Limiter::VanLeer;
174 }
else if (limiter_str ==
"minmod") {
175 limiter = Limiter::Minmod;
176 }
else if (limiter_str ==
"superbee") {
177 limiter = Limiter::Superbee;
178 }
else if (limiter_str ==
"mc") {
179 limiter = Limiter::MC;
184 p.set(MUSCL{limiter});
std::uint32_t u32
32 bit unsigned integer
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
void to_json(nlohmann::json &j, const EOSConfig< Tvec > &p)
Serialize EOSConfig to json.
void from_json(const nlohmann::json &j, EOSConfig< Tvec > &p)
Deserializes an EOSConfig<Tvec> from a JSON object.
Contains traits and utilities for backend related types.
MUSCL reconstruction (2nd order)
Limiter limiter
Slope limiter type.
Piecewise constant (1st order)
Configuration for reconstruction methods in GSPH.
Limiter
Slope limiter types for MUSCL reconstruction.
@ Superbee
Superbee limiter (least diffusive)
@ Minmod
Minmod limiter (most diffusive)
@ MC
Monotonized Central limiter.
@ VanLeer
van Leer limiter (smooth)