25#include <nlohmann/json.hpp>
34 using Tscal = shambase::VecComponent<Tvec>;
35 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
61 struct ShearingBoxForce {
62 i32_3 shear_base = {1, 0, 0};
63 i32_3 shear_dir = {0, 1, 0};
69 inline Tscal shear_speed(Tscal box_length) {
return q * Omega_0 * box_length; }
71 ShearingBoxForce() =
default;
72 ShearingBoxForce(Tscal Omega_0, Tscal eta, Tscal q)
73 : Omega_0(Omega_0), eta(eta), q(q) {};
74 ShearingBoxForce(i32_3 shear_base, i32_3 shear_dir, Tscal Omega_0, Tscal eta, Tscal q)
75 : shear_base(shear_base), shear_dir(shear_dir), Omega_0(Omega_0), eta(eta), q(q) {};
89 using VariantForce = std::variant<
102 using Tscal = shambase::VecComponent<Tvec>;
103 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
112 std::vector<ExtForceVariant<Tvec>> ext_forces;
114 inline void add_point_mass(Tscal central_mass, Tscal Racc) {
118 inline void add_paczynski_wiita(Tscal central_mass, Tvec central_pos, Tscal Racc) {
122 inline void add_lense_thirring(
123 Tscal central_mass, Tscal Racc, Tscal a_spin, Tvec dir_spin) {
124 if (sham::abs(sycl::length(dir_spin) - 1) > 1e-8) {
126 "the sping direction should be a unit vector");
128 ext_forces.push_back(
141 inline void add_vertical_disc_potential(Tscal central_mass, Tscal R0) {
145 inline void add_velocity_dissipation(Tscal eta) {
146 ext_forces.push_back(ExtForceVariant<Tvec>{VelocityDissipation{eta}});
157 using PointMass =
typename T::PointMass;
158 using PN_PW =
typename T::PN_PW;
159 using LenseThirring =
typename T::LenseThirring;
160 using ShearingBoxForce =
typename T::ShearingBoxForce;
161 using VerticalDiscPotential =
typename T::VerticalDiscPotential;
162 using VelocityDissipation =
typename T::VelocityDissipation;
164 if (
const PointMass *v = std::get_if<PointMass>(&p.val)) {
166 {
"force_type",
"point_mass"}, {
"central_mass", v->central_mass}, {
"Racc", v->Racc}};
168 }
else if (
const PN_PW *v = std::get_if<PN_PW>(&p.val)) {
170 = {{
"force_type",
"paczynski_wiita"},
171 {
"central_mass", v->central_mass},
172 {
"central_pos", v->central_pos},
174 }
else if (
const LenseThirring *v = std::get_if<LenseThirring>(&p.val)) {
176 {
"force_type",
"lense_thirring"},
177 {
"central_mass", v->central_mass},
179 {
"a_spin", v->a_spin},
180 {
"dir_spin", v->dir_spin},
182 }
else if (
const ShearingBoxForce *v = std::get_if<ShearingBoxForce>(&p.val)) {
184 {
"force_type",
"shearing_box_force"},
185 {
"shear_base", v->shear_base},
186 {
"shear_dir", v->shear_dir},
187 {
"Omega_0", v->Omega_0},
191 }
else if (
const VerticalDiscPotential *v = std::get_if<VerticalDiscPotential>(&p.val)) {
193 = {{
"force_type",
"vertical_disc_potential"},
194 {
"central_mass", v->central_mass},
196 }
else if (
const VelocityDissipation *v = std::get_if<VelocityDissipation>(&p.val)) {
197 j = {{
"force_type",
"velocity_dissipation"}, {
"eta", v->eta}};
205 using Tscal = shambase::VecComponent<Tvec>;
208 if (!j.contains(
"force_type")) {
212 std::string force_type;
213 j.at(
"force_type").get_to(force_type);
215 using PointMass =
typename T::PointMass;
216 using PN_PW =
typename T::PN_PW;
217 using LenseThirring =
typename T::LenseThirring;
218 using ShearingBoxForce =
typename T::ShearingBoxForce;
219 using VerticalDiscPotential =
typename T::VerticalDiscPotential;
220 using VelocityDissipation =
typename T::VelocityDissipation;
222 if (force_type ==
"point_mass") {
224 j.at(
"central_mass").get<Tscal>(),
225 j.at(
"Racc").get<Tscal>(),
227 }
else if (force_type ==
"paczynski_wiita") {
229 j.at(
"central_mass").get<Tscal>(),
230 j.at(
"central_pos").get<Tvec>(),
231 j.at(
"Racc").get<Tscal>(),
233 }
else if (force_type ==
"lense_thirring") {
234 p.val = LenseThirring{
235 j.at(
"central_mass").get<Tscal>(),
236 j.at(
"Racc").get<Tscal>(),
237 j.at(
"a_spin").get<Tscal>(),
238 j.at(
"dir_spin").get<Tvec>(),
240 }
else if (force_type ==
"shearing_box_force") {
241 p.val = ShearingBoxForce{
242 j.at(
"shear_base").get<i32_3>(),
243 j.at(
"shear_dir").get<i32_3>(),
244 j.at(
"Omega_0").get<Tscal>(),
245 j.at(
"eta").get<Tscal>(),
246 j.at(
"q").get<Tscal>(),
248 }
else if (force_type ==
"vertical_disc_potential") {
249 p.val = VerticalDiscPotential{
250 j.at(
"central_mass").get<Tscal>(),
251 j.at(
"R0").get<Tscal>(),
253 }
else if (force_type ==
"velocity_dissipation") {
254 p.val = VelocityDissipation{j.at(
"eta").get<Tscal>()};
264 j = {{
"force_list", p.ext_forces}};
271 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 stone2010_shear_box.
f = -GMy / sqrt(R0^2 + y^2)
Contains functions for converting between SYCL vector types and C++ standard library array types.