Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 :
8 : #include "DataStructures/Tensor/Tensor.hpp"
9 : #include "Evolution/Systems/NewtonianMhd/Sources/Source.hpp"
10 : #include "Evolution/Systems/NewtonianMhd/TagsDeclarations.hpp"
11 : #include "Options/String.hpp"
12 : #include "Utilities/TMPL.hpp"
13 :
14 : /// \cond
15 : class DataVector;
16 :
17 : namespace NewtonianMhd::Solutions {
18 : struct LaneEmdenStar;
19 : } // namespace NewtonianMhd::Solutions
20 :
21 : namespace PUP {
22 : class er;
23 : } // namespace PUP
24 :
25 : namespace Tags {
26 : template <typename SolutionType>
27 : struct AnalyticSolution;
28 : } // namespace Tags
29 :
30 : namespace domain::Tags {
31 : template <size_t Dim, typename Frame>
32 : struct Coordinates;
33 : } // namespace domain::Tags
34 :
35 : namespace gsl {
36 : template <typename T>
37 : class not_null;
38 : } // namespace gsl
39 : /// \endcond
40 :
41 : namespace NewtonianMhd::Sources {
42 :
43 : /*!
44 : * \brief Source giving the acceleration due to gravity in the spherical,
45 : * Newtonian Lane-Emden star solution.
46 : *
47 : * The gravitational field \f$g^i\f$ enters the NewtonianMhd system as source
48 : * terms for the conserved momentum and energy:
49 : *
50 : * \f{align*}
51 : * \partial_t S^i + \partial_j F^{j}(S^i) &= S(S^i) = \rho g^i
52 : * \partial_t e + \partial_j F^{j}(e) &= S(e) = S_i g^i,
53 : * \f}
54 : *
55 : * where \f$S^i\f$ is the conserved momentum density, \f$e\f$ is the conserved
56 : * energy, \f$F^{j}(u)\f$ is the flux of the conserved quantity \f$u\f$, and
57 : * \f$\rho\f$ is the fluid mass density.
58 : *
59 : * \note This source is specialized to the Lane-Emden solution because it
60 : * queries a LaneEmdenStar analytic solution for the gravitational field that
61 : * generates the fluid acceleration. This source does *not* integrate the fluid
62 : * density to compute a self-consistent gravitational field (i.e., as if one
63 : * were solving a coupled Euler + Poisson system).
64 : */
65 1 : class LaneEmdenGravitationalField : public Source<3> {
66 : public:
67 : /// The central mass density of the star.
68 1 : struct CentralMassDensity {
69 0 : using type = double;
70 0 : static constexpr Options::String help = {
71 : "The central mass density of the star."};
72 0 : static type lower_bound() { return 0.; }
73 : };
74 :
75 : /// The polytropic constant of the polytropic fluid.
76 1 : struct PolytropicConstant {
77 0 : using type = double;
78 0 : static constexpr Options::String help = {
79 : "The polytropic constant of the fluid."};
80 0 : static type lower_bound() { return 0.; }
81 : };
82 :
83 0 : using options = tmpl::list<CentralMassDensity, PolytropicConstant>;
84 :
85 0 : static constexpr Options::String help = {
86 : "The gravitational field corresponding to a static, "
87 : "spherically-symmetric star in Newtonian gravity, found by "
88 : "solving the Lane-Emden equations, with a given central density and "
89 : "polytropic fluid. The fluid has polytropic index 1, but the polytropic "
90 : "constant is specifiable"};
91 :
92 0 : LaneEmdenGravitationalField(double central_mass_density,
93 : double polytropic_constant);
94 :
95 0 : LaneEmdenGravitationalField() = default;
96 0 : LaneEmdenGravitationalField(const LaneEmdenGravitationalField& /*rhs*/) =
97 : default;
98 0 : LaneEmdenGravitationalField& operator=(
99 : const LaneEmdenGravitationalField& /*rhs*/) = default;
100 0 : LaneEmdenGravitationalField(LaneEmdenGravitationalField&& /*rhs*/) = default;
101 0 : LaneEmdenGravitationalField& operator=(
102 : LaneEmdenGravitationalField&& /*rhs*/) = default;
103 0 : ~LaneEmdenGravitationalField() override = default;
104 :
105 : /// \cond
106 : explicit LaneEmdenGravitationalField(CkMigrateMessage* msg);
107 : using PUP::able::register_constructor;
108 : WRAPPED_PUPable_decl_template(LaneEmdenGravitationalField);
109 : /// \endcond
110 :
111 : // NOLINTNEXTLINE(google-runtime-references)
112 0 : void pup(PUP::er& p) override;
113 :
114 0 : auto get_clone() const -> std::unique_ptr<Source> override;
115 :
116 0 : void operator()(
117 : gsl::not_null<Scalar<DataVector>*> source_mass_density_cons,
118 : gsl::not_null<tnsr::I<DataVector, 3>*> source_momentum_density,
119 : gsl::not_null<Scalar<DataVector>*> source_energy_density,
120 : const Scalar<DataVector>& mass_density_cons,
121 : const tnsr::I<DataVector, 3>& momentum_density,
122 : const Scalar<DataVector>& energy_density,
123 : const tnsr::I<DataVector, 3>& velocity,
124 : const Scalar<DataVector>& pressure,
125 : const Scalar<DataVector>& specific_internal_energy,
126 : const EquationsOfState::EquationOfState<false, 2>& eos,
127 : const tnsr::I<DataVector, 3>& coords, double time) const override;
128 :
129 : private:
130 0 : tnsr::I<DataVector, 3> gravitational_field(
131 : const tnsr::I<DataVector, 3>& x) const;
132 :
133 0 : double central_mass_density_ = std::numeric_limits<double>::signaling_NaN();
134 0 : double polytropic_constant_ = std::numeric_limits<double>::signaling_NaN();
135 : };
136 : } // namespace NewtonianMhd::Sources
|