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/Hydro/EquationsOfState/IdealFluid.hpp"
14 #include "PointwiseFunctions/Hydro/TagsDeclarations.hpp"
15 #include "Utilities/MakeArray.hpp"
16 #include "Utilities/TMPL.hpp"
17 #include "Utilities/TaggedTuple.hpp"
18 
19 namespace hydro::Solutions {
20 /*!
21  * \brief Smooth sinusoidal density wave.
22  *
23  * This is the generic infrastructure for a smooth flow solution that can be
24  * used by the hydro systems to avoid code duplication. The solution has a
25  * constant pressure and uniform spatial velocity provided that the rest mass
26  * density satisfies the advection equation
27  *
28  * \f{align*}{
29  * \partial_t\rho + v^i\partial_i\rho = 0,
30  * \f}
31  *
32  * and the specific internal energy is a function of the rest mass density only,
33  * \f$\epsilon = \epsilon(\rho)\f$. For testing purposes, this class implements
34  * this solution for the case where \f$\rho\f$ is a sine wave. The user
35  * specifies the mean flow velocity of the fluid, the wavevector of the density
36  * profile, and the amplitude \f$A\f$ of the density profile. In Cartesian
37  * coordinates \f$(x, y, z)\f$, and using dimensionless units, the primitive
38  * variables at a given time \f$t\f$ are then
39  *
40  * \f{align*}{
41  * \rho(\vec{x},t) &= 1 + A \sin(\vec{k}\cdot(\vec{x} - \vec{v}t)) \\
42  * \vec{v}(\vec{x},t) &= [v_x, v_y, v_z]^{T},\\
43  * P(\vec{x},t) &= P, \\
44  * \epsilon(\vec{x}, t) &= \frac{P}{(\gamma - 1)\rho}\\
45  * \f}
46  *
47  * where we have assumed \f$\epsilon\f$ and \f$\rho\f$ to be related through an
48  * equation mathematically equivalent to the equation of state of an ideal gas,
49  * where the pressure is held constant.
50  */
51 template <size_t Dim, bool IsRelativistic>
52 class SmoothFlow : virtual public MarkAsAnalyticSolution {
53  public:
54  SmoothFlow() = default;
55  SmoothFlow(const SmoothFlow& /*rhs*/) = delete;
56  SmoothFlow& operator=(const SmoothFlow& /*rhs*/) = delete;
57  SmoothFlow(SmoothFlow&& /*rhs*/) noexcept = default;
58  SmoothFlow& operator=(SmoothFlow&& /*rhs*/) noexcept = default;
59  ~SmoothFlow() = default;
60 
61  explicit SmoothFlow(CkMigrateMessage* /*unused*/) noexcept;
62 
63  // clang-tidy: no runtime references
64  void pup(PUP::er& /*p*/) noexcept; // NOLINT
65 
66  protected:
68 
69  /// The mean flow velocity.
70  struct MeanVelocity {
72  static constexpr Options::String help = {"The mean flow velocity."};
73  };
74 
75  /// The wave vector of the profile.
76  struct WaveVector {
78  static constexpr Options::String help = {"The wave vector of the profile."};
79  };
80 
81  /// The constant pressure throughout the fluid.
82  struct Pressure {
83  using type = double;
84  static constexpr Options::String help = {
85  "The constant pressure throughout the fluid."};
86  static type lower_bound() noexcept { return 0.0; }
87  };
88 
89  /// The adiabatic index for the ideal fluid.
90  struct AdiabaticIndex {
91  using type = double;
92  static constexpr Options::String help = {
93  "The adiabatic index for the ideal fluid."};
94  static type lower_bound() noexcept { return 1.0; }
95  };
96 
97  /// The perturbation amplitude of the rest mass density of the fluid.
99  using type = double;
100  static constexpr Options::String help = {
101  "The perturbation size of the rest mass density."};
102  static type lower_bound() noexcept { return -1.0; }
103  static type upper_bound() noexcept { return 1.0; }
104  };
105 
106  using options = tmpl::list<MeanVelocity, WaveVector, Pressure, AdiabaticIndex,
108 
109  SmoothFlow(const std::array<double, Dim>& mean_velocity,
110  const std::array<double, Dim>& wavevector, double pressure,
111  double adiabatic_index, double perturbation_size) noexcept;
112 
113  /// @{
114  /// Retrieve hydro variable at `(x, t)`
115  template <typename DataType>
116  auto variables(const tnsr::I<DataType, Dim>& x, double t,
117  tmpl::list<hydro::Tags::RestMassDensity<DataType>> /*meta*/)
118  const noexcept
119  -> tuples::TaggedTuple<hydro::Tags::RestMassDensity<DataType>>;
120 
121  template <typename DataType>
122  auto variables(
123  const tnsr::I<DataType, Dim>& x, double t,
124  tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>> /*meta*/)
125  const noexcept
126  -> tuples::TaggedTuple<hydro::Tags::SpecificInternalEnergy<DataType>>;
127 
128  template <typename DataType>
129  auto variables(const tnsr::I<DataType, Dim>& x, double /*t*/,
130  tmpl::list<hydro::Tags::Pressure<DataType>> /*meta*/)
131  const noexcept -> tuples::TaggedTuple<hydro::Tags::Pressure<DataType>>;
132 
133  template <typename DataType>
134  auto variables(
135  const tnsr::I<DataType, Dim>& x, double /*t*/,
136  tmpl::list<hydro::Tags::SpatialVelocity<DataType, Dim>> /*meta*/)
137  const noexcept
138  -> tuples::TaggedTuple<hydro::Tags::SpatialVelocity<DataType, Dim>>;
139 
140  template <typename DataType, bool LocalIsRelativistic = IsRelativistic,
141  Requires<IsRelativistic and IsRelativistic == LocalIsRelativistic> =
142  nullptr>
143  auto variables(
144  const tnsr::I<DataType, Dim>& x, double /*t*/,
145  tmpl::list<hydro::Tags::LorentzFactor<DataType>> /*meta*/) const noexcept
146  -> tuples::TaggedTuple<hydro::Tags::LorentzFactor<DataType>>;
147 
148  template <typename DataType>
149  auto variables(const tnsr::I<DataType, Dim>& x, double t,
150  tmpl::list<hydro::Tags::SpecificEnthalpy<DataType>> /*meta*/)
151  const noexcept
152  -> tuples::TaggedTuple<hydro::Tags::SpecificEnthalpy<DataType>>;
153  /// @}
154 
155  const EquationsOfState::IdealFluid<IsRelativistic>& equation_of_state()
156  const noexcept {
157  return equation_of_state_;
158  }
159 
160  private:
161  template <size_t LocalDim, bool LocalIsRelativistic>
162  friend bool
163  operator==( // NOLINT (clang-tidy: readability-redundant-declaration)
165  const SmoothFlow<LocalDim, LocalIsRelativistic>& rhs) noexcept;
166 
167  // Computes the phase.
168  template <typename DataType>
169  DataType k_dot_x_minus_vt(const tnsr::I<DataType, Dim>& x,
170  double t) const noexcept;
171 
172  std::array<double, Dim> mean_velocity_ =
174  std::array<double, Dim> wavevector_ =
176  double pressure_ = std::numeric_limits<double>::signaling_NaN();
177  double adiabatic_index_ = std::numeric_limits<double>::signaling_NaN();
178  double perturbation_size_ = std::numeric_limits<double>::signaling_NaN();
179  // The angular frequency.
180  double k_dot_v_ = std::numeric_limits<double>::signaling_NaN();
182 };
183 
184 template <size_t Dim, bool IsRelativistic>
185 bool operator!=(const SmoothFlow<Dim, IsRelativistic>& lhs,
186  const SmoothFlow<Dim, IsRelativistic>& rhs) noexcept;
187 } // namespace hydro::Solutions
EquationsOfState
Contains all equations of state, including base class.
Definition: DarkEnergyFluid.hpp:26
Options.hpp
MakeArray.hpp
hydro::Solutions
Holds classes implementing common portions of solutions to various different (magneto)hydrodynamical ...
Definition: SmoothFlow.hpp:19
hydro::Solutions::SmoothFlow::MeanVelocity
The mean flow velocity.
Definition: SmoothFlow.hpp:70
hydro::Solutions::SmoothFlow::AdiabaticIndex
The adiabatic index for the ideal fluid.
Definition: SmoothFlow.hpp:90
hydro::Solutions::SmoothFlow::PerturbationSize
The perturbation amplitude of the rest mass density of the fluid.
Definition: SmoothFlow.hpp:98
hydro::Solutions::SmoothFlow
Smooth sinusoidal density wave.
Definition: SmoothFlow.hpp:52
EquationsOfState::IdealFluid
Equation of state for an ideal fluid.
Definition: IdealFluid.hpp:39
array
hydro::Solutions::SmoothFlow::variables
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)
hydro
Items related to hydrodynamic systems.
Definition: SmoothFlow.hpp:19
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
limits
TypeAliases.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
hydro::Solutions::SmoothFlow::Pressure
The constant pressure throughout the fluid.
Definition: SmoothFlow.hpp:82
std::numeric_limits
hydro::Solutions::SmoothFlow::WaveVector
The wave vector of the profile.
Definition: SmoothFlow.hpp:76
TMPL.hpp
hydro::Tags::RestMassDensity
The rest-mass density .
Definition: Tags.hpp:125