Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ForceFormulationConfig.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
26
28#include "shambackends/vec.hpp"
30#include <nlohmann/json.hpp>
31#include <variant>
32
33namespace shammodels::gsph {
34
35 template<class Tvec>
37
38} // namespace shammodels::gsph
39
40template<class Tvec>
42
43 using Tscal = shambase::VecComponent<Tvec>;
44 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
45
49 struct ChaWhitworth {};
50
57 struct InutsukaV2 {};
58
59 using Variant = std::variant<ChaWhitworth, InutsukaV2>;
60
61 Variant config = ChaWhitworth{};
62
63 void set(Variant v) { config = v; }
64
65 void set_cha_whitworth() { set(ChaWhitworth{}); }
66
67 void set_inutsuka_v2() { set(InutsukaV2{}); }
68
69 inline bool is_cha_whitworth() const { return std::holds_alternative<ChaWhitworth>(config); }
70
71 inline bool is_inutsuka_v2() const { return std::holds_alternative<InutsukaV2>(config); }
72
73 inline void print_status() const {
74 logger::raw_ln("--- Force formulation config");
75
76 if (std::get_if<ChaWhitworth>(&config)) {
77 logger::raw_ln(" Type : ChaWhitworth (2003) - symmetric SPH form");
78 } else if (std::get_if<InutsukaV2>(&config)) {
79 logger::raw_ln(
80 " Type : InutsukaV2 (2002) - effective volume/face, linear (1st order)");
81 } else {
83 }
84
85 logger::raw_ln("-------------");
86 }
87};
88
89namespace shammodels::gsph {
90
91 template<class Tvec>
92 inline void to_json(nlohmann::json &j, const ForceFormulationConfig<Tvec> &p) {
94 using ChaWhitworth = typename T::ChaWhitworth;
95 using InutsukaV2 = typename T::InutsukaV2;
96
97 if (std::get_if<ChaWhitworth>(&p.config)) {
98 j = {
99 {"force_formulation", "cha_whitworth"},
100 };
101 } else if (std::get_if<InutsukaV2>(&p.config)) {
102 j = {
103 {"force_formulation", "inutsuka_v2"},
104 };
105 } else {
107 }
108 }
109
110 template<class Tvec>
111 inline void from_json(const nlohmann::json &j, ForceFormulationConfig<Tvec> &p) {
113 using ChaWhitworth = typename T::ChaWhitworth;
114 using InutsukaV2 = typename T::InutsukaV2;
115
116 if (!j.contains("force_formulation")) {
118 "no field force_formulation is found in this json");
119 }
120
121 std::string force_formulation;
122 j.at("force_formulation").get_to(force_formulation);
123
124 if (force_formulation == "cha_whitworth") {
125 p.set(ChaWhitworth{});
126 } else if (force_formulation == "inutsuka_v2") {
127 p.set(InutsukaV2{});
128 } else {
129 shambase::throw_unimplemented("Unknown force formulation type: " + force_formulation);
130 }
131 }
132
133} // namespace shammodels::gsph
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.
Contains traits and utilities for backend related types.
Cha & Whitworth (2003) symmetric SPH momentum equation (default).
Inutsuka (2002) effective volume/face momentum equation.