25#include <nlohmann/json.hpp>
43 using Tscal = shambase::VecComponent<Tvec>;
53 Tvec pos = Tvec(0.5, 0.5, 0.5);
54 Tscal epsilon_soft = 0.05;
57 using Variant = std::variant<ConstantGravity, PointMassGravity>;
59 std::vector<Variant> ext_forces;
66 inline void add_constant_gravity(Tvec g) { ext_forces.push_back(ConstantGravity{g}); }
67 inline void add_point_mass_gravity(Tscal mass, Tvec pos, Tscal epsilon_soft) {
68 if (!(std::isfinite(epsilon_soft) && epsilon_soft > 0)) {
70 "point mass gravity: epsilon_soft must be finite and > 0");
75 inline bool is_coordinates_needed()
const {
76 return std::any_of(ext_forces.begin(), ext_forces.end(), [](
const Variant &f) {
77 return std::holds_alternative<PointMassGravity>(f);
81 inline bool has_ext_forces()
const {
return !ext_forces.empty(); }
88 nlohmann::json force_list = nlohmann::json::array();
89 for (
const auto &var_force : p.ext_forces) {
92 [&](
const typename EF::ConstantGravity &cfg) {
94 nlohmann::json{{
"force_type",
"constant_gravity"}, {
"g", cfg.g}});
96 [&](
const typename EF::PointMassGravity &cfg) {
99 {
"force_type",
"point_mass_gravity"},
102 {
"epsilon_soft", cfg.epsilon_soft}});
108 j = nlohmann::json{{
"force_list", force_list}, {
"coupling", p.coupling}};
113 p.ext_forces.clear();
117 if (j.contains(
"coupling")) {
118 j.at(
"coupling").get_to(p.coupling);
121 for (
const auto &jforce : j.at(
"force_list")) {
122 const std::string force_type = jforce.at(
"force_type").get<std::string>();
123 using Tscal = shambase::VecComponent<Tvec>;
124 if (force_type ==
"constant_gravity") {
125 p.add_constant_gravity(jforce.at(
"g").get<Tvec>());
126 }
else if (force_type ==
"point_mass_gravity") {
127 p.add_point_mass_gravity(
128 jforce.at(
"mass").get<Tscal>(),
129 jforce.at(
"pos").get<Tvec>(),
130 jforce.at(
"epsilon_soft").get<Tscal>());
133 "Invalid external force type: " + force_type);
External forces time coupling enum + json serialization/deserialization.
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.
overloaded(Ts...) -> overloaded< Ts... >
Deduction guide so overloaded{lambda1, lambda2, ...} deduces Ts... from the lambdas.
namespace for the basegodunov model
ExtForceCoupling
Time quadrature used to couple the external forces source term to the solver.
Constant gravitational acceleration g.
List of the external forces applied to the gas.
ExtForceCoupling coupling
Time quadrature of the external forces source term.
Contains functions for converting between SYCL vector types and C++ standard library array types.