24#include <nlohmann/json.hpp>
34 static constexpr std::string_view variant_type_name =
"none";
41 inline void from_json(
const nlohmann::json &j, AVConfig_None<Tscal> &p) {
50 static constexpr std::string_view variant_type_name =
"constant";
60 {
"alpha_u", p.alpha_u},
61 {
"alpha_AV", p.alpha_AV},
62 {
"beta_AV", p.beta_AV},
67 inline void from_json(
const nlohmann::json &j, AVConfig_Constant<Tscal> &p) {
68 j.at(
"alpha_u").get_to(p.alpha_u);
69 j.at(
"alpha_AV").get_to(p.alpha_AV);
70 j.at(
"beta_AV").get_to(p.beta_AV);
79 static constexpr std::string_view variant_type_name =
"varying_mm97";
81 Tscal alpha_min = 0.1;
82 Tscal alpha_max = 1.0;
83 Tscal sigma_decay = 0.1;
91 {
"alpha_min", p.alpha_min},
92 {
"alpha_max", p.alpha_max},
93 {
"sigma_decay", p.sigma_decay},
94 {
"alpha_u", p.alpha_u},
95 {
"beta_AV", p.beta_AV},
100 inline void from_json(
const nlohmann::json &j, AVConfig_VaryingMM97<Tscal> &p) {
101 j.at(
"alpha_min").get_to(p.alpha_min);
102 j.at(
"alpha_max").get_to(p.alpha_max);
103 j.at(
"sigma_decay").get_to(p.sigma_decay);
104 j.at(
"alpha_u").get_to(p.alpha_u);
105 j.at(
"beta_AV").get_to(p.beta_AV);
112 template<
class Tscal>
114 static constexpr std::string_view variant_type_name =
"varying_cd10";
116 Tscal alpha_min = 0.1;
117 Tscal alpha_max = 1.0;
118 Tscal sigma_decay = 0.1;
123 template<
class Tscal>
126 {
"alpha_min", p.alpha_min},
127 {
"alpha_max", p.alpha_max},
128 {
"sigma_decay", p.sigma_decay},
129 {
"alpha_u", p.alpha_u},
130 {
"beta_AV", p.beta_AV},
134 template<
class Tscal>
135 inline void from_json(
const nlohmann::json &j, AVConfig_VaryingCD10<Tscal> &p) {
136 j.at(
"alpha_min").get_to(p.alpha_min);
137 j.at(
"alpha_max").get_to(p.alpha_max);
138 j.at(
"sigma_decay").get_to(p.sigma_decay);
139 j.at(
"alpha_u").get_to(p.alpha_u);
140 j.at(
"beta_AV").get_to(p.beta_AV);
146 template<
class Tscal>
148 static constexpr std::string_view variant_type_name =
"constant_disc";
150 Tscal alpha_AV = 1.0;
155 template<
class Tscal>
158 {
"alpha_AV", p.alpha_AV},
159 {
"alpha_u", p.alpha_u},
160 {
"beta_AV", p.beta_AV},
164 template<
class Tscal>
165 inline void from_json(
const nlohmann::json &j, AVConfig_ConstantDisc<Tscal> &p) {
166 j.at(
"alpha_AV").get_to(p.alpha_AV);
167 j.at(
"alpha_u").get_to(p.alpha_u);
168 j.at(
"beta_AV").get_to(p.beta_AV);
192 using Tscal = shambase::VecComponent<Tvec>;
203 using Variant = std::variant<None, Constant, VaryingMM97, VaryingCD10, ConstantDisc>;
222 set(
VaryingCD10{alpha_min, alpha_max, sigma_decay, alpha_u, beta_AV});
231 bool is_varying_alpha
232 = bool(std::get_if<VaryingMM97>(&
config)) || bool(std::get_if<VaryingCD10>(&
config));
233 return is_varying_alpha;
243 bool is_varying_alpha
244 = bool(std::get_if<VaryingMM97>(&
config)) || bool(std::get_if<VaryingCD10>(&
config));
245 return is_varying_alpha;
255 bool is_varying_alpha = bool(std::get_if<VaryingCD10>(&
config));
256 return is_varying_alpha;
265 bool is_varying_alpha = bool(std::get_if<VaryingCD10>(&
config));
266 return is_varying_alpha;
282 bool is_varying_alpha
283 = bool(std::get_if<VaryingMM97>(&
config)) || bool(std::get_if<VaryingCD10>(&
config));
284 return is_varying_alpha;
291 logger::raw_ln(
"--- artificial viscosity config");
294 logger::raw_ln(
" Config Type : None (No artificial viscosity)");
296 logger::raw_ln(
" Config Type : Constant (Constant artificial viscosity)");
297 logger::raw_ln(
" alpha_u =", v->alpha_u);
298 logger::raw_ln(
" alpha_AV =", v->alpha_AV);
299 logger::raw_ln(
" beta_AV =", v->beta_AV);
301 logger::raw_ln(
" Config Type : VaryingMM97 (Morris & Monaghan 1997)");
302 logger::raw_ln(
" alpha_min =", v->alpha_min);
303 logger::raw_ln(
" alpha_max =", v->alpha_max);
304 logger::raw_ln(
" sigma_decay =", v->sigma_decay);
305 logger::raw_ln(
" alpha_u =", v->alpha_u);
306 logger::raw_ln(
" beta_AV =", v->beta_AV);
308 logger::raw_ln(
" Config Type : VaryingCD10 (Cullen & Dehnen 2010)");
309 logger::raw_ln(
" alpha_min =", v->alpha_min);
310 logger::raw_ln(
" alpha_max =", v->alpha_max);
311 logger::raw_ln(
" sigma_decay =", v->sigma_decay);
312 logger::raw_ln(
" alpha_u =", v->alpha_u);
313 logger::raw_ln(
" beta_AV =", v->beta_AV);
315 logger::raw_ln(
" Config Type : constant disc");
316 logger::raw_ln(
" alpha_AV =", v->alpha_AV);
317 logger::raw_ln(
" alpha_u =", v->alpha_u);
318 logger::raw_ln(
" beta_AV =", v->beta_AV);
323 logger::raw_ln(
"--- artificial viscosity config (deduced)");
325 logger::raw_ln(
"-------------");
328 inline std::optional<Tscal> get_alpha_u() {
329 if (
const Constant *v = std::get_if<Constant>(&
config)) {
331 }
else if (
const VaryingMM97 *v = std::get_if<VaryingMM97>(&
config)) {
333 }
else if (
const VaryingCD10 *v = std::get_if<VaryingCD10>(&
config)) {
335 }
else if (
const ConstantDisc *v = std::get_if<ConstantDisc>(&
config)) {
337 }
else if (
const None *v = std::get_if<None>(&
config)) {
357 [&](
const auto &value) {
359 j[
"type"] = value.variant_type_name;
373 using Tscal = shambase::VecComponent<Tvec>;
375 if (!j.contains(
"type") && !j.contains(
"av_type")) {
377 "neither \"type\" nor \"av_type\" in this json, can not infer type json=\n"
382 if (j.contains(
"type")) {
383 j.at(
"type").get_to(av_type);
385 j.at(
"av_type").get_to(av_type);
388 shamrock::json_deserialize_variant(j, av_type, p.config);
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.
namespace for the sph model
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.
Constant artificial viscosity for alpha disc viscosity.
Constant artificial viscosity: .
No artificial viscosity: .
Configuration for the Artificial Viscosity (AV)
void set_varying_cd10(Tscal alpha_min, Tscal alpha_max, Tscal sigma_decay, Tscal alpha_u, Tscal beta_AV)
Sets the configuration to use a varying Cullen & Dehnen 2010 artificial viscosity.
static constexpr u32 dim
Number of dimensions of the problem.
std::variant< None, Constant, VaryingMM97, VaryingCD10, ConstantDisc > Variant
Variant of all types of artificial viscosity possible.
Variant config
The actual configuration (default to constant viscosity)
void set(Variant v)
Set the configuration.
shambase::VecComponent< Tvec > Tscal
Type of the components of the vector of coordinates.
void print_status()
Prints the status of the artificial viscosity configuration.
bool has_alphaAV_field()
Checks if the current configuration has an alpha artificial viscosity field.
bool has_divv_field()
Checks if the current configuration need the divergence of the velocity field.
bool has_field_soundspeed()
Checks if the current configuration requires the soundspeed field.
bool has_curlv_field()
Checks if the current configuration need the curl of the velocity field.
bool has_dtdivv_field()
Checks if the current configuration has a dtdivv field.