FixConservatives.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <limits>
7 
9 #include "Evolution/Systems/GrMhd/ValenciaDivClean/TagsDeclarations.hpp" // IWYU pragma: keep
10 #include "Options/Options.hpp"
11 #include "PointwiseFunctions/GeneralRelativity/TagsDeclarations.hpp" // IWYU pragma: keep
12 #include "Utilities/Gsl.hpp"
13 #include "Utilities/TMPL.hpp"
14 
15 /// \cond
16 namespace PUP {
17 class er;
18 } // namespace PUP
19 class DataVector;
20 /// \endcond
21 
22 // IWYU pragma: no_forward_declare EquationsOfState::EquationOfState
23 // IWYU pragma: no_forward_declare Tensor
24 // IWYU pragma: no_forward_declare grmhd::ValenciaDivClean::Tags::TildeD
25 // IWYU pragma: no_forward_declare grmhd::ValenciaDivClean::Tags::TildeTau
26 // IWYU pragma: no_forward_declare grmhd::ValenciaDivClean::Tags::TildeS
27 // IWYU pragma: no_forward_declare grmhd::ValenciaDivClean::Tags::TildeB
28 // IWYU pragma: no_forward_declare gr::Tags::SpatialMetric
29 // IWYU pragma: no_forward_declare gr::Tags::InverseSpatialMetric
30 // IWYU pragma: no_forward_declare gr::Tags::SqrtDetSpatialMetric
31 
32 namespace grmhd {
33 namespace ValenciaDivClean {
34 
35 /// \ingroup VariableFixingGroup
36 /// \brief Fix conservative variables using method developed by Foucart.
37 ///
38 /// Adjusts the conservative variables as follows:
39 /// - Changes \f${\tilde D}\f$, the generalized mass-energy density, such
40 /// that \f$D\f$, the product of the rest mass density \f$\rho\f$ and the
41 /// Lorentz factor \f$W\f$, is set to value of the option `MinimumValueOfD`,
42 /// whenever \f$D\f$ is below the value of the option `CutoffD`.
43 /// - Increases \f${\tilde \tau}\f$, the generalized internal energy density,
44 /// such that
45 /// \f${\tilde B}^2 \leq 2 \sqrt{\gamma} (1 - \epsilon_B) {\tilde \tau}\f$,
46 /// where \f${\tilde B}^i\f$ is the generalized magnetic field,
47 /// \f$\gamma\f$ is the determinant of the spatial metric, and
48 /// \f$\epsilon_B\f$ is the option `SafetyFactorForB`.
49 /// - Decreases \f${\tilde S}_i\f$, the generalized momentum density, such that
50 /// \f${\tilde S}^2 \leq (1 - \epsilon_S) {\tilde S}^2_{max}\f$, where
51 /// \f$\epsilon_S\f$ is the option `SafetyFactorForS`, and
52 /// \f${\tilde S}^2_{max}\f$ is a complicated function of the conservative
53 /// variables which can only be found through root finding. There are
54 /// sufficient conditions for a set of conservative variables to satisfy the
55 /// inequality, which can be used to avoid root finding at most points.
56 ///
57 /// \note The routine currently assumes the minimum specific enthalpy is one.
58 ///
59 /// For more details see Appendix B from the [thesis of Francois
60 /// Foucart](https://ecommons.cornell.edu/handle/1813/30652)
62  public:
63  /// \brief Minimum value of rest-mass density times lorentz factor
64  struct MinimumValueOfD {
65  using type = double;
66  static type lower_bound() noexcept { return 0.0; }
67  static constexpr OptionString help = {
68  "Minimum value of rest-mass density times lorentz factor"};
69  };
70  /// \brief Cutoff below which \f$D = \rho W\f$ is set to MinimumValueOfD
71  struct CutoffD {
72  using type = double;
73  static type lower_bound() noexcept { return 0.0; }
74  static constexpr OptionString help = {
75  "Cutoff below which D is set to MinimumValueOfD"};
76  };
77 
78  /// \brief Safety factor \f$\epsilon_B\f$.
80  using type = double;
81  static type lower_bound() noexcept { return 0.0; }
82  static constexpr OptionString help = {
83  "Safety factor for magnetic field bound."};
84  };
85  /// \brief Safety factor \f$\epsilon_S\f$.
87  using type = double;
88  static type lower_bound() noexcept { return 0.0; }
89  static constexpr OptionString help = {
90  "Safety factor for momentum density bound."};
91  };
92  using options =
93  tmpl::list<MinimumValueOfD, CutoffD, SafetyFactorForB, SafetyFactorForS>;
94  static constexpr OptionString help = {
95  "Variable fixing used in Foucart's thesis.\n"};
96 
97  FixConservatives(double minimum_rest_mass_density_times_lorentz_factor,
98  double rest_mass_density_times_lorentz_factor_cutoff,
99  double safety_factor_for_magnetic_field,
100  double safety_factor_for_momentum_density,
101  const OptionContext& context = {});
102 
103  FixConservatives() = default;
104  FixConservatives(const FixConservatives& /*rhs*/) = default;
105  FixConservatives& operator=(const FixConservatives& /*rhs*/) = default;
106  FixConservatives(FixConservatives&& /*rhs*/) noexcept = default;
107  FixConservatives& operator=(FixConservatives&& /*rhs*/) noexcept = default;
108  ~FixConservatives() = default;
109 
110  // NOLINTNEXTLINE(google-runtime-references)
111  void pup(PUP::er& p) noexcept;
112 
113  using return_tags = tmpl::list<grmhd::ValenciaDivClean::Tags::TildeD,
116  using argument_tags =
117  tmpl::list<grmhd::ValenciaDivClean::Tags::TildeB<>,
120 
121  void operator()(
123  gsl::not_null<Scalar<DataVector>*> tilde_tau,
124  gsl::not_null<tnsr::i<DataVector, 3, Frame::Inertial>*> tilde_s,
125  const tnsr::I<DataVector, 3, Frame::Inertial>& tilde_b,
126  const tnsr::ii<DataVector, 3, Frame::Inertial>& spatial_metric,
127  const tnsr::II<DataVector, 3, Frame::Inertial>& inv_spatial_metric,
128  const Scalar<DataVector>& sqrt_det_spatial_metric) const noexcept;
129 
130  private:
131  friend bool operator==(const FixConservatives& lhs,
132  const FixConservatives& rhs) noexcept;
133 
134  double minimum_rest_mass_density_times_lorentz_factor_{
136  double rest_mass_density_times_lorentz_factor_cutoff_{
138  double one_minus_safety_factor_for_magnetic_field_{
140  double one_minus_safety_factor_for_momentum_density_{
142 };
143 
144 bool operator!=(const FixConservatives& lhs,
145  const FixConservatives& rhs) noexcept;
146 
147 } // namespace ValenciaDivClean
148 } // namespace grmhd
Definition: Strahlkorper.hpp:14
Minimum value of rest-mass density times lorentz factor.
Definition: FixConservatives.hpp:64
T signaling_NaN(T... args)
Definition: Tags.hpp:49
Safety factor .
Definition: FixConservatives.hpp:79
Defines classes and functions for making classes creatable from input files.
Inverse of the spatial metric.
Definition: Tags.hpp:36
tnsr::ii< DataType, SpatialDim, Frame > spatial_metric(const tnsr::aa< DataType, SpatialDim, Frame > &spacetime_metric) noexcept
Compute spatial metric from spacetime metric.
Definition: ComputeSpacetimeQuantities.cpp:62
The densitized energy density .
Definition: Tags.hpp:38
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
The densitized momentum density .
Definition: Tags.hpp:45
Definition: Tags.hpp:28
Defines a list of useful type aliases for tensors.
The densitized rest-mass density .
Definition: Tags.hpp:32
Stores a collection of function values.
Definition: DataVector.hpp:42
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)
Defines functions and classes from the GSL.
Safety factor .
Definition: FixConservatives.hpp:86
Cutoff below which is set to MinimumValueOfD.
Definition: FixConservatives.hpp:71
Items related to general relativistic magnetohydrodynamics (GRMHD)
Definition: Characteristics.hpp:34
Tensor< T, Symmetry<>, index_list<> > Scalar
Scalar type.
Definition: TypeAliases.hpp:21
Fix conservative variables using method developed by Foucart.
Definition: FixConservatives.hpp:61
Require a pointer to not be a nullptr
Definition: Gsl.hpp:182