TimeDerivativeTerms.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
11 #include "Evolution/Systems/NewtonianEuler/TagsDeclarations.hpp"
12 #include "Utilities/TMPL.hpp"
13 
14 /// \cond
15 namespace gsl {
16 template <typename T>
17 class not_null;
18 } // namespace gsl
19 
20 class DataVector;
21 /// \endcond
22 
23 namespace NewtonianEuler {
24 /// \cond
25 namespace Sources {
26 struct NoSource;
27 } // namespace Sources
28 /// \endcond
29 
30 namespace detail {
31 template <size_t Dim>
32 void fluxes_impl(
33  gsl::not_null<tnsr::I<DataVector, Dim>*> mass_density_cons_flux,
34  gsl::not_null<tnsr::IJ<DataVector, Dim>*> momentum_density_flux,
35  gsl::not_null<tnsr::I<DataVector, Dim>*> energy_density_flux,
36  gsl::not_null<Scalar<DataVector>*> enthalpy_density,
37  const tnsr::I<DataVector, Dim>& momentum_density,
38  const Scalar<DataVector>& energy_density,
39  const tnsr::I<DataVector, Dim>& velocity,
40  const Scalar<DataVector>& pressure) noexcept;
41 } // namespace detail
42 
43 /*!
44  * \brief Compute the time derivative of the conserved variables for the
45  * Newtonian Euler system
46  */
47 template <size_t Dim, typename InitialDataType>
49  private:
50  struct EnthalpyDensity : db::SimpleTag {
51  using type = Scalar<DataVector>;
52  };
53 
54  using SourceTerm = typename InitialDataType::source_term_type;
55  using argument_tags_flux =
56  tmpl::list<Tags::MomentumDensity<Dim>, Tags::EnergyDensity,
58 
59  public:
60  using temporary_tags = tmpl::list<EnthalpyDensity>;
61  using argument_tags = tmpl::append<
62  argument_tags_flux,
63  tmpl::conditional_t<std::is_same_v<SourceTerm, Sources::NoSource>,
64  tmpl::list<>,
65  tmpl::push_front<typename SourceTerm::argument_tags,
67 
68  template <typename... SourceTermArgs>
69  static void apply(
70  // Time derivatives returned by reference. All the tags in the
71  // variables_tag in the system struct.
72  const gsl::not_null<Scalar<DataVector>*> non_flux_terms_dt_mass_density,
73  const gsl::not_null<tnsr::I<DataVector, Dim>*>
74  non_flux_terms_dt_momentum_density,
75  const gsl::not_null<Scalar<DataVector>*> non_flux_terms_dt_energy_density,
76 
77  // Fluxes returned by reference. Listed in the system struct as
78  // flux_variables.
79  const gsl::not_null<tnsr::I<DataVector, Dim>*> mass_density_cons_flux,
80  const gsl::not_null<tnsr::IJ<DataVector, Dim>*> momentum_density_flux,
81  const gsl::not_null<tnsr::I<DataVector, Dim>*> energy_density_flux,
82 
83  // Temporaries returned by reference. Listed in temporary_tags above.
84  const gsl::not_null<Scalar<DataVector>*> enthalpy_density,
85 
86  // Arguments listed in argument_tags above
87  const tnsr::I<DataVector, Dim>& momentum_density,
88  const Scalar<DataVector>& energy_density,
89  const tnsr::I<DataVector, Dim>& velocity,
90  const Scalar<DataVector>& pressure, const SourceTerm& source,
91  const SourceTermArgs&... source_term_args) noexcept {
92  detail::fluxes_impl(mass_density_cons_flux, momentum_density_flux,
93  energy_density_flux, enthalpy_density, momentum_density,
94  energy_density, velocity, pressure);
95  if constexpr (not std::is_same_v<SourceTerm, Sources::NoSource>) {
96  sources_impl(
97  std::make_tuple(non_flux_terms_dt_mass_density,
98  non_flux_terms_dt_momentum_density,
99  non_flux_terms_dt_energy_density),
100  typename InitialDataType::source_term_type::sourced_variables{},
101  source, source_term_args...);
102  }
103  }
104 
105  static void apply(
106  // Time derivatives returned by reference. No source terms or
107  // nonconservative products, so not used. All the tags in the
108  // variables_tag in the system struct.
109  const gsl::not_null<
110  Scalar<DataVector>*> /*non_flux_terms_dt_mass_density*/,
111  const gsl::not_null<
112  tnsr::I<DataVector, Dim>*> /*non_flux_terms_dt_momentum_density*/,
113  const gsl::not_null<
114  Scalar<DataVector>*> /*non_flux_terms_dt_energy_density*/,
115 
116  // Fluxes returned by reference. Listed in the system struct as
117  // flux_variables.
118  const gsl::not_null<tnsr::I<DataVector, Dim>*> mass_density_cons_flux,
119  const gsl::not_null<tnsr::IJ<DataVector, Dim>*> momentum_density_flux,
120  const gsl::not_null<tnsr::I<DataVector, Dim>*> energy_density_flux,
121 
122  // Temporaries returned by reference. Listed in temporary_tags above.
123  const gsl::not_null<Scalar<DataVector>*> enthalpy_density,
124 
125  // Arguments listed in argument_tags above
126  const tnsr::I<DataVector, Dim>& momentum_density,
127  const Scalar<DataVector>& energy_density,
128  const tnsr::I<DataVector, Dim>& velocity,
129  const Scalar<DataVector>& pressure) noexcept {
130  detail::fluxes_impl(mass_density_cons_flux, momentum_density_flux,
131  energy_density_flux, enthalpy_density, momentum_density,
132  energy_density, velocity, pressure);
133  }
134 
135  private:
136  using non_flux_terms_dt_vars_list =
137  tmpl::list<Tags::MassDensityCons, Tags::MomentumDensity<Dim>,
139 
140  template <typename... SourceTermArgs, typename... SourcedVars>
141  static void sources_impl(std::tuple<gsl::not_null<Scalar<DataVector>*>,
142  gsl::not_null<tnsr::I<DataVector, Dim>*>,
144  non_flux_terms_dt_vars,
145  tmpl::list<SourcedVars...> /*meta*/,
146  const SourceTerm& source,
147  const SourceTermArgs&... source_term_args) noexcept {
148  source.apply(
149  std::get<
150  tmpl::index_of<non_flux_terms_dt_vars_list, SourcedVars>::value>(
151  non_flux_terms_dt_vars)...,
152  source_term_args...);
153  }
154 };
155 
156 } // namespace NewtonianEuler
domain::push_front
CoordinateMap< SourceFrame, TargetFrame, NewMap, Maps... > push_front(CoordinateMap< SourceFrame, TargetFrame, Maps... > old_map, NewMap new_map) noexcept
Creates a CoordinateMap by prepending the new map to the beginning of the old maps.
DataBoxTag.hpp
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:639
std::tuple
db::SimpleTag
Tags for the DataBox inherit from this type.
Definition: Tag.hpp:23
NewtonianEuler
Items related to evolving the Newtonian Euler system.
Definition: EvolveNewtonianEulerFwd.hpp:8
NewtonianEuler::TimeDerivativeTerms
Compute the time derivative of the conserved variables for the Newtonian Euler system.
Definition: TimeDerivativeTerms.hpp:48
NewtonianEuler::Tags::SourceTerm
The source term in the evolution equations.
Definition: Tags.hpp:107
cstddef
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:42
NewtonianEuler::Tags::Pressure
The fluid pressure.
Definition: Tags.hpp:66
NewtonianEuler::Tags::EnergyDensity
The energy density of the fluid.
Definition: Tags.hpp:45
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
TypeAliases.hpp
NewtonianEuler::Tags::Velocity
The macroscopic or flow velocity of the fluid.
Definition: Tags.hpp:51
Prefixes.hpp
gsl
Implementations from the Guideline Support Library.
Definition: Gsl.hpp:80
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183