Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
BCConfig.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
20#include "shambackends/vec.hpp"
22#include <nlohmann/json.hpp>
23#include <variant>
24
25namespace shammodels::sph {
26
34 template<class Tvec>
35 struct BCConfig;
36
37} // namespace shammodels::sph
38
39template<class Tvec>
41
43 using Tscal = shambase::VecComponent<Tvec>;
46
52 struct Free {
60 };
61
65 struct Periodic {};
66
79
83 i32_3 shear_dir;
84
89 };
90
92 using Variant = std::variant<Free, Periodic, ShearingPeriodic>;
93
96
98 inline void set_free() { config = Free{}; }
99
101 inline void set_periodic() { config = Periodic{}; }
102
111 inline void set_shearing_periodic(i32_3 shear_base, i32_3 shear_dir, Tscal speed) {
112 config = ShearingPeriodic{shear_base, shear_dir, speed};
113 }
114
121 inline void print_status() {
122 logger::raw_ln("--- Bondaries config");
123
124 if (Free *v = std::get_if<Free>(&config)) {
125 logger::raw_ln(" Config Type : Free boundaries");
126 } else if (Periodic *v = std::get_if<Periodic>(&config)) {
127 logger::raw_ln(" Config Type : Periodic boundaries");
128 } else if (ShearingPeriodic *v = std::get_if<ShearingPeriodic>(&config)) {
129 logger::raw_ln(" Config Type : ShearingPeriodic (Stone 2010)");
130 logger::raw_ln(" shear_base =", v->shear_base);
131 logger::raw_ln(" shear_dir =", v->shear_dir);
132 logger::raw_ln(" shear_speed =", v->shear_speed);
133 } else {
135 }
136
137 logger::raw_ln("--- Bondaries config config (deduced)");
138
139 logger::raw_ln("-------------");
140 }
141};
142
143namespace shammodels::sph {
144
151 template<class Tvec>
152 inline void to_json(nlohmann::json &j, const BCConfig<Tvec> &p) {
153 using T = BCConfig<Tvec>;
154
155 using Free = typename T::Free;
156 using Periodic = typename T::Periodic;
157 using ShearingPeriodic = typename T::ShearingPeriodic;
158
159 // Write the config type into the JSON object
160 if (const Free *v = std::get_if<Free>(&p.config)) {
161 j = {
162 {"bc_type", "free"},
163 };
164 } else if (const Periodic *v = std::get_if<Periodic>(&p.config)) {
165 j = {
166 {"bc_type", "periodic"},
167 };
168 } else if (const ShearingPeriodic *v = std::get_if<ShearingPeriodic>(&p.config)) {
169 // Write the shear base, direction, and speed into the JSON object
170 j = {
171 {"bc_type", "shearing_periodic"},
172 {"shear_base", v->shear_base},
173 {"shear_dir", v->shear_dir},
174 {"shear_speed", v->shear_speed},
175 };
176 } else {
178 }
179 }
180
187 template<class Tvec>
188 inline void from_json(const nlohmann::json &j, BCConfig<Tvec> &p) {
189 using T = BCConfig<Tvec>;
190
191 using Tscal = shambase::VecComponent<Tvec>;
192
193 // Check if the JSON object contains the "bc_type" field
194 if (!j.contains("bc_type")) {
195 shambase::throw_with_loc<std::runtime_error>("no field eos_type is found in this json");
196 }
197
198 // Read the config type from the JSON object
199 std::string bc_type;
200 j.at("bc_type").get_to(bc_type);
201
202 using Free = typename T::Free;
203 using Periodic = typename T::Periodic;
204 using ShearingPeriodic = typename T::ShearingPeriodic;
205
206 // Set the BCConfig based on the config type
207 if (bc_type == "free") {
208 p.set_free();
209 } else if (bc_type == "periodic") {
210 p.set_periodic();
211 } else if (bc_type == "shearing_periodic") {
212 p.set_shearing_periodic(
213 j.at("shear_base").get<i32_3>(),
214 j.at("shear_dir").get<i32_3>(),
215 j.at("speed").get<Tscal>());
216 } else {
218 }
219 }
220
221} // namespace shammodels::sph
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.
Definition EOSConfig.cpp:43
void from_json(const nlohmann::json &j, EOSConfig< Tvec > &p)
Deserializes an EOSConfig<Tvec> from a JSON object.
Free boundary condition.
Definition BCConfig.hpp:52
Tscal expand_tolerance
The tolerance for the box expansion.
Definition BCConfig.hpp:59
Periodic boundary condition.
Definition BCConfig.hpp:65
Shearing periodic boundary condition.
Definition BCConfig.hpp:73
Tscal shear_speed
The speed of the shear.
Definition BCConfig.hpp:88
i32_3 shear_dir
The direction of the shear.
Definition BCConfig.hpp:83
i32_3 shear_base
The base of the scalar product to define the number of shearing periodicity to be applied.
Definition BCConfig.hpp:78
Boundary conditions configuration.
Definition BCConfig.hpp:40
void print_status()
Prints the current boundary condition configuration to the logger.
Definition BCConfig.hpp:121
static constexpr u32 dim
Number of dimensions of the problem.
Definition BCConfig.hpp:45
void set_periodic()
Set the boundary condition to periodic boundaries.
Definition BCConfig.hpp:101
void set_free()
Set the boundary condition to free boundaries.
Definition BCConfig.hpp:98
Variant config
The actual configuration (default to free boundaries)
Definition BCConfig.hpp:95
std::variant< Free, Periodic, ShearingPeriodic > Variant
Variant of all types of artificial viscosity possible.
Definition BCConfig.hpp:92
void set_shearing_periodic(i32_3 shear_base, i32_3 shear_dir, Tscal speed)
Set the boundary condition to shearing periodic boundaries.
Definition BCConfig.hpp:111
shambase::VecComponent< Tvec > Tscal
Type of the components of the vector of coordinates.
Definition BCConfig.hpp:43
Contains functions for converting between SYCL vector types and C++ standard library array types.