MagneticRotor.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 
10 #include "Options/Options.hpp"
11 #include "PointwiseFunctions/AnalyticSolutions/GeneralRelativity/Minkowski.hpp"
12 #include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
13 #include "PointwiseFunctions/Hydro/EquationsOfState/IdealFluid.hpp" // IWYU pragma: keep
14 #include "PointwiseFunctions/Hydro/Tags.hpp"
15 #include "Utilities/MakeArray.hpp" // IWYU pragma: keep
16 #include "Utilities/TMPL.hpp"
18 
19 // IWYU pragma: no_include <pup.h>
20 
21 /// \cond
22 namespace PUP {
23 class er; // IWYU pragma: keep
24 } // namespace PUP
25 /// \endcond
26 
27 namespace grmhd {
28 namespace AnalyticData {
29 
30 /*!
31  * \brief Analytic initial data for a magnetic rotor.
32  *
33  * This is a test first described in \cite Balsara1999 for classical MHD and
34  * later generalised to relativistic MHD in \cite DelZanna2002rv
35  *
36  * This effectively 2D test initially consists of an infinitely long cylinder of
37  * radius `RotorRadius` rotating about the z-axis with the given
38  * `AngularVelocity`. The rest mass density of the fluid inside the rotor,
39  * `RotorDensity`, is higher than the `BackgroundDensity` outside of the rotor.
40  * The fluid is at a constant `Pressure`. The rotor is embedded in a constant
41  * `MagneticField` (usually taken to be along the x-axis). The fluid is an
42  * ideal fluid with the given `AdiabaticIndex`. Evolving the initial data,
43  * magnetic braking will slow down the rotor, while dragging the magnetic field
44  * lines.
45  *
46  * The standard test setup is done on a unit cube with the following values
47  * given for the options:
48  * - RotorRadius: 0.1
49  * - RotorDensity: 10.0
50  * - BackgroundDensity: 1.0
51  * - Pressure: 1.0
52  * - AngularVelocity: 9.95
53  * - MagneticField: [3.54490770181103205, 0.0, 0.0]
54  * - AdiabaticIndex: 1.66666666666666667
55  *
56  * The magnetic field in the disk should rotate by about 90 degrees by t = 0.4.
57  *
58  */
60  public:
63 
64  /// Radius of the rotor.
65  struct RotorRadius {
66  using type = double;
67  static constexpr OptionString help = {"The initial radius of the rotor."};
68  static type lower_bound() noexcept { return 0.0; }
69  };
70  /// Density inside the rotor.
71  struct RotorDensity {
72  using type = double;
73  static constexpr OptionString help = {"Density inside RotorRadius."};
74  static type lower_bound() noexcept { return 0.0; }
75  };
76  /// Density outside the rotor.
78  using type = double;
79  static constexpr OptionString help = {"Density outside RotorRadius."};
80  static type lower_bound() noexcept { return 0.0; }
81  };
82  /// Uniform pressure inside and outside the rotor.
83  struct Pressure {
84  using type = double;
85  static constexpr OptionString help = {"Pressure."};
86  static type lower_bound() noexcept { return 0.0; }
87  };
88  /// Angular velocity inside the rotor.
89  struct AngularVelocity {
90  using type = double;
91  static constexpr OptionString help = {
92  "Angular velocity of matter inside RotorRadius"};
93  };
94  /// The x,y,z components of the uniform magnetic field threading the matter.
95  struct MagneticField {
97  static constexpr OptionString help = {
98  "The x,y,z components of the uniform magnetic field."};
99  };
100  /// The adiabatic index of the ideal fluid.
101  struct AdiabaticIndex {
102  using type = double;
103  static constexpr OptionString help = {
104  "The adiabatic index of the ideal fluid."};
105  static type lower_bound() noexcept { return 1.0; }
106  };
107 
108  using options =
111 
112  static constexpr OptionString help = {
113  "Magnetic rotor analytic initial data."};
114 
115  MagneticRotor() = default;
116  MagneticRotor(const MagneticRotor& /*rhs*/) = delete;
117  MagneticRotor& operator=(const MagneticRotor& /*rhs*/) = delete;
118  MagneticRotor(MagneticRotor&& /*rhs*/) noexcept = default;
119  MagneticRotor& operator=(MagneticRotor&& /*rhs*/) noexcept = default;
120  ~MagneticRotor() = default;
121 
122  MagneticRotor(double rotor_radius, double rotor_density,
123  double background_density, double pressure,
124  double angular_velocity, std::array<double, 3> magnetic_field,
125  double adiabatic_index, const OptionContext& context = {});
126 
127  explicit MagneticRotor(CkMigrateMessage* /*unused*/) noexcept {}
128 
129  // @{
130  /// Retrieve the GRMHD variables at a given position.
131  template <typename DataType>
132  auto variables(
133  const tnsr::I<DataType, 3>& x,
134  tmpl::list<hydro::Tags::RestMassDensity<DataType>> /*meta*/) const
136 
137  template <typename DataType>
138  auto variables(
139  const tnsr::I<DataType, 3>& x,
140  tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>> /*meta*/) const
141  noexcept
143 
144  template <typename DataType>
145  auto variables(const tnsr::I<DataType, 3>& x,
146  tmpl::list<hydro::Tags::Pressure<DataType>> /*meta*/) const
148 
149  template <typename DataType>
150  auto variables(const tnsr::I<DataType, 3>& x,
151  tmpl::list<hydro::Tags::SpatialVelocity<
152  DataType, 3, Frame::Inertial>> /*meta*/) const noexcept
155 
156  template <typename DataType>
157  auto variables(const tnsr::I<DataType, 3>& x,
158  tmpl::list<hydro::Tags::MagneticField<
159  DataType, 3, Frame::Inertial>> /*meta*/) const noexcept
162 
163  template <typename DataType>
164  auto variables(
165  const tnsr::I<DataType, 3>& x,
166  tmpl::list<hydro::Tags::DivergenceCleaningField<DataType>> /*meta*/) const
167  noexcept
169 
170  template <typename DataType>
171  auto variables(
172  const tnsr::I<DataType, 3>& x,
173  tmpl::list<hydro::Tags::LorentzFactor<DataType>> /*meta*/) const noexcept
175 
176  template <typename DataType>
177  auto variables(
178  const tnsr::I<DataType, 3>& x,
179  tmpl::list<hydro::Tags::SpecificEnthalpy<DataType>> /*meta*/) const
181  // @}
182 
183  /// Retrieve a collection of hydrodynamic variables at position x
184  template <typename DataType, typename... Tags>
186  const tnsr::I<DataType, 3, Frame::Inertial>& x,
187  tmpl::list<Tags...> /*meta*/) const noexcept {
188  static_assert(sizeof...(Tags) > 1,
189  "The generic template will recurse infinitely if only one "
190  "tag is being retrieved.");
191  return {tuples::get<Tags>(variables(x, tmpl::list<Tags>{}))...};
192  }
193 
194  /// Retrieve the metric variables
195  template <typename DataType, typename Tag>
196  tuples::TaggedTuple<Tag> variables(const tnsr::I<DataType, 3>& x,
197  tmpl::list<Tag> /*meta*/) const noexcept {
198  constexpr double dummy_time = 0.0;
199  return background_spacetime_.variables(x, dummy_time, tmpl::list<Tag>{});
200  }
201 
202  const EquationsOfState::IdealFluid<true>& equation_of_state() const noexcept {
203  return equation_of_state_;
204  }
205 
206  // clang-tidy: no runtime references
207  void pup(PUP::er& /*p*/) noexcept; // NOLINT
208 
209  private:
210  double rotor_radius_ = std::numeric_limits<double>::signaling_NaN();
211  double rotor_density_ = std::numeric_limits<double>::signaling_NaN();
212  double background_density_ = std::numeric_limits<double>::signaling_NaN();
213  double pressure_ = std::numeric_limits<double>::signaling_NaN();
214  double angular_velocity_ = std::numeric_limits<double>::signaling_NaN();
215  std::array<double, 3> magnetic_field_ =
219  double adiabatic_index_ = std::numeric_limits<double>::signaling_NaN();
220  EquationsOfState::IdealFluid<true> equation_of_state_{};
221  gr::Solutions::Minkowski<3> background_spacetime_{};
222 
223  friend bool operator==(const MagneticRotor& lhs,
224  const MagneticRotor& rhs) noexcept;
225 
226  friend bool operator!=(const MagneticRotor& lhs,
227  const MagneticRotor& rhs) noexcept;
228 };
229 
230 } // namespace AnalyticData
231 } // namespace grmhd
Density outside the rotor.
Definition: MagneticRotor.hpp:77
Uniform pressure inside and outside the rotor.
Definition: MagneticRotor.hpp:83
Definition: Strahlkorper.hpp:14
Defines class tuples::TaggedTuple.
Analytic initial data for a magnetic rotor.
Definition: MagneticRotor.hpp:59
The spatial velocity of the fluid, where . Here is the spatial part of the 4-velocity of the fluid...
Definition: Tags.hpp:156
The fluid pressure .
Definition: Tags.hpp:130
The specific internal energy .
Definition: Tags.hpp:189
Radius of the rotor.
Definition: MagneticRotor.hpp:65
Angular velocity inside the rotor.
Definition: MagneticRotor.hpp:89
T signaling_NaN(T... args)
The x,y,z components of the uniform magnetic field threading the matter.
Definition: MagneticRotor.hpp:95
Defines function make_array.
The adiabatic index of the ideal fluid.
Definition: MagneticRotor.hpp:101
Defines classes and functions for making classes creatable from input files.
auto variables(const tnsr::I< DataType, 3 > &x, tmpl::list< hydro::Tags::RestMassDensity< DataType >>) const noexcept -> tuples::TaggedTuple< hydro::Tags::RestMassDensity< DataType >>
Retrieve the GRMHD variables at a given position.
The magnetic field measured by an Eulerian observer, where is the normal to the spatial hypersurfac...
Definition: Tags.hpp:86
The divergence-cleaning field .
Definition: Tags.hpp:50
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
Density inside the rotor.
Definition: MagneticRotor.hpp:71
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataType, 3, Frame::Inertial > &x, tmpl::list< Tags... >) const noexcept
Retrieve a collection of hydrodynamic variables at position x.
Definition: MagneticRotor.hpp:185
The Lorentz factor , where is the spatial velocity of the fluid.
Definition: Tags.hpp:68
Definition: DataBoxTag.hpp:29
Defines a list of useful type aliases for tensors.
Information about the nested operations being performed by the parser, for use in printing errors...
Definition: Options.hpp:38
Wraps the template metaprogramming library used (brigand)
tuples::TaggedTuple< Tag > variables(const tnsr::I< DataType, 3 > &x, tmpl::list< Tag >) const noexcept
Retrieve the metric variables.
Definition: MagneticRotor.hpp:196
The rest-mass density .
Definition: Tags.hpp:137
Definition: IndexType.hpp:44
The specific enthalpy .
Definition: Tags.hpp:182
Items related to general relativistic magnetohydrodynamics (GRMHD)
Definition: Characteristics.hpp:34