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/GeneralRelativity/Minkowski.hpp"
13 #include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
14 #include "PointwiseFunctions/Hydro/Tags.hpp" // IWYU pragma: keep
15 #include "Utilities/MakeArray.hpp" // IWYU pragma: keep
16 #include "Utilities/TMPL.hpp"
18 
19 namespace grmhd {
20 namespace Solutions {
21 
22 /*!
23  * \brief Periodic GrMhd solution in Minkowski spacetime.
24  *
25  * An analytic solution to the 3-D GrMhd system. The user specifies the mean
26  * flow velocity of the fluid, the wavevector of the density profile, and the
27  * amplitude \f$A\f$ of the density profile. The magnetic field is taken to be
28  * zero everywhere. In Cartesian coordinates \f$(x, y, z)\f$, and using
29  * dimensionless units, the primitive quantities at a given time \f$t\f$ are
30  * then
31  *
32  * \f{align*}
33  * \rho(\vec{x},t) &= 1 + A \sin(\vec{k}\cdot(\vec{x} - \vec{v}t)) \\
34  * \vec{v}(\vec{x},t) &= [v_x, v_y, v_z]^{T},\\
35  * P(\vec{x},t) &= P, \\
36  * \epsilon(\vec{x}, t) &= \frac{P}{(\gamma - 1)\rho}\\
37  * \vec{B}(\vec{x},t) &= [0, 0, 0]^{T}
38  * \f}
39  */
40 class SmoothFlow {
41  public:
44 
45  /// The mean flow velocity.
46  struct MeanVelocity {
48  static constexpr OptionString help = {"The mean flow velocity."};
49  };
50 
51  /// The wave vector of the profile.
52  struct WaveVector {
54  static constexpr OptionString help = {"The wave vector of the profile."};
55  };
56 
57  /// The constant pressure throughout the fluid.
58  struct Pressure {
59  using type = double;
60  static constexpr OptionString help = {
61  "The constant pressure throughout the fluid."};
62  static type lower_bound() noexcept { return 0.0; }
63  };
64 
65  /// The adiabatic index for the ideal fluid.
66  struct AdiabaticIndex {
67  using type = double;
68  static constexpr OptionString help = {
69  "The adiabatic index for the ideal fluid."};
70  static type lower_bound() noexcept { return 1.0; }
71  };
72 
73  /// The perturbation amplitude of the rest mass density of the fluid.
75  using type = double;
76  static constexpr OptionString help = {
77  "The perturbation size of the rest mass density."};
78  static type lower_bound() noexcept { return -1.0; }
79  static type upper_bound() noexcept { return 1.0; }
80  };
81 
82  using options = tmpl::list<MeanVelocity, WaveVector, Pressure, AdiabaticIndex,
84  static constexpr OptionString help = {
85  "Periodic smooth flow in Minkowski spacetime with zero magnetic field."};
86 
87  SmoothFlow() = default;
88  SmoothFlow(const SmoothFlow& /*rhs*/) = delete;
89  SmoothFlow& operator=(const SmoothFlow& /*rhs*/) = delete;
90  SmoothFlow(SmoothFlow&& /*rhs*/) noexcept = default;
91  SmoothFlow& operator=(SmoothFlow&& /*rhs*/) noexcept = default;
92  ~SmoothFlow() = default;
93 
94  SmoothFlow(MeanVelocity::type mean_velocity, WaveVector::type wavevector,
95  Pressure::type pressure, AdiabaticIndex::type adiabatic_index,
96  PerturbationSize::type perturbation_size) noexcept;
97 
98  explicit SmoothFlow(CkMigrateMessage* /*unused*/) noexcept {}
99 
100  // @{
101  /// Retrieve hydro variable at `(x, t)`
102  template <typename DataType>
103  auto variables(
104  const tnsr::I<DataType, 3>& x, double t,
105  tmpl::list<hydro::Tags::RestMassDensity<DataType>> /*meta*/) const
107 
108  template <typename DataType>
109  auto variables(
110  const tnsr::I<DataType, 3>& x, double t,
111  tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>> /*meta*/) const
112  noexcept
114 
115  template <typename DataType>
116  auto variables(const tnsr::I<DataType, 3>& x, double /*t*/,
117  tmpl::list<hydro::Tags::Pressure<DataType>> /*meta*/) const
119 
120  template <typename DataType>
121  auto variables(const tnsr::I<DataType, 3>& x, double /*t*/,
122  tmpl::list<hydro::Tags::SpatialVelocity<
123  DataType, 3, Frame::Inertial>> /*meta*/) const noexcept
126 
127  template <typename DataType>
128  auto variables(const tnsr::I<DataType, 3>& x, double /*t*/,
129  tmpl::list<hydro::Tags::MagneticField<
130  DataType, 3, Frame::Inertial>> /*meta*/) const noexcept
133 
134  template <typename DataType>
135  auto variables(
136  const tnsr::I<DataType, 3>& x, double /*t*/,
137  tmpl::list<hydro::Tags::DivergenceCleaningField<DataType>> /*meta*/) const
138  noexcept
140 
141  template <typename DataType>
142  auto variables(
143  const tnsr::I<DataType, 3>& x, double /*t*/,
144  tmpl::list<hydro::Tags::LorentzFactor<DataType>> /*meta*/) const noexcept
146 
147  template <typename DataType>
148  auto variables(
149  const tnsr::I<DataType, 3>& x, double t,
150  tmpl::list<hydro::Tags::SpecificEnthalpy<DataType>> /*meta*/) const
152  // @}
153 
154  /// Retrieve a collection of hydro variables at `(x, t)`
155  template <typename DataType, typename... Tags>
156  tuples::TaggedTuple<Tags...> variables(const tnsr::I<DataType, 3>& x,
157  double t,
158  tmpl::list<Tags...> /*meta*/) const
159  noexcept {
160  static_assert(sizeof...(Tags) > 1,
161  "The generic template will recurse infinitely if only one "
162  "tag is being retrieved.");
163  return {get<Tags>(variables(x, t, tmpl::list<Tags>{}))...};
164  }
165 
166  /// Retrieve the metric variables
167  template <typename DataType, typename Tag>
168  tuples::TaggedTuple<Tag> variables(const tnsr::I<DataType, 3>& x, double t,
169  tmpl::list<Tag> /*meta*/) const noexcept {
170  return background_spacetime_.variables(x, t, tmpl::list<Tag>{});
171  }
172 
173  // clang-tidy: no runtime references
174  void pup(PUP::er& /*p*/) noexcept; // NOLINT
175 
176  const EquationsOfState::IdealFluid<true>& equation_of_state() const noexcept {
177  return equation_of_state_;
178  }
179 
180  private:
181  friend bool operator==(const SmoothFlow& lhs, const SmoothFlow& rhs) noexcept;
182 
183  // Computes the phase.
184  template <typename DataType>
185  DataType k_dot_x_minus_vt(const tnsr::I<DataType, 3>& x, double t) const
186  noexcept;
187  MeanVelocity::type mean_velocity_ =
189  WaveVector::type wavevector_ =
191  Pressure::type pressure_ = std::numeric_limits<double>::signaling_NaN();
192  AdiabaticIndex::type adiabatic_index_ =
194  PerturbationSize::type perturbation_size_ =
196  // The angular frequency.
197  double k_dot_v_ = std::numeric_limits<double>::signaling_NaN();
198  EquationsOfState::IdealFluid<true> equation_of_state_{};
199  gr::Solutions::Minkowski<3> background_spacetime_{};
200 };
201 
202 bool operator!=(const SmoothFlow& lhs, const SmoothFlow& rhs) noexcept;
203 } // namespace Solutions
204 } // namespace grmhd
The constant pressure throughout the fluid.
Definition: SmoothFlow.hpp:58
Defines class tuples::TaggedTuple.
The spatial velocity .
Definition: Tags.hpp:144
The fluid pressure .
Definition: Tags.hpp:123
The specific internal energy .
Definition: Tags.hpp:176
T signaling_NaN(T... args)
Defines function make_array.
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataType, 3 > &x, double t, tmpl::list< Tags... >) const noexcept
Retrieve a collection of hydro variables at (x, t)
Definition: SmoothFlow.hpp:156
Defines classes and functions for making classes creatable from input files.
auto variables(const tnsr::I< DataType, 3 > &x, double t, tmpl::list< hydro::Tags::RestMassDensity< DataType >>) const noexcept -> tuples::TaggedTuple< hydro::Tags::RestMassDensity< DataType >>
Retrieve hydro variable at (x, t)
The perturbation amplitude of the rest mass density of the fluid.
Definition: SmoothFlow.hpp:74
The magnetic field measured by an Eulerian observer, where is the normal to the spatial hypersurfac...
Definition: Tags.hpp:80
The divergence-cleaning field .
Definition: Tags.hpp:47
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
The wave vector of the profile.
Definition: SmoothFlow.hpp:52
The Lorentz factor .
Definition: Tags.hpp:64
Definition: DataBoxTag.hpp:29
Defines a list of useful type aliases for tensors.
Wraps the template metaprogramming library used (brigand)
The rest-mass density .
Definition: Tags.hpp:130
Definition: IndexType.hpp:44
The mean flow velocity.
Definition: SmoothFlow.hpp:46
The specific enthalpy .
Definition: Tags.hpp:169
Items related to general relativistic magnetohydrodynamics (GRMHD)
Definition: Characteristics.hpp:34
Periodic GrMhd solution in Minkowski spacetime.
Definition: SmoothFlow.hpp:40
The adiabatic index for the ideal fluid.
Definition: SmoothFlow.hpp:66
tuples::TaggedTuple< Tag > variables(const tnsr::I< DataType, 3 > &x, double t, tmpl::list< Tag >) const noexcept
Retrieve the metric variables.
Definition: SmoothFlow.hpp:168