Equations.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <string>
8 
10 #include "Domain/FaceNormal.hpp"
12 #include "Options/Options.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 template <typename>
18 class Variables;
19 
20 class DataVector;
21 
22 namespace gsl {
23 template <typename T>
24 class not_null;
25 } // namespace gsl
26 
27 namespace Tags {
28 template <typename>
29 struct NormalDotFlux;
30 template <typename>
31 struct Normalized;
32 } // namespace Tags
33 
34 namespace ScalarWave {
35 struct Pi;
36 template <size_t Dim>
37 struct Phi;
38 } // namespace ScalarWave
39 
40 namespace PUP {
41 class er;
42 } // namespace PUP
43 /// \endcond
44 
45 // IWYU pragma: no_forward_declare Tensor
46 
47 namespace ScalarWave {
48 /*!
49  * \brief Compute the time derivative of the evolved variables of the
50  * first-order scalar wave system.
51  *
52  * The evolution equations for the first-order scalar wave system are given by:
53  * \f{align}
54  * \partial_t\psi = & -\pi \\
55  * \partial_t\Phi_i = & -\partial_i \pi \\
56  * \partial_t\pi = & - \delta^{ij}\partial_i\Phi_j
57  * \f}
58  *
59  * where \f$\psi\f$ is the scalar field, \f$\pi=-\partial_t\psi\f$ is the
60  * conjugate momentum to \f$\psi\f$, and \f$\Phi_i=\partial_i\psi\f$ is an
61  * auxiliary variable.
62  */
63 template <size_t Dim>
64 struct ComputeDuDt {
65  using argument_tags =
66  tmpl::list<Pi, Tags::deriv<Pi, tmpl::size_t<Dim>, Frame::Inertial>,
67  Tags::deriv<Phi<Dim>, tmpl::size_t<Dim>, Frame::Inertial>>;
68  static void apply(
70  gsl::not_null<tnsr::i<DataVector, Dim, Frame::Inertial>*> dt_phi,
72  const tnsr::i<DataVector, Dim, Frame::Inertial>& d_pi,
73  const tnsr::ij<DataVector, Dim, Frame::Inertial>& d_phi) noexcept;
74 };
75 
76 /*!
77  * \brief Compute normal component of flux on a boundary.
78  *
79  * \f{align}
80  * F(\Psi) =& 0 \\
81  * F(\Pi) =& n^i \Phi_i \\
82  * F(\Phi_i) =& n_i \Pi
83  * \f}
84  */
85 template <size_t Dim>
87  using argument_tags =
88  tmpl::list<Pi, Phi<Dim>,
90  static void apply(gsl::not_null<Scalar<DataVector>*> pi_normal_dot_flux,
91  gsl::not_null<tnsr::i<DataVector, Dim, Frame::Inertial>*>
92  phi_normal_dot_flux,
93  gsl::not_null<Scalar<DataVector>*> psi_normal_dot_flux,
94  const Scalar<DataVector>& pi,
95  const tnsr::i<DataVector, Dim, Frame::Inertial>& phi,
96  const tnsr::i<DataVector, Dim, Frame::Inertial>&
97  interface_unit_normal) noexcept;
98 };
99 
100 /*!
101  * \ingroup NumericalFluxesGroup
102  * \brief Computes the upwind flux
103  *
104  * The upwind flux is given by:
105  * \f{align}
106  * F^*(\Psi) =& 0 \\
107  * F^*(\Pi) =& \frac{1}{2}\left(F(\Pi)_{\mathrm{int}} + F(\Pi)_{\mathrm{ext}}
108  * + \Pi_{\mathrm{int}} - \Pi_{\mathrm{ext}}\right) \\
109  * F^*(\Phi_i) =& \frac{1}{2} \left(F(\Phi_i)_{\mathrm{int}}
110  * + F(\Phi_i)_{\mathrm{ext}}
111  * + (n_i)_{\mathrm{int}} F(\Pi)_{\mathrm{int}}
112  * - (n_i)_{\mathrm{ext}} F(\Pi)_{\mathrm{ext}}\right)
113  * \f}
114  * where \f$F^*\f$ is the normal dotted with the numerical flux and \f$F\f$ is
115  * the normal dotted with the flux, which is computed in
116  * ScalarWave::ComputeNormalDotFluxes
117  */
118 template <size_t Dim>
119 struct UpwindFlux {
120  private:
121  struct NormalTimesFluxPi {
122  using type = tnsr::i<DataVector, Dim, Frame::Inertial>;
123  static std::string name() noexcept { return "NormalTimesFluxPi"; }
124  };
125 
126  public:
127  using options = tmpl::list<>;
128  static constexpr OptionString help = {
129  "Computes the upwind flux for a scalar wave system. It requires no "
130  "options."};
131 
132  // clang-tidy: non-const reference
133  void pup(PUP::er& /*p*/) noexcept {} // NOLINT
134 
135  // This is the data needed to compute the numerical flux.
136  // `dg::SendBoundaryFluxes` calls `package_data` to store these tags in a
137  // Variables. Local and remote values of this data are then combined in the
138  // `()` operator.
139  using package_tags =
140  tmpl::list<Tags::NormalDotFlux<Pi>, Tags::NormalDotFlux<Phi<Dim>>, Pi,
141  NormalTimesFluxPi>;
142 
143  // These tags on the interface of the element are passed to
144  // `package_data` to provide the data needed to compute the numerical fluxes.
145  using argument_tags =
146  tmpl::list<Tags::NormalDotFlux<Pi>, Tags::NormalDotFlux<Phi<Dim>>, Pi,
148 
149  // pseudo-interface: used internally by Algorithm infrastructure, not
150  // user-level code
151  // Following the not-null pointer to packaged_data, this function expects as
152  // arguments the databox types of the `argument_tags`.
153  void package_data(
154  gsl::not_null<Variables<package_tags>*> packaged_data,
155  const Scalar<DataVector>& normal_dot_flux_pi,
156  const tnsr::i<DataVector, Dim, Frame::Inertial>& normal_dot_flux_phi,
157  const Scalar<DataVector>& pi,
158  const tnsr::i<DataVector, Dim, Frame::Inertial>& interface_unit_normal)
159  const noexcept;
160 
161  // pseudo-interface: used internally by Algorithm infrastructure, not
162  // user-level code
163  // The arguments are first the system::variables_tag::tags_list wrapped in
164  // Tags::NormalDotNumericalFLux as not-null pointers to write the results
165  // into, then the package_tags on the interior side of the mortar followed by
166  // the package_tags on the exterior side.
167  void operator()(
168  gsl::not_null<Scalar<DataVector>*> pi_normal_dot_numerical_flux,
169  gsl::not_null<tnsr::i<DataVector, Dim, Frame::Inertial>*>
170  phi_normal_dot_numerical_flux,
171  gsl::not_null<Scalar<DataVector>*> psi_normal_dot_numerical_flux,
172  const Scalar<DataVector>& normal_dot_flux_pi_interior,
173  const tnsr::i<DataVector, Dim, Frame::Inertial>&
174  normal_dot_flux_phi_interior,
175  const Scalar<DataVector>& pi_interior,
176  const tnsr::i<DataVector, Dim, Frame::Inertial>&
177  normal_times_flux_pi_interior,
178  const Scalar<DataVector>& minus_normal_dot_flux_pi_exterior,
179  const tnsr::i<DataVector, Dim, Frame::Inertial>&
180  minus_normal_dot_flux_phi_exterior,
181  const Scalar<DataVector>& pi_exterior,
182  const tnsr::i<DataVector, Dim, Frame::Inertial>&
183  normal_times_flux_pi_exterior) const noexcept;
184 };
185 
186 /// Compute the maximum magnitude of the characteristic speeds.
188  using argument_tags = tmpl::list<>;
189  SPECTRE_ALWAYS_INLINE static constexpr double apply() noexcept { return 1.0; }
190 };
191 } // namespace ScalarWave
Prefix indicating a boundary unit normal vector dotted into the flux.
Definition: Prefixes.hpp:76
Definition: Strahlkorper.hpp:14
Implementations from the Guideline Support Library.
Definition: ConservativeFromPrimitive.hpp:10
The normalized (co)vector represented by Tag.
Definition: Magnitude.hpp:93
Defines classes and functions for making classes creatable from input files.
Compute normal component of flux on a boundary.
Definition: Equations.hpp:86
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
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 .
Definition: ComputeGhQuantities.cpp:58
#define SPECTRE_ALWAYS_INLINE
Always inline a function. Only use this if you benchmarked the code.
Definition: ForceInline.hpp:20
Items related to evolving the scalar wave equation:
Definition: Equations.cpp:20
Computes the upwind flux.
Definition: Equations.hpp:119
Compute the maximum magnitude of the characteristic speeds.
Definition: Equations.hpp:187
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&#39;s equations...
Definition: ComputeGhQuantities.cpp:22
Defines functions computing partial derivatives.
Defines macro to always inline a function.
Definition: DataBoxTag.hpp:29
Defines a list of useful type aliases for tensors.
Declares function unnormalized_face_normal.
Stores a collection of function values.
Definition: DataVector.hpp:46
Wraps the template metaprogramming library used (brigand)
Definition: IndexType.hpp:44
Compute the time derivative of the evolved variables of the first-order scalar wave system...
Definition: Equations.hpp:64
Definition: Tags.hpp:23
Tensor< T, Symmetry<>, index_list<> > Scalar
Scalar type.
Definition: TypeAliases.hpp:21
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12