Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <array>
7 : #include <cstddef>
8 :
9 : #include "DataStructures/DataBox/Tag.hpp"
10 : #include "DataStructures/Tensor/EagerMath/Magnitude.hpp"
11 : #include "DataStructures/Tensor/TypeAliases.hpp"
12 : #include "Domain/FaceNormal.hpp"
13 : #include "Evolution/Systems/GrMhd/ValenciaDivClean/Tags.hpp"
14 : #include "PointwiseFunctions/GeneralRelativity/TagsDeclarations.hpp"
15 : #include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
16 : #include "PointwiseFunctions/Hydro/TagsDeclarations.hpp"
17 : #include "Utilities/Gsl.hpp"
18 : #include "Utilities/TMPL.hpp"
19 :
20 : /// \cond
21 : class DataVector;
22 : namespace Tags {
23 : template <typename Tag>
24 : struct Normalized;
25 : } // namespace Tags
26 : /// \endcond
27 :
28 : namespace grmhd {
29 : namespace ValenciaDivClean {
30 :
31 : /// @{
32 : /*!
33 : * \brief Compute the characteristic speeds for the Valencia formulation of
34 : * GRMHD with divergence cleaning.
35 : *
36 : * Obtaining the exact form of the characteristic speeds involves the solution
37 : * of a nontrivial quartic equation for the fast and slow modes. Here we make
38 : * use of a common approximation in the literature (e.g. \cite Gammie2003)
39 : * where the resulting characteristic speeds are analogous to those of the
40 : * Valencia formulation of the 3-D relativistic Euler system
41 : * (see RelativisticEuler::Valencia::characteristic_speeds),
42 : *
43 : * \f{align*}
44 : * \lambda_2 &= \alpha \Lambda^- - \beta_n,\\
45 : * \lambda_{3, 4, 5, 6, 7} &= \alpha v_n - \beta_n,\\
46 : * \lambda_{8} &= \alpha \Lambda^+ - \beta_n,
47 : * \f}
48 : *
49 : * with the substitution
50 : *
51 : * \f{align*}
52 : * c_s^2 \longrightarrow c_s^2 + v_A^2(1 - c_s^2)
53 : * \f}
54 : *
55 : * in the definition of \f$\Lambda^\pm\f$. Here \f$v_A\f$ is the Alfvén
56 : * speed. In addition, two more speeds corresponding to the divergence cleaning
57 : * mode and the longitudinal magnetic field are added,
58 : *
59 : * \f{align*}
60 : * \lambda_1 = -\alpha - \beta_n,\\
61 : * \lambda_9 = \alpha - \beta_n.
62 : * \f}
63 : *
64 : * \note The ordering assumed here is such that, in the Newtonian limit,
65 : * the exact expressions for \f$\lambda_{2, 8}\f$, \f$\lambda_{3, 7}\f$,
66 : * and \f$\lambda_{4, 6}\f$ should reduce to the
67 : * corresponding fast modes, Alfvén modes, and slow modes, respectively.
68 : * See \cite Dedner2002 for a detailed description of the hyperbolic
69 : * characterization of Newtonian MHD. In terms of the primitive variables:
70 : *
71 : * \f{align*}
72 : * v^2 &= \gamma_{mn} v^m v^n \\
73 : * c_s^2 &= \frac{1}{h} \left[ \left( \frac{\partial p}{\partial \rho}
74 : * \right)_\epsilon +
75 : * \frac{p}{\rho^2} \left(\frac{\partial p}{\partial \epsilon}
76 : * \right)_\rho \right] \\
77 : * v_A^2 &= \frac{b^2}{b^2 + \rho h} \\
78 : * b^2 &= \frac{1}{W^2} \gamma_{mn} B^m B^n + \left( \gamma_{mn} B^m v^n
79 : * \right)^2
80 : * \f}
81 : *
82 : * where \f$\gamma_{mn}\f$ is the spatial metric, \f$\rho\f$ is the rest
83 : * mass density, \f$W = 1/\sqrt{1-v_i v^i}\f$ is the Lorentz factor, \f$h = 1 +
84 : * \epsilon + \frac{p}{\rho}\f$ is the specific enthalpy, \f$v^i\f$ is the
85 : * spatial velocity, \f$\epsilon\f$ is the specific internal energy, \f$p\f$ is
86 : * the pressure, and \f$B^i\f$ is the spatial magnetic field measured by an
87 : * Eulerian observer.
88 : */
89 : template <size_t ThermodynamicDim>
90 1 : std::array<DataVector, 9> characteristic_speeds(
91 : const Scalar<DataVector>& rest_mass_density,
92 : const Scalar<DataVector>& electron_fraction,
93 : const Scalar<DataVector>& specific_internal_energy,
94 : const Scalar<DataVector>& specific_enthalpy,
95 : const tnsr::I<DataVector, 3, Frame::Inertial>& spatial_velocity,
96 : const Scalar<DataVector>& lorentz_factor,
97 : const tnsr::I<DataVector, 3, Frame::Inertial>& magnetic_field,
98 : const Scalar<DataVector>& lapse, const tnsr::I<DataVector, 3>& shift,
99 : const tnsr::ii<DataVector, 3, Frame::Inertial>& spatial_metric,
100 : const tnsr::i<DataVector, 3>& unit_normal,
101 : const EquationsOfState::EquationOfState<true, ThermodynamicDim>&
102 : equation_of_state);
103 :
104 : template <size_t ThermodynamicDim>
105 1 : void characteristic_speeds(
106 : gsl::not_null<std::array<DataVector, 9>*> char_speeds,
107 : const Scalar<DataVector>& rest_mass_density,
108 : const Scalar<DataVector>& electron_fraction,
109 : const Scalar<DataVector>& specific_internal_energy,
110 : const Scalar<DataVector>& specific_enthalpy,
111 : const tnsr::I<DataVector, 3, Frame::Inertial>& spatial_velocity,
112 : const Scalar<DataVector>& lorentz_factor,
113 : const tnsr::I<DataVector, 3, Frame::Inertial>& magnetic_field,
114 : const Scalar<DataVector>& lapse, const tnsr::I<DataVector, 3>& shift,
115 : const tnsr::ii<DataVector, 3, Frame::Inertial>& spatial_metric,
116 : const tnsr::i<DataVector, 3>& unit_normal,
117 : const EquationsOfState::EquationOfState<true, ThermodynamicDim>&
118 : equation_of_state);
119 : /// @}
120 :
121 1 : namespace Tags {
122 : /// \brief Compute the characteristic speeds for the Valencia formulation of
123 : /// GRMHD with divergence cleaning.
124 : ///
125 : /// \details see grmhd::ValenciaDivClean::characteristic_speeds
126 1 : struct CharacteristicSpeedsCompute : Tags::CharacteristicSpeeds,
127 : db::ComputeTag {
128 0 : using base = Tags::CharacteristicSpeeds;
129 0 : using argument_tags =
130 : tmpl::list<hydro::Tags::RestMassDensity<DataVector>,
131 : hydro::Tags::ElectronFraction<DataVector>,
132 : hydro::Tags::SpecificInternalEnergy<DataVector>,
133 : hydro::Tags::SpecificEnthalpy<DataVector>,
134 : hydro::Tags::SpatialVelocity<DataVector, 3>,
135 : hydro::Tags::LorentzFactor<DataVector>,
136 : hydro::Tags::MagneticField<DataVector, 3>,
137 : gr::Tags::Lapse<DataVector>, gr::Tags::Shift<DataVector, 3>,
138 : gr::Tags::SpatialMetric<DataVector, 3>,
139 : ::Tags::Normalized<domain::Tags::UnnormalizedFaceNormal<3>>,
140 : hydro::Tags::GrmhdEquationOfState>;
141 :
142 0 : using volume_tags = tmpl::list<hydro::Tags::GrmhdEquationOfState>;
143 :
144 0 : using return_type = std::array<DataVector, 9>;
145 :
146 : template <size_t ThermodynamicDim>
147 0 : static constexpr void function(
148 : const gsl::not_null<return_type*> result,
149 : const Scalar<DataVector>& rest_mass_density,
150 : const Scalar<DataVector>& /* electron_fraction */,
151 : const Scalar<DataVector>& specific_internal_energy,
152 : const Scalar<DataVector>& specific_enthalpy,
153 : const tnsr::I<DataVector, 3, Frame::Inertial>& spatial_velocity,
154 : const Scalar<DataVector>& lorentz_factor,
155 : const tnsr::I<DataVector, 3, Frame::Inertial>& magnetic_field,
156 : const Scalar<DataVector>& lapse, const tnsr::I<DataVector, 3>& shift,
157 : const tnsr::ii<DataVector, 3, Frame::Inertial>& spatial_metric,
158 : const tnsr::i<DataVector, 3>& unit_normal,
159 : const EquationsOfState::EquationOfState<true, ThermodynamicDim>&
160 : equation_of_state) {
161 : characteristic_speeds<ThermodynamicDim>(
162 : result, rest_mass_density, specific_internal_energy, specific_enthalpy,
163 : spatial_velocity, lorentz_factor, magnetic_field, lapse, shift,
164 : spatial_metric, unit_normal, equation_of_state);
165 : }
166 : };
167 :
168 0 : struct LargestCharacteristicSpeed : db::SimpleTag {
169 0 : using type = double;
170 : };
171 :
172 0 : struct ComputeLargestCharacteristicSpeed : db::ComputeTag,
173 : LargestCharacteristicSpeed {
174 0 : using argument_tags =
175 : tmpl::list<gr::Tags::Lapse<DataVector>, gr::Tags::Shift<DataVector, 3>,
176 : gr::Tags::SpatialMetric<DataVector, 3>>;
177 0 : using return_type = double;
178 0 : using base = LargestCharacteristicSpeed;
179 0 : static void function(gsl::not_null<double*> speed,
180 : const Scalar<DataVector>& lapse,
181 : const tnsr::I<DataVector, 3>& shift,
182 : const tnsr::ii<DataVector, 3>& spatial_metric) {
183 : const auto shift_magnitude = magnitude(shift, spatial_metric);
184 : *speed = max(get(shift_magnitude) + get(lapse));
185 : }
186 : };
187 : } // namespace Tags
188 : } // namespace ValenciaDivClean
189 : } // namespace grmhd
|