LaneEmdenStar.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <limits>
7 
9 #include "Evolution/Systems/NewtonianEuler/Sources/LaneEmdenGravitationalField.hpp"
10 #include "Evolution/Systems/NewtonianEuler/Tags.hpp"
11 #include "Options/Options.hpp"
12 #include "PointwiseFunctions/AnalyticSolutions/AnalyticSolution.hpp"
13 #include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
14 #include "PointwiseFunctions/Hydro/EquationsOfState/PolytropicFluid.hpp" // IWYU pragma: keep
15 #include "Utilities/TMPL.hpp"
16 #include "Utilities/TaggedTuple.hpp"
17 
18 /// \cond
19 namespace PUP {
20 class er; // IWYU pragma: keep
21 } // namespace PUP
22 /// \endcond
23 
24 // IWYU pragma: no_include <pup.h>
25 
26 namespace NewtonianEuler {
27 namespace Solutions {
28 
29 /*!
30  * \brief A static spherically symmetric star in Newtonian gravity
31  *
32  * The solution for a static, spherically-symmetric star in 3 dimensions, found
33  * by solving the Lane-Emden equation \cite Chandrasekhar1939
34  * \cite Shapiro1983 .
35  * The Lane-Emden equation has closed-form solutions for certain equations of
36  * state; this class implements the solution for a polytropic fluid with
37  * polytropic exponent \f$\Gamma=2\f$ (i.e., with polytropic index \f$n=1\f$).
38  * The solution is returned in units where \f$G=1\f$, with \f$G\f$ the
39  * gravitational constant.
40  *
41  * The radius and mass of the star are determined by the polytropic constant
42  * \f$\kappa\f$ and central density \f$\rho_c\f$.
43  * The radius is \f$R = \pi \alpha\f$,
44  * and the mass is \f$M = 4 \pi^2 \alpha^3 \rho_c\f$,
45  * where \f$\alpha = \sqrt{\kappa / (2 \pi)}\f$ and \f$G=1\f$.
46  */
47 class LaneEmdenStar : public MarkAsAnalyticSolution {
48  public:
51 
52  /// The central mass density of the star.
54  using type = double;
55  static constexpr OptionString help = {
56  "The central mass density of the star."};
57  static type lower_bound() noexcept { return 0.; }
58  };
59 
60  /// The polytropic constant of the polytropic fluid.
62  using type = double;
63  static constexpr OptionString help = {
64  "The polytropic constant of the fluid."};
65  static type lower_bound() noexcept { return 0.; }
66  };
67 
68  using options = tmpl::list<CentralMassDensity, PolytropicConstant>;
69 
70  static constexpr OptionString help = {
71  "A static, spherically-symmetric star in Newtonian gravity, found by\n"
72  "solving the Lane-Emden equations, with a given central density and\n"
73  "polytropic fluid. The fluid has polytropic index 1, but the polytropic\n"
74  "constant is specifiable"};
75 
76  LaneEmdenStar() = default;
77  LaneEmdenStar(const LaneEmdenStar& /*rhs*/) = delete;
78  LaneEmdenStar& operator=(const LaneEmdenStar& /*rhs*/) = delete;
79  LaneEmdenStar(LaneEmdenStar&& /*rhs*/) noexcept = default;
80  LaneEmdenStar& operator=(LaneEmdenStar&& /*rhs*/) noexcept = default;
81  ~LaneEmdenStar() = default;
82 
83  LaneEmdenStar(double central_mass_density,
84  double polytropic_constant) noexcept;
85 
86  /// Retrieve a collection of variables at `(x, t)`
87  template <typename DataType, typename... Tags>
88  tuples::TaggedTuple<Tags...> variables(const tnsr::I<DataType, 3>& x,
89  const double /*t*/,
90  tmpl::list<Tags...> /*meta*/) const
91  noexcept {
92  const auto mass_density = precompute_mass_density(x);
93  return {tuples::get<Tags>(variables(tmpl::list<Tags>{}, mass_density))...};
94  }
95 
96  /// \brief Compute the gravitational field for the corresponding source term,
97  /// LaneEmdenGravitationalField.
98  ///
99  /// The result is the vector-field giving the acceleration due to gravity
100  /// that is felt by a test particle.
101  template <typename DataType>
102  tnsr::I<DataType, 3> gravitational_field(const tnsr::I<DataType, 3>& x) const
103  noexcept;
104 
105  const EquationsOfState::PolytropicFluid<false>& equation_of_state() const
106  noexcept {
107  return equation_of_state_;
108  }
109 
110  const Sources::LaneEmdenGravitationalField& source_term() const noexcept {
111  return source_term_;
112  }
113 
114  // clang-tidy: no runtime references
115  void pup(PUP::er& /*p*/) noexcept; // NOLINT
116 
117  private:
118  template <typename DataType>
119  Scalar<DataType> precompute_mass_density(const tnsr::I<DataType, 3>& x) const
120  noexcept;
121 
122  template <typename DataType>
124  tmpl::list<Tags::MassDensity<DataType>> /*meta*/,
125  const Scalar<DataType>& mass_density) const noexcept;
126 
127  template <typename DataType>
129  tmpl::list<Tags::Velocity<DataType, 3>> /*meta*/,
130  const Scalar<DataType>& mass_density) const noexcept;
131 
132  template <typename DataType>
134  tmpl::list<Tags::Pressure<DataType>> /*meta*/,
135  const Scalar<DataType>& mass_density) const noexcept;
136 
137  template <typename DataType>
139  tmpl::list<Tags::SpecificInternalEnergy<DataType>> /*meta*/,
140  const Scalar<DataType>& mass_density) const noexcept;
141 
142  friend bool operator==(const LaneEmdenStar& lhs,
143  const LaneEmdenStar& rhs) noexcept;
144 
145  double central_mass_density_ = std::numeric_limits<double>::signaling_NaN();
146  double polytropic_constant_ = std::numeric_limits<double>::signaling_NaN();
147  EquationsOfState::PolytropicFluid<false> equation_of_state_{};
148  Sources::LaneEmdenGravitationalField source_term_{};
149 };
150 
151 bool operator!=(const LaneEmdenStar& lhs, const LaneEmdenStar& rhs) noexcept;
152 
153 } // namespace Solutions
154 } // namespace NewtonianEuler
NewtonianEuler::Solutions::LaneEmdenStar::gravitational_field
tnsr::I< DataType, 3 > gravitational_field(const tnsr::I< DataType, 3 > &x) const noexcept
Compute the gravitational field for the corresponding source term, LaneEmdenGravitationalField.
Definition: LaneEmdenStar.cpp:41
NewtonianEuler::Solutions::LaneEmdenStar::PolytropicConstant
The polytropic constant of the polytropic fluid.
Definition: LaneEmdenStar.hpp:61
std::rel_ops::operator!=
T operator!=(T... args)
Options.hpp
NewtonianEuler
Items related to evolving the Newtonian Euler system.
Definition: EvolveNewtonianEulerFwd.hpp:8
NewtonianEuler::Solutions::LaneEmdenStar::variables
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataType, 3 > &x, const double, tmpl::list< Tags... >) const noexcept
Retrieve a collection of variables at (x, t)
Definition: LaneEmdenStar.hpp:88
EquationsOfState::PolytropicFluid< false >
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
limits
Tensor.hpp
NewtonianEuler::Sources::LaneEmdenGravitationalField
Source giving the acceleration due to gravity in the spherical, Newtonian Lane-Emden star solution.
Definition: LaneEmdenGravitationalField.hpp:72
NewtonianEuler::Solutions::LaneEmdenStar
A static spherically symmetric star in Newtonian gravity.
Definition: LaneEmdenStar.hpp:47
OptionString
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:30
TMPL.hpp
NewtonianEuler::Solutions::LaneEmdenStar::CentralMassDensity
The central mass density of the star.
Definition: LaneEmdenStar.hpp:53