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 "Evolution/Systems/NewtonianEuler/Sources/NoSource.hpp"
12 #include "Evolution/Systems/NewtonianEuler/Tags.hpp"
13 #include "Options/Options.hpp"
14 #include "PointwiseFunctions/AnalyticSolutions/AnalyticSolution.hpp"
15 #include "PointwiseFunctions/AnalyticSolutions/Hydro/SmoothFlow.hpp"
16 #include "PointwiseFunctions/Hydro/EquationsOfState/IdealFluid.hpp"
17 #include "PointwiseFunctions/Hydro/Tags.hpp"
18 #include "Utilities/MakeArray.hpp"
19 #include "Utilities/TMPL.hpp"
20 #include "Utilities/TaggedTuple.hpp"
21
22 namespace NewtonianEuler::Solutions {
23 /*!
24  * \brief Smooth density wave advecting across the domain.
25  *
26  * A solution with constant pressure and uniform spatial velocity provided
27  * that the rest mass density satisfies the advection equation
28  *
29  * \f{align*}{
30  * \partial_t\rho + v^i\partial_i\rho = 0,
31  * \f}
32  *
33  * and the specific internal energy is a function of the rest mass density only,
34  * \f$\epsilon = \epsilon(\rho)\f$. For testing purposes, this class implements
35  * this solution for the case where \f$\rho\f$ is a sine wave. The user
36  * specifies the mean flow velocity of the fluid, the wavevector of the density
37  * profile, and the amplitude \f$A\f$ of the density profile. In Cartesian
38  * coordinates \f$(x, y, z)\f$, and using dimensionless units, the primitive
39  * variables at a given time \f$t\f$ are then
40  *
41  * \f{align*}{
42  * \rho(\vec{x},t) &= 1 + A \sin(\vec{k}\cdot(\vec{x} - \vec{v}t)) \\
43  * \vec{v}(\vec{x},t) &= [v_x, v_y, v_z]^{T},\\
44  * P(\vec{x},t) &= P, \\
45  * \epsilon(\vec{x}, t) &= \frac{P}{(\gamma - 1)\rho}\\
46  * \f}
47  *
48  * where we have assumed \f$\epsilon\f$ and \f$\rho\f$ to be related through an
49  * equation mathematically equivalent to the equation of state of an ideal gas,
50  * where the pressure is held constant.
51  */
52 template <size_t Dim>
53 class SmoothFlow : virtual public MarkAsAnalyticSolution,
54  private hydro::Solutions::SmoothFlow<Dim, false> {
55  using smooth_flow = hydro::Solutions::SmoothFlow<Dim, false>;
56
57  public:
58  using options = typename smooth_flow::options;
59
60  static constexpr Options::String help = {
61  "Smooth density wave advecting across a domain."};
62
63  SmoothFlow() = default;
64  SmoothFlow(const SmoothFlow& /*rhs*/) = delete;
65  SmoothFlow& operator=(const SmoothFlow& /*rhs*/) = delete;
66  SmoothFlow(SmoothFlow&& /*rhs*/) noexcept = default;
67  SmoothFlow& operator=(SmoothFlow&& /*rhs*/) noexcept = default;
68  ~SmoothFlow() = default;
69
70  SmoothFlow(const std::array<double, Dim>& mean_velocity,
71  const std::array<double, Dim>& wavevector, double pressure,
72  double adiabatic_index, double perturbation_size) noexcept;
73
74  explicit SmoothFlow(CkMigrateMessage* msg) noexcept;
75
76  using smooth_flow::equation_of_state;
77  using typename smooth_flow::equation_of_state_type;
78  using source_term_type = Sources::NoSource;
79
80  // Overload the variables function from the base class.
81  using smooth_flow::variables;
82
83  template <typename DataType>
84  tuples::TaggedTuple<Tags::MassDensity<DataType>> variables(
85  const tnsr::I<DataType, Dim>& x, const double t,
86  tmpl::list<Tags::MassDensity<DataType>> /*meta*/) const noexcept {
87  return {tuples::get<hydro::Tags::RestMassDensity<DataType>>(
88  variables(x, t, tmpl::list<hydro::Tags::RestMassDensity<DataType>>{}))};
89  }
90
91  template <typename DataType>
93  const tnsr::I<DataType, Dim>& x, const double t,
94  tmpl::list<Tags::Velocity<DataType, Dim>> /*meta*/) const noexcept {
95  return {tuples::get<hydro::Tags::SpatialVelocity<DataType, Dim>>(variables(
96  x, t, tmpl::list<hydro::Tags::SpatialVelocity<DataType, Dim>>{}))};
97  }
98
99  template <typename DataType>
101  const tnsr::I<DataType, Dim>& x, const double t,
102  tmpl::list<Tags::Pressure<DataType>> /*meta*/) const noexcept {
103  return {tuples::get<hydro::Tags::Pressure<DataType>>(
104  variables(x, t, tmpl::list<hydro::Tags::Pressure<DataType>>{}))};
105  }
106
107  template <typename DataType>
109  const tnsr::I<DataType, Dim>& x, const double t,
110  tmpl::list<Tags::SpecificInternalEnergy<DataType>> /*meta*/)
111  const noexcept {
112  return {
113  tuples::get<hydro::Tags::SpecificInternalEnergy<DataType>>(variables(
114  x, t,
116  }
117
118  /// Retrieve a collection of hydro variables at (x, t)
119  template <typename DataType, typename... Tags>
121  const tnsr::I<DataType, Dim>& x, const double t,
122  tmpl::list<Tags...> /*meta*/) const noexcept {
123  static_assert(sizeof...(Tags) > 1,
124  "The generic template will recurse infinitely if only one "
125  "tag is being retrieved.");
126  return {tuples::get<Tags>(variables(x, t, tmpl::list<Tags>{}))...};
127  }
128
129  // clang-tidy: no runtime references
130  void pup(PUP::er& /*p*/) noexcept; // NOLINT
131
132  private:
133  template <size_t SpatialDim>
134  friend bool
135  operator==( // NOLINT (clang-tidy: readability-redundant-declaration)
136  const SmoothFlow<SpatialDim>& lhs,
137  const SmoothFlow<SpatialDim>& rhs) noexcept;
138 };
139
140 template <size_t Dim>
141 bool operator!=(const SmoothFlow<Dim>& lhs,
142  const SmoothFlow<Dim>& rhs) noexcept;
143 } // namespace NewtonianEuler::Solutions
hydro::Tags::Pressure
The fluid pressure .
Definition: Tags.hpp:119
hydro::Tags::SpecificInternalEnergy
The specific internal energy .
Definition: Tags.hpp:173
NewtonianEuler::Solutions
Holds classes implementing a solution to the Newtonian Euler system.
Definition: EvolveNewtonianEulerFwd.hpp:14
Options.hpp
MakeArray.hpp
hydro::Solutions::SmoothFlow
Smooth sinusoidal density wave.
Definition: SmoothFlow.hpp:52
array
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
NewtonianEuler::Solutions::SmoothFlow::variables
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataType, Dim > &x, const double t, tmpl::list< Tags... >) const noexcept
Retrieve a collection of hydro variables at (x, t)
Definition: SmoothFlow.hpp:120
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
hydro::Tags::SpatialVelocity
The spatial velocity of the fluid, where . Here is the spatial part of the 4-velocity of the fluid,...
Definition: Tags.hpp:142
TMPL.hpp
NewtonianEuler::Solutions::SmoothFlow
Smooth density wave advecting across the domain.
Definition: EvolveNewtonianEulerFwd.hpp:21
hydro::Tags::RestMassDensity
The rest-mass density .
Definition: Tags.hpp:125