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 VariableFixing {
33 
34 /// \ingroup VariableFixingGroup
35 /// \brief Fix conservative variables using method developed by Foucart.
36 ///
37 /// Adjusts the conservative variables as follows:
38 /// - Changes \f${\tilde D}\f$, the generalized mass-energy density, such
39 /// that \f$D\f$, the product of the rest mass density \f$\rho\f$ and the
40 /// Lorentz factor \f$W\f$, is set to value of the option `MinimumValueOfD`,
41 /// whenever \f$D\f$ is below the value of the option `CutoffD`.
42 /// - Increases \f${\tilde \tau}\f$, the generalized internal energy density,
43 /// such that
44 /// \f${\tilde B}^2 \leq 2 \sqrt{\gamma} (1 - \epsilon_B) {\tilde \tau}\f$,
45 /// where \f${\tilde B}^i\f$ is the generalized magnetic field,
46 /// \f$\gamma\f$ is the determinant of the spatial metric, and
47 /// \f$\epsilon_B\f$ is the option `SafetyFactorForB`.
48 /// - Decreases \f${\tilde S}_i\f$, the generalized momentum density, such that
49 /// \f${\tilde S}^2 \leq (1 - \epsilon_S) {\tilde S}^2_{max}\f$, where
50 /// \f$\epsilon_S\f$ is the option `SafetyFactorForS`, and
51 /// \f${\tilde S}^2_{max}\f$ is a complicated function of the conservative
52 /// variables which can only be found through root finding. There are
53 /// sufficient conditions for a set of conservative variables to satisfy the
54 /// inequality, which can be used to avoid root finding at most points.
55 ///
56 /// \note The routine currently assumes the minimum specific enthalpy is one.
57 ///
58 /// For more details see Appendix B from the [thesis of Francois
59 /// Foucart](https://ecommons.cornell.edu/handle/1813/30652)
61  public:
62  /// \brief Minimum value of rest-mass density times lorentz factor
63  struct MinimumValueOfD {
64  using type = double;
65  static type lower_bound() noexcept { return 0.0; }
66  static constexpr OptionString help = {
67  "Minimum value of rest-mass density times lorentz factor"};
68  };
69  /// \brief Cutoff below which \f$D = \rho W\f$ is set to MinimumValueOfD
70  struct CutoffD {
71  using type = double;
72  static type lower_bound() noexcept { return 0.0; }
73  static constexpr OptionString help = {
74  "Cutoff below which D is set to MinimumValueOfD"};
75  };
76 
77  /// \brief Safety factor \f$\epsilon_B\f$.
79  using type = double;
80  static type lower_bound() noexcept { return 0.0; }
81  static constexpr OptionString help = {
82  "Safety factor for magnetic field bound."};
83  };
84  /// \brief Safety factor \f$\epsilon_S\f$.
86  using type = double;
87  static type lower_bound() noexcept { return 0.0; }
88  static constexpr OptionString help = {
89  "Safety factor for momentum density bound."};
90  };
91  using options =
92  tmpl::list<MinimumValueOfD, CutoffD, SafetyFactorForB, SafetyFactorForS>;
93  static constexpr OptionString help = {
94  "Variable fixing used in Foucart's thesis.\n"};
95 
96  FixConservatives(double minimum_rest_mass_density_times_lorentz_factor,
97  double rest_mass_density_times_lorentz_factor_cutoff,
98  double safety_factor_for_magnetic_field,
99  double safety_factor_for_momentum_density,
100  const OptionContext& context = {});
101 
102  FixConservatives() = default;
103  FixConservatives(const FixConservatives& /*rhs*/) = default;
104  FixConservatives& operator=(const FixConservatives& /*rhs*/) = default;
105  FixConservatives(FixConservatives&& /*rhs*/) noexcept = default;
106  FixConservatives& operator=(FixConservatives&& /*rhs*/) noexcept = default;
107  ~FixConservatives() = default;
108 
109  // NOLINTNEXTLINE(google-runtime-references)
110  void pup(PUP::er& p) noexcept;
111 
112  using return_tags = tmpl::list<grmhd::ValenciaDivClean::Tags::TildeD,
115  using argument_tags =
116  tmpl::list<grmhd::ValenciaDivClean::Tags::TildeB<>,
119 
120  void operator()(
122  gsl::not_null<Scalar<DataVector>*> tilde_tau,
123  gsl::not_null<tnsr::i<DataVector, 3, Frame::Inertial>*> tilde_s,
124  const tnsr::I<DataVector, 3, Frame::Inertial>& tilde_b,
125  const tnsr::ii<DataVector, 3, Frame::Inertial>& spatial_metric,
126  const tnsr::II<DataVector, 3, Frame::Inertial>& inv_spatial_metric,
127  const Scalar<DataVector>& sqrt_det_spatial_metric) const noexcept;
128 
129  private:
130  friend bool operator==(const FixConservatives& lhs,
131  const FixConservatives& rhs) noexcept;
132 
133  double minimum_rest_mass_density_times_lorentz_factor_{
135  double rest_mass_density_times_lorentz_factor_cutoff_{
137  double one_minus_safety_factor_for_magnetic_field_{
139  double one_minus_safety_factor_for_momentum_density_{
141 };
142 
143 bool operator!=(const FixConservatives& lhs,
144  const FixConservatives& rhs) noexcept;
145 
146 } // namespace VariableFixing
Minimum value of rest-mass density times lorentz factor.
Definition: FixConservatives.hpp:63
Safety factor .
Definition: FixConservatives.hpp:85
Cutoff below which is set to MinimumValueOfD.
Definition: FixConservatives.hpp:70
Definition: Strahlkorper.hpp:14
T signaling_NaN(T... args)
Definition: Tags.hpp:36
Defines classes and functions for making classes creatable from input files.
Definition: Tags.hpp:31
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:43
Safety factor .
Definition: FixConservatives.hpp:78
The densitized energy density .
Definition: Tags.hpp:50
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
The densitized momentum density .
Definition: Tags.hpp:57
Contains all variable fixers.
Definition: FixConservatives.cpp:55
Definition: Tags.hpp:26
Defines a list of useful type aliases for tensors.
The densitized rest-mass density .
Definition: Tags.hpp:44
Stores a collection of function values.
Definition: DataVector.hpp:46
Information about the nested operations being performed by the parser, for use in printing errors...
Definition: Options.hpp:36
Wraps the template metaprogramming library used (brigand)
Defines functions and classes from the GSL.
Fix conservative variables using method developed by Foucart.
Definition: FixConservatives.hpp:60
Tensor< T, Symmetry<>, index_list<> > Scalar
Scalar type.
Definition: TypeAliases.hpp:21
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12