24#include <nlohmann/json.hpp>
33 using Tscal = shambase::VecComponent<Tvec>;
55 i32_3 shear_base = {1, 0, 0};
56 i32_3 shear_dir = {0, 1, 0};
62 inline Tscal shear_speed(Tscal box_length) {
return q * Omega_0 * box_length; }
66 : Omega_0(Omega_0), eta(eta), q(q) {};
67 ShearingBoxForce(i32_3 shear_base, i32_3 shear_dir, Tscal Omega_0, Tscal eta, Tscal q)
68 : shear_base(shear_base), shear_dir(shear_dir), Omega_0(Omega_0), eta(eta), q(q) {};
82 using VariantForce = std::variant<
94 using Tscal = shambase::VecComponent<Tvec>;
103 std::vector<ExtForceVariant<Tvec>> ext_forces;
105 inline void add_point_mass(Tscal central_mass, Tscal Racc) {
109 inline void add_lense_thirring(
110 Tscal central_mass, Tscal Racc, Tscal a_spin, Tvec dir_spin) {
111 if (sham::abs(sycl::length(dir_spin) - 1) > 1e-8) {
113 "the sping direction should be a unit vector");
115 ext_forces.push_back(
128 inline void add_vertical_disc_potential(Tscal central_mass, Tscal R0) {
132 inline void add_velocity_dissipation(Tscal eta) {
133 ext_forces.push_back(ExtForceVariant<Tvec>{VelocityDissipation{eta}});
141 inline void to_json(nlohmann::json &j,
const ExtForceVariant<Tvec> &p) {
142 using T = ExtForceVariant<Tvec>;
144 using PointMass =
typename T::PointMass;
145 using LenseThirring =
typename T::LenseThirring;
146 using ShearingBoxForce =
typename T::ShearingBoxForce;
147 using VerticalDiscPotential =
typename T::VerticalDiscPotential;
148 using VelocityDissipation =
typename T::VelocityDissipation;
150 if (
const PointMass *v = std::get_if<PointMass>(&p.val)) {
152 {
"force_type",
"point_mass"}, {
"central_mass", v->central_mass}, {
"Racc", v->Racc}};
153 }
else if (
const LenseThirring *v = std::get_if<LenseThirring>(&p.val)) {
155 {
"force_type",
"lense_thirring"},
156 {
"central_mass", v->central_mass},
158 {
"a_spin", v->a_spin},
159 {
"dir_spin", v->dir_spin},
161 }
else if (
const ShearingBoxForce *v = std::get_if<ShearingBoxForce>(&p.val)) {
163 {
"force_type",
"shearing_box_force"},
164 {
"shear_base", v->shear_base},
165 {
"shear_dir", v->shear_dir},
166 {
"Omega_0", v->Omega_0},
170 }
else if (
const VerticalDiscPotential *v = std::get_if<VerticalDiscPotential>(&p.val)) {
172 = {{
"force_type",
"vertical_disc_potential"},
173 {
"central_mass", v->central_mass},
175 }
else if (
const VelocityDissipation *v = std::get_if<VelocityDissipation>(&p.val)) {
176 j = {{
"force_type",
"velocity_dissipation"}, {
"eta", v->eta}};
183 inline void from_json(
const nlohmann::json &j, ExtForceVariant<Tvec> &p) {
184 using Tscal = shambase::VecComponent<Tvec>;
185 using T = ExtForceVariant<Tvec>;
187 if (!j.contains(
"force_type")) {
191 std::string force_type;
192 j.at(
"force_type").get_to(force_type);
194 using PointMass =
typename T::PointMass;
195 using LenseThirring =
typename T::LenseThirring;
196 using ShearingBoxForce =
typename T::ShearingBoxForce;
197 using VerticalDiscPotential =
typename T::VerticalDiscPotential;
198 using VelocityDissipation =
typename T::VelocityDissipation;
200 if (force_type ==
"point_mass") {
202 j.at(
"central_mass").get<Tscal>(),
203 j.at(
"Racc").get<Tscal>(),
205 }
else if (force_type ==
"lense_thirring") {
206 p.val = LenseThirring{
207 j.at(
"central_mass").get<Tscal>(),
208 j.at(
"Racc").get<Tscal>(),
209 j.at(
"a_spin").get<Tscal>(),
210 j.at(
"dir_spin").get<Tvec>(),
212 }
else if (force_type ==
"shearing_box_force") {
213 p.val = ShearingBoxForce{
214 j.at(
"shear_base").get<i32_3>(),
215 j.at(
"shear_dir").get<i32_3>(),
216 j.at(
"Omega_0").get<Tscal>(),
217 j.at(
"eta").get<Tscal>(),
218 j.at(
"q").get<Tscal>(),
220 }
else if (force_type ==
"vertical_disc_potential") {
221 p.val = VerticalDiscPotential{
222 j.at(
"central_mass").get<Tscal>(),
223 j.at(
"R0").get<Tscal>(),
225 }
else if (force_type ==
"velocity_dissipation") {
226 p.val = VelocityDissipation{j.at(
"eta").get<Tscal>()};
233 inline void to_json(nlohmann::json &j,
const ExtForceConfig<Tvec> &p) {
234 using T = ExtForceConfig<Tvec>;
236 j = {{
"force_list", p.ext_forces}};
240 inline void from_json(
const nlohmann::json &j, ExtForceConfig<Tvec> &p) {
241 using T = ExtForceConfig<Tvec>;
243 j.at(
"force_list").get_to(p.ext_forces);
std::uint32_t u32
32 bit unsigned integer
This header file contains utility functions related to exception handling in the code.
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.
void add_shearing_box(Tscal Omega_0, Tscal eta, Tscal q)
Shearing box forces as in athena .
f = -GMy / sqrt(R0^2 + y^2)
Contains functions for converting between SYCL vector types and C++ standard library array types.