31#include <nlohmann/json.hpp>
34namespace shammodels::gsph {
55 using Tscal = shambase::VecComponent<Tvec>;
66 Tscal
tol = Tscal{1.0e-6};
78 Tscal
tol = Tscal{1.0e-8};
101 using Variant = std::variant<Iterative, Exact, HLLC, Roe>;
103 Variant config = Iterative{};
105 void set(Variant v) { config = v; }
107 void set_iterative(Tscal tol = Tscal{1.0e-6},
u32 max_iter = 20) {
108 set(Iterative{tol, max_iter});
111 void set_exact(Tscal tol = Tscal{1.0e-8}) { set(Exact{tol}); }
113 void set_hllc() { set(HLLC{}); }
115 void set_roe(Tscal entropy_fix = Tscal{0.1}) { set(Roe{entropy_fix}); }
117 inline bool is_iterative()
const {
return std::holds_alternative<Iterative>(config); }
118 inline bool is_exact()
const {
return std::holds_alternative<Exact>(config); }
119 inline bool is_hllc()
const {
return std::holds_alternative<HLLC>(config); }
120 inline bool is_roe()
const {
return std::holds_alternative<Roe>(config); }
122 inline void print_status()
const {
123 logger::raw_ln(
"--- Riemann solver config");
125 if (
const Iterative *v = std::get_if<Iterative>(&config)) {
126 logger::raw_ln(
" Type : Iterative (van Leer 1997)");
127 logger::raw_ln(
" tol =", v->tol);
128 logger::raw_ln(
" max_iter =", v->max_iter);
129 }
else if (
const Exact *v = std::get_if<Exact>(&config)) {
130 logger::raw_ln(
" Type : Exact (Toro)");
131 logger::raw_ln(
" tol =", v->tol);
132 }
else if (std::get_if<HLLC>(&config)) {
133 logger::raw_ln(
" Type : HLLC");
134 }
else if (
const Roe *v = std::get_if<Roe>(&config)) {
135 logger::raw_ln(
" Type : Roe");
136 logger::raw_ln(
" entropy_fix =", v->entropy_fix);
141 logger::raw_ln(
"-------------");
145namespace shammodels::gsph {
148 inline void to_json(nlohmann::json &j,
const RiemannConfig<Tvec> &p) {
149 using T = RiemannConfig<Tvec>;
150 using Iterative =
typename T::Iterative;
151 using Exact =
typename T::Exact;
152 using HLLC =
typename T::HLLC;
153 using Roe =
typename T::Roe;
155 if (
const Iterative *v = std::get_if<Iterative>(&p.config)) {
157 {
"riemann_type",
"iterative"},
159 {
"max_iter", v->max_iter},
161 }
else if (
const Exact *v = std::get_if<Exact>(&p.config)) {
163 {
"riemann_type",
"exact"},
166 }
else if (std::get_if<HLLC>(&p.config)) {
168 {
"riemann_type",
"hllc"},
170 }
else if (
const Roe *v = std::get_if<Roe>(&p.config)) {
172 {
"riemann_type",
"roe"},
173 {
"entropy_fix", v->entropy_fix},
181 inline void from_json(
const nlohmann::json &j, RiemannConfig<Tvec> &p) {
182 using T = RiemannConfig<Tvec>;
183 using Tscal = shambase::VecComponent<Tvec>;
185 if (!j.contains(
"riemann_type")) {
187 "no field riemann_type is found in this json");
190 std::string riemann_type;
191 j.at(
"riemann_type").get_to(riemann_type);
193 using Iterative =
typename T::Iterative;
194 using Exact =
typename T::Exact;
195 using HLLC =
typename T::HLLC;
196 using Roe =
typename T::Roe;
198 if (riemann_type ==
"iterative") {
199 p.set(Iterative{j.at(
"tol").get<Tscal>(), j.at(
"max_iter").get<
u32>()});
200 }
else if (riemann_type ==
"exact") {
201 p.set(Exact{j.at(
"tol").get<Tscal>()});
202 }
else if (riemann_type ==
"hllc") {
204 }
else if (riemann_type ==
"roe") {
205 p.set(Roe{j.at(
"entropy_fix").get<Tscal>()});
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.
Tscal tol
Convergence tolerance.
HLLC approximate Riemann solver.
van Leer (1997) iterative Riemann solver
Tscal tol
Convergence tolerance.
u32 max_iter
Maximum iterations.
Roe linearized Riemann solver.
Tscal entropy_fix
Entropy fix parameter.
Configuration for Riemann solvers in GSPH.