SmoothFlow.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <limits>
8 #include <pup.h>
9 
11 #include "Options/Options.hpp"
12 #include "PointwiseFunctions/AnalyticSolutions/AnalyticSolution.hpp"
13 #include "PointwiseFunctions/AnalyticSolutions/GeneralRelativity/Minkowski.hpp"
14 #include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
15 #include "PointwiseFunctions/Hydro/Tags.hpp"
16 #include "Utilities/MakeArray.hpp"
17 #include "Utilities/TMPL.hpp"
19 
20 namespace RelativisticEuler {
21 namespace Solutions {
22 
23 /*!
24  * \brief Smooth wave propagating in Minkowski spacetime.
25  *
26  * The relativistic Euler equations in Minkowski spacetime accept a
27  * solution with constant pressure and uniform spatial velocity provided
28  * that the rest mass density satisfies the advection equation
29  *
30  * \f{align*}
31  * \partial_t\rho + v^i\partial_i\rho = 0,
32  * f}
33  *
34  * and the specific internal energy is a function of the rest mass density only,
35  * \f$\epsilon = \epsilon(\rho)\f$. For testing purposes, this class implements
36  * this solution for the case where \f$\rho\f$ is a sine wave. The user
37  * specifies the mean flow velocity of the fluid, the wavevector of the density
38  * profile, and the amplitude \f$A\f$ of the density profile. In Cartesian
39  * coordinates \f$(x, y, z)\f$, and using dimensionless units, the primitive
40  * variables at a given time \f$t\f$ are then
41  *
42  * \f{align*}
43  * \rho(\vec{x},t) &= 1 + A \sin(\vec{k}\cdot(\vec{x} - \vec{v}t)) \\
44  * \vec{v}(\vec{x},t) &= [v_x, v_y, v_z]^{T},\\
45  * P(\vec{x},t) &= P, \\
46  * \epsilon(\vec{x}, t) &= \frac{P}{(\gamma - 1)\rho}\\
47  * \f}
48  *
49  * where we have assumed \f$\epsilon\f$ and \f$\rho\f$ to be related through an
50  * equation mathematically equivalent to the equation of state of an ideal gas,
51  * where the pressure is held constant.
52  */
53 template <size_t Dim>
54 class SmoothFlow : virtual public MarkAsAnalyticSolution {
55  public:
57 
58  /// The mean flow velocity.
59  struct MeanVelocity {
61  static constexpr OptionString help = {"The mean flow velocity."};
62  };
63 
64  /// The wave vector of the profile.
65  struct WaveVector {
67  static constexpr OptionString help = {"The wave vector of the profile."};
68  };
69 
70  /// The constant pressure throughout the fluid.
71  struct Pressure {
72  using type = double;
73  static constexpr OptionString help = {
74  "The constant pressure throughout the fluid."};
75  static type lower_bound() noexcept { return 0.0; }
76  };
77 
78  /// The adiabatic index for the ideal fluid.
79  struct AdiabaticIndex {
80  using type = double;
81  static constexpr OptionString help = {
82  "The adiabatic index for the ideal fluid."};
83  static type lower_bound() noexcept { return 1.0; }
84  };
85 
86  /// The perturbation amplitude of the rest mass density of the fluid.
88  using type = double;
89  static constexpr OptionString help = {
90  "The perturbation size of the rest mass density."};
91  static type lower_bound() noexcept { return -1.0; }
92  static type upper_bound() noexcept { return 1.0; }
93  };
94 
95  using options = tmpl::list<MeanVelocity, WaveVector, Pressure, AdiabaticIndex,
97  static constexpr OptionString help = {"Smooth flow in Minkowski spacetime."};
98 
99  SmoothFlow() = default;
100  SmoothFlow(const SmoothFlow& /*rhs*/) = delete;
101  SmoothFlow& operator=(const SmoothFlow& /*rhs*/) = delete;
102  SmoothFlow(SmoothFlow&& /*rhs*/) noexcept = default;
103  SmoothFlow& operator=(SmoothFlow&& /*rhs*/) noexcept = default;
104  ~SmoothFlow() = default;
105 
106  SmoothFlow(std::array<double, Dim> mean_velocity,
107  std::array<double, Dim> wavevector, double pressure,
108  double adiabatic_index, double perturbation_size) noexcept;
109 
110  explicit SmoothFlow(CkMigrateMessage* /*unused*/) noexcept {}
111 
112  // @{
113  /// Retrieve hydro variable at `(x, t)`
114  template <typename DataType>
115  auto variables(
116  const tnsr::I<DataType, Dim>& x, double t,
117  tmpl::list<hydro::Tags::RestMassDensity<DataType>> /*meta*/) const
119 
120  template <typename DataType>
121  auto variables(
122  const tnsr::I<DataType, Dim>& x, double t,
123  tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>> /*meta*/) const
124  noexcept
126 
127  template <typename DataType>
128  auto variables(const tnsr::I<DataType, Dim>& x, double /*t*/,
129  tmpl::list<hydro::Tags::Pressure<DataType>> /*meta*/) const
131 
132  template <typename DataType>
133  auto variables(const tnsr::I<DataType, Dim>& x, double /*t*/,
134  tmpl::list<hydro::Tags::SpatialVelocity<
135  DataType, Dim, Frame::Inertial>> /*meta*/) const noexcept
138 
139  template <typename DataType>
140  auto variables(
141  const tnsr::I<DataType, Dim>& x, double /*t*/,
142  tmpl::list<hydro::Tags::LorentzFactor<DataType>> /*meta*/) const noexcept
144 
145  template <typename DataType>
146  auto variables(
147  const tnsr::I<DataType, Dim>& x, double t,
148  tmpl::list<hydro::Tags::SpecificEnthalpy<DataType>> /*meta*/) const
150  // @}
151 
152  /// Retrieve a collection of hydro variables at `(x, t)`
153  template <typename DataType, typename... Tags>
154  tuples::TaggedTuple<Tags...> variables(const tnsr::I<DataType, Dim>& x,
155  double t,
156  tmpl::list<Tags...> /*meta*/) const
157  noexcept {
158  static_assert(sizeof...(Tags) > 1,
159  "The generic template will recurse infinitely if only one "
160  "tag is being retrieved.");
161  return {get<Tags>(variables(x, t, tmpl::list<Tags>{}))...};
162  }
163 
164  /// Retrieve the metric variables
165  template <typename DataType, typename Tag>
166  tuples::TaggedTuple<Tag> variables(const tnsr::I<DataType, Dim>& x, double t,
167  tmpl::list<Tag> /*meta*/) const noexcept {
168  return background_spacetime_.variables(x, t, tmpl::list<Tag>{});
169  }
170 
171  // clang-tidy: no runtime references
172  void pup(PUP::er& /*p*/) noexcept; // NOLINT
173 
174  const EquationsOfState::IdealFluid<true>& equation_of_state() const noexcept {
175  return equation_of_state_;
176  }
177 
178  private:
179  template <size_t SpatialDim>
180  friend bool
181  operator==( // NOLINT (clang-tidy: readability-redundant-declaration)
182  const SmoothFlow<SpatialDim>& lhs,
183  const SmoothFlow<SpatialDim>& rhs) noexcept;
184 
185  // Computes the phase.
186  template <typename DataType>
187  DataType k_dot_x_minus_vt(const tnsr::I<DataType, Dim>& x, double t) const
188  noexcept;
189 
190  std::array<double, Dim> mean_velocity_ =
192  std::array<double, Dim> wavevector_ =
194  double pressure_ = std::numeric_limits<double>::signaling_NaN();
195  double adiabatic_index_ = std::numeric_limits<double>::signaling_NaN();
196  double perturbation_size_ = std::numeric_limits<double>::signaling_NaN();
197  // The angular frequency.
198  double k_dot_v_ = std::numeric_limits<double>::signaling_NaN();
199  EquationsOfState::IdealFluid<true> equation_of_state_{};
200  gr::Solutions::Minkowski<Dim> background_spacetime_{};
201 };
202 
203 template <size_t Dim>
204 bool operator!=(const SmoothFlow<Dim>& lhs,
205  const SmoothFlow<Dim>& rhs) noexcept;
206 } // namespace Solutions
207 } // namespace RelativisticEuler
The wave vector of the profile.
Definition: SmoothFlow.hpp:65
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataType, Dim > &x, double t, tmpl::list< Tags... >) const noexcept
Retrieve a collection of hydro variables at (x, t)
Definition: SmoothFlow.hpp:154
Defines class tuples::TaggedTuple.
The spatial velocity of the fluid, where . Here is the spatial part of the 4-velocity of the fluid...
Definition: Tags.hpp:157
The fluid pressure .
Definition: Tags.hpp:131
The specific internal energy .
Definition: Tags.hpp:190
T signaling_NaN(T... args)
The Minkowski solution for flat space in Dim spatial dimensions.
Definition: Minkowski.hpp:38
Defines function make_array.
Items related to evolving the relativistic Euler system.
Definition: Characteristics.hpp:21
Defines classes and functions for making classes creatable from input files.
tuples::TaggedTuple< Tag > variables(const tnsr::I< DataType, Dim > &x, double t, tmpl::list< Tag >) const noexcept
Retrieve the metric variables.
Definition: SmoothFlow.hpp:166
The perturbation amplitude of the rest mass density of the fluid.
Definition: SmoothFlow.hpp:87
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
The constant pressure throughout the fluid.
Definition: SmoothFlow.hpp:71
The adiabatic index for the ideal fluid.
Definition: SmoothFlow.hpp:79
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:273
Smooth wave propagating in Minkowski spacetime.
Definition: SmoothFlow.hpp:54
The Lorentz factor , where is the spatial velocity of the fluid.
Definition: Tags.hpp:69
Definition: DataBoxTag.hpp:29
Defines a list of useful type aliases for tensors.
Wraps the template metaprogramming library used (brigand)
The mean flow velocity.
Definition: SmoothFlow.hpp:59
The rest-mass density .
Definition: Tags.hpp:138
Definition: IndexType.hpp:44
The specific enthalpy .
Definition: Tags.hpp:183
auto variables(const tnsr::I< DataType, Dim > &x, double t, tmpl::list< hydro::Tags::RestMassDensity< DataType >>) const noexcept -> tuples::TaggedTuple< hydro::Tags::RestMassDensity< DataType >>
Retrieve hydro variable at (x, t)