CharacteristicHelpers.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 #include <limits>
9 #include <string>
10 #include <type_traits>
11 #include <unordered_map>
12 #include <utility>
13 
14 #include "DataStructures/Tags.hpp"
17 #include "Evolution/Systems/NewtonianEuler/Characteristics.hpp"
18 #include "Evolution/Systems/NewtonianEuler/SoundSpeedSquared.hpp"
19 #include "Evolution/Systems/NewtonianEuler/Tags.hpp"
20 #include "Utilities/Gsl.hpp"
21 #include "Utilities/TMPL.hpp"
22 #include "Utilities/TaggedTuple.hpp"
23 
24 namespace NewtonianEuler::Limiters {
25 
26 /*!
27  * \brief Compute the transform matrices between the conserved variables and
28  * the characteristic variables of the NewtonianEuler system.
29  *
30  * Wraps calls to `NewtonianEuler::right_eigenvectors` and
31  * `NewtonianEuler::left_eigenvectors`.
32  */
33 template <size_t VolumeDim, size_t ThermodynamicDim>
34 std::pair<Matrix, Matrix> right_and_left_eigenvectors(
35  const Scalar<double>& mean_density,
36  const tnsr::I<double, VolumeDim>& mean_momentum,
37  const Scalar<double>& mean_energy,
39  equation_of_state,
40  const tnsr::i<double, VolumeDim>& unit_normal) noexcept;
41 
42 // @{
43 /// \brief Compute characteristic fields from conserved fields
44 ///
45 /// Note that these functions apply the same transformation to every grid point
46 /// in the element, using the same matrix from `left_eigenvectors`.
47 /// This is in contrast to the characteristic transformation used in the
48 /// GeneralizedHarmonic upwind flux, which is computed pointwise.
49 ///
50 /// By using a fixed matrix of eigenvectors computed from the cell-averaged
51 /// fields, we ensure we can consistently transform back from the characteristic
52 /// variables even after applying the limiter (the limiter changes the pointwise
53 /// values but preserves the cell averages).
54 template <size_t VolumeDim>
55 void characteristic_fields(
60  char_means,
61  const tuples::TaggedTuple<
65  const Matrix& left) noexcept;
66 
67 template <size_t VolumeDim>
68 void characteristic_fields(
69  gsl::not_null<Scalar<DataVector>*> char_v_minus,
70  gsl::not_null<tnsr::I<DataVector, VolumeDim>*> char_v_momentum,
71  gsl::not_null<Scalar<DataVector>*> char_v_plus,
72  const Scalar<DataVector>& cons_mass_density,
73  const tnsr::I<DataVector, VolumeDim>& cons_momentum_density,
74  const Scalar<DataVector>& cons_energy_density, const Matrix& left) noexcept;
75 
76 template <size_t VolumeDim>
77 void characteristic_fields(
79  Variables<tmpl::list<NewtonianEuler::Tags::VMinus,
82  char_vars,
83  const Variables<tmpl::list<NewtonianEuler::Tags::MassDensityCons,
86  const Matrix& left) noexcept;
87 // @}
88 
89 /// \brief Compute conserved fields from characteristic fields
90 ///
91 /// Note that this function applies the same transformation to every grid point
92 /// in the element, using the same matrix from `right_eigenvectors`.
93 /// This is in contrast to the characteristic transformation used in the
94 /// GeneralizedHarmonic upwind flux, which is computed pointwise.
95 ///
96 /// By using a fixed matrix of eigenvectors computed from the cell-averaged
97 /// fields, we ensure we can consistently transform back from the characteristic
98 /// variables even after applying the limiter (the limiter changes the pointwise
99 /// values but preserves the cell averages).
100 template <size_t VolumeDim>
101 void conserved_fields_from_characteristic_fields(
102  gsl::not_null<Scalar<DataVector>*> cons_mass_density,
103  gsl::not_null<tnsr::I<DataVector, VolumeDim>*> cons_momentum_density,
104  gsl::not_null<Scalar<DataVector>*> cons_energy_density,
105  const Scalar<DataVector>& char_v_minus,
106  const tnsr::I<DataVector, VolumeDim>& char_v_momentum,
107  const Scalar<DataVector>& char_v_plus, const Matrix& right) noexcept;
108 
109 } // namespace NewtonianEuler::Limiters
Matrix
A dynamically sized matrix of doubles with column-major storage.
Definition: Matrix.hpp:19
NewtonianEuler::Tags::VMomentum
Definition: Tags.hpp:94
utility
EquationsOfState::EquationOfState
Base class for equations of state depending on whether or not the system is relativistic,...
Definition: EquationOfState.hpp:63
NewtonianEuler::Tags::VMinus
The characteristic fields of the NewtonianEuler system.
Definition: Tags.hpp:90
std::pair
Tags::Mean
Given the Tag holding a Tensor<DataVector, ...>, swap the DataVector with a double.
Definition: Tags.hpp:23
NewtonianEuler::Tags::MassDensityCons
The mass density of the fluid (as a conservative variable).
Definition: Tags.hpp:31
cstddef
array
NewtonianEuler::Tags::VPlus
Definition: Tags.hpp:97
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
NewtonianEuler::Tags::EnergyDensity
The energy density of the fluid.
Definition: Tags.hpp:45
Variables.hpp
NewtonianEuler::Tags::MomentumDensity
The momentum density of the fluid.
Definition: Tags.hpp:37
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
limits
Gsl.hpp
Tensor.hpp
unordered_map
type_traits
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183
string