Characteristics.hpp
1 // 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/DataVector.hpp"
12 #include "Domain/FaceNormal.hpp"
14 #include "Utilities/Gsl.hpp"
16 #include "Utilities/TMPL.hpp"
17 
18 /// \cond
19 template <typename>
20 class Variables;
21 
22 namespace Tags {
23 template <typename Tag>
24 struct Normalized;
25 } // namespace Tags
26 /// \endcond
27 
28 namespace ScalarWave {
29 // @{
30 /*!
31  * \brief Compute the characteristic speeds for the scalar wave system.
32  *
33  * Computes the speeds as described in "Optimal constraint projection for
34  * hyperbolic evolution systems" by Holst et al. \cite Holst2004wt
35  * [see text following Eq.(32)]. The characteristic fields' names used here
36  * differ from this paper:
37  *
38  * \f{align*}
39  * \mathrm{SpECTRE} && \mathrm{Holst} \\
40  * v^{\hat \psi} && Z^1 \\
41  * v^{\hat 0}_{i} && Z^{2}_{i} \\
42  * v^{\hat \pm} && u^{1\pm}
43  * \f}
44  *
45  * The corresponding characteristic speeds \f$\lambda_{\hat \alpha}\f$ are given
46  * in the text following Eq.(38) of \cite Holst2004wt :
47  *
48  * \f{align*}
49  * \lambda_{\hat \psi} =& 0 \\
50  * \lambda_{\hat 0} =& 0 \\
51  * \lambda_{\hat \pm} =& \pm 1.
52  * \f}
53  */
54 template <size_t Dim>
55 std::array<DataVector, 4> characteristic_speeds(
56  const tnsr::i<DataVector, Dim, Frame::Inertial>&
57  unit_normal_one_form) noexcept;
58 
59 template <size_t Dim>
60 void characteristic_speeds(
62  const tnsr::i<DataVector, Dim, Frame::Inertial>&
63  unit_normal_one_form) noexcept;
64 
65 namespace Tags {
66 template <size_t Dim>
70  using return_type = typename base::type;
71  using argument_tags =
72  tmpl::list<::Tags::Normalized<domain::Tags::UnnormalizedFaceNormal<Dim>>>;
73 
74  static void function(gsl::not_null<return_type*> char_speeds,
75  const tnsr::i<DataVector, Dim, Frame::Inertial>&
76  unit_normal_one_form) noexcept {
77  characteristic_speeds(char_speeds, unit_normal_one_form);
78  }
79 };
80 } // namespace Tags
81 // @}
82 
83 // @{
84 /*!
85  * \brief Computes characteristic fields from evolved fields
86  *
87  * \ref Tags::CharacteristicFieldsCompute and
88  * \ref Tags::EvolvedFieldsFromCharacteristicFieldsCompute convert between
89  * characteristic and evolved fields for the scalar-wave system.
90  *
91  * \ref Tags::CharacteristicFieldsCompute computes
92  * characteristic fields as described in "Optimal constraint projection for
93  * hyperbolic evolution systems" by Holst et al. \cite Holst2004wt .
94  * Their names used here differ from this paper:
95  *
96  * \f{align*}
97  * \mathrm{SpECTRE} && \mathrm{Holst} \\
98  * v^{\hat \psi} && Z^1 \\
99  * v^{\hat 0}_{i} && Z^{2}_{i} \\
100  * v^{\hat \pm} && u^{1\pm}
101  * \f}
102  *
103  * The characteristic fields \f${v}^{\hat \alpha}\f$ are given in terms of
104  * the evolved fields by Eq.(33) - (35) of \cite Holst2004wt, respectively:
105  *
106  * \f{align*}
107  * v^{\hat \psi} =& \psi \\
108  * v^{\hat 0}_{i} =& (\delta^k_i - n_i n^k) \Phi_{k} := P^k_i \Phi_{k} \\
109  * v^{\hat \pm} =& \Pi \pm n^i \Phi_{i} - \gamma_2\psi
110  * \f}
111  *
112  * where \f$\psi\f$ is the scalar field, \f$\Phi_{i}=\partial_i \psi\f$ is an
113  * auxiliary variable, \f$\Pi\f$ is a conjugate momentum, \f$\gamma_2\f$
114  * is a constraint damping parameter, and \f$n_k\f$ is the unit normal to the
115  * surface along which the characteristic fields are defined.
116  *
117  * \ref Tags::EvolvedFieldsFromCharacteristicFieldsCompute computes evolved
118  * fields \f$u_\alpha\f$ in terms of the characteristic fields. This uses the
119  * inverse of above relations:
120  *
121  * \f{align*}
122  * \psi =& v^{\hat \psi}, \\
123  * \Pi =& \frac{1}{2}(v^{\hat +} + v^{\hat -}) + \gamma_2 v^{\hat \psi}, \\
124  * \Phi_{i} =& \frac{1}{2}(v^{\hat +} - v^{\hat -}) n_i + v^{\hat 0}_{i}.
125  * \f}
126  *
127  * The corresponding characteristic speeds \f$\lambda_{\hat \alpha}\f$
128  * are computed by \ref Tags::CharacteristicSpeedsCompute .
129  */
130 template <size_t Dim>
131 Variables<tmpl::list<Tags::VPsi, Tags::VZero<Dim>, Tags::VPlus, Tags::VMinus>>
132 characteristic_fields(const Scalar<DataVector>& gamma_2,
133  const Scalar<DataVector>& psi,
134  const Scalar<DataVector>& pi,
135  const tnsr::i<DataVector, Dim, Frame::Inertial>& phi,
136  const tnsr::i<DataVector, Dim, Frame::Inertial>&
137  unit_normal_one_form) noexcept;
138 
139 template <size_t Dim>
140 void characteristic_fields(
141  gsl::not_null<Variables<
143  char_fields,
144  const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& psi,
145  const Scalar<DataVector>& pi,
146  const tnsr::i<DataVector, Dim, Frame::Inertial>& phi,
147  const tnsr::i<DataVector, Dim, Frame::Inertial>&
148  unit_normal_one_form) noexcept;
149 
150 namespace Tags {
151 template <size_t Dim>
155  using return_type = typename base::type;
156  using argument_tags =
157  tmpl::list<Tags::ConstraintGamma2, Psi, Pi, Phi<Dim>,
159 
160  static void function(const gsl::not_null<return_type*> char_fields,
161  const Scalar<DataVector>& gamma_2,
162  const Scalar<DataVector>& psi,
163  const Scalar<DataVector>& pi,
164  const tnsr::i<DataVector, Dim, Frame::Inertial>& phi,
165  const tnsr::i<DataVector, Dim, Frame::Inertial>&
166  unit_normal_one_form) noexcept {
167  characteristic_fields(char_fields, gamma_2, psi, pi, phi,
169  };
170 };
171 } // namespace Tags
172 // @}
173 
174 // @{
175 /*!
176  * \brief Compute evolved fields from characteristic fields.
177  *
178  * For expressions used here to compute evolved fields from characteristic ones,
179  * see \ref Tags::CharacteristicFieldsCompute.
180  */
181 template <size_t Dim>
182 Variables<tmpl::list<Psi, Pi, Phi<Dim>>>
183 evolved_fields_from_characteristic_fields(
184  const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& v_psi,
185  const tnsr::i<DataVector, Dim, Frame::Inertial>& v_zero,
186  const Scalar<DataVector>& v_plus, const Scalar<DataVector>& v_minus,
187  const tnsr::i<DataVector, Dim, Frame::Inertial>&
188  unit_normal_one_form) noexcept;
189 
190 template <size_t Dim>
191 void evolved_fields_from_characteristic_fields(
192  gsl::not_null<Variables<tmpl::list<Psi, Pi, Phi<Dim>>>*> evolved_fields,
193  const Scalar<DataVector>& gamma_2, const Scalar<DataVector>& v_psi,
194  const tnsr::i<DataVector, Dim, Frame::Inertial>& v_zero,
195  const Scalar<DataVector>& v_plus, const Scalar<DataVector>& v_minus,
196  const tnsr::i<DataVector, Dim, Frame::Inertial>&
197  unit_normal_one_form) noexcept;
198 
199 namespace Tags {
200 template <size_t Dim>
205  using return_type = typename base::type;
206  using argument_tags =
207  tmpl::list<Tags::ConstraintGamma2, Tags::VPsi, Tags::VZero<Dim>,
210 
211  static void function(const gsl::not_null<return_type*> evolved_fields,
212  const Scalar<DataVector>& gamma_2,
213  const Scalar<DataVector>& v_psi,
214  const tnsr::i<DataVector, Dim, Frame::Inertial>& v_zero,
215  const Scalar<DataVector>& v_plus,
216  const Scalar<DataVector>& v_minus,
217  const tnsr::i<DataVector, Dim, Frame::Inertial>&
218  unit_normal_one_form) noexcept {
219  evolved_fields_from_characteristic_fields(evolved_fields, gamma_2, v_psi,
220  v_zero, v_plus, v_minus,
222  };
223 };
224 } // namespace Tags
225 // @}
226 } // namespace ScalarWave
db::ComputeTag
Marks a DataBoxTag as being a compute item that executes a function.
Definition: Tag.hpp:109
ScalarWave::Tags::EvolvedFieldsFromCharacteristicFieldsCompute
Definition: Characteristics.hpp:201
GeneralizedHarmonic::pi
void pi(gsl::not_null< tnsr::aa< DataType, SpatialDim, Frame > * > pi, const Scalar< DataType > &lapse, const Scalar< DataType > &dt_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::I< DataType, SpatialDim, Frame > &dt_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ii< DataType, SpatialDim, Frame > &dt_spatial_metric, const tnsr::iaa< DataType, SpatialDim, Frame > &phi) noexcept
Computes the conjugate momentum of the spacetime metric .
ScalarWave::Tags::CharacteristicSpeedsCompute
Definition: Characteristics.hpp:67
ScalarWave::Tags::VPlus
Definition: Tags.hpp:78
ScalarWave::Phi
Definition: Tags.hpp:31
ScalarWave::Tags::CharacteristicFields
Definition: Tags.hpp:95
FaceNormal.hpp
Tags.hpp
ScalarWave::Tags::CharacteristicFieldsCompute
Definition: Characteristics.hpp:152
ScalarWave::Tags::VZero
Definition: Tags.hpp:74
Tags::Normalized
Definition: Magnitude.hpp:145
cstddef
MakeWithValue.hpp
array
ScalarWave::Tags::CharacteristicSpeeds
Definition: Tags.hpp:89
GeneralizedHarmonic::phi
void phi(gsl::not_null< tnsr::iaa< DataType, SpatialDim, Frame > * > phi, const Scalar< DataType > &lapse, const tnsr::i< DataType, SpatialDim, Frame > &deriv_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::iJ< DataType, SpatialDim, Frame > &deriv_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ijj< DataType, SpatialDim, Frame > &deriv_spatial_metric) noexcept
Computes the auxiliary variable used by the generalized harmonic formulation of Einstein's equations...
ScalarWave::Tags::VPsi
Tags corresponding to the characteristic fields of the flat-spacetime scalar-wave system.
Definition: Tags.hpp:69
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
Gsl.hpp
ScalarWave::Tags::EvolvedFieldsFromCharacteristicFields
Definition: Tags.hpp:101
Tensor.hpp
ScalarWave
Items related to evolving the scalar wave equation.
Definition: Characteristics.cpp:16
ScalarWave::Psi
Definition: Tags.hpp:20
StrahlkorperGr::unit_normal_one_form
void unit_normal_one_form(gsl::not_null< tnsr::i< DataVector, 3, Frame > * > result, const tnsr::i< DataVector, 3, Frame > &normal_one_form, const DataVector &one_over_one_form_magnitude) noexcept
Computes normalized unit normal one-form to a Strahlkorper.
ScalarWave::Tags::VMinus
Definition: Tags.hpp:82
ScalarWave::Pi
Definition: Tags.hpp:25
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183