Line data Source code
1 0 :
2 : // Distributed under the MIT License.
3 : // See LICENSE.txt for details.
4 :
5 : #pragma once
6 :
7 : #include <cstddef>
8 :
9 : #include "DataStructures/Tensor/Tensor.hpp"
10 : #include "PointwiseFunctions/Hydro/TagsDeclarations.hpp"
11 : #include "Utilities/TMPL.hpp"
12 : #include "Utilities/TaggedTuple.hpp"
13 :
14 : namespace hydro {
15 :
16 : /// @{
17 : /*!
18 : * \brief Wrapper to add temperature variable to initial data
19 : * providing only density and or energy_density initialization.
20 : */
21 :
22 : template <typename DerivedSolution>
23 1 : class TemperatureInitialization {
24 : private:
25 : template <typename DataType, size_t Dim, typename... Args>
26 0 : auto variables_impl(const tnsr::I<DataType, Dim>& x,
27 : tmpl::list<hydro::Tags::Temperature<DataType>> /*meta*/,
28 : Args&... extra_args) const
29 : -> tuples::TaggedTuple<hydro::Tags::Temperature<DataType>> {
30 : const auto* derived = static_cast<DerivedSolution const*>(this);
31 : const auto& eos = derived->equation_of_state();
32 : if constexpr (std::decay_t<decltype(eos)>::thermodynamic_dim == 1) {
33 : return eos.temperature_from_density(
34 : get<hydro::Tags::RestMassDensity<DataType>>(derived->variables(
35 : x, extra_args...,
36 : tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})));
37 : } else if constexpr (std::decay_t<decltype(eos)>::thermodynamic_dim == 2) {
38 : return eos.temperature_from_density_and_energy(
39 : get<hydro::Tags::RestMassDensity<DataType>>(derived->variables(
40 : x, extra_args...,
41 : tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})),
42 : get<hydro::Tags::SpecificInternalEnergy<DataType>>(derived->variables(
43 : x, extra_args...,
44 : tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>>{})));
45 : } else {
46 : return eos.temperature_from_density_and_energy(
47 : get<hydro::Tags::RestMassDensity<DataType>>(derived->variables(
48 : x, extra_args...,
49 : tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})),
50 : get<hydro::Tags::SpecificInternalEnergy<DataType>>(derived->variables(
51 : x, extra_args...,
52 : tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>>{})),
53 : get<hydro::Tags::ElectronFraction<DataType>>(derived->variables(
54 : x, extra_args...,
55 : tmpl::list<hydro::Tags::ElectronFraction<DataType>>{})));
56 : }
57 : }
58 :
59 : public:
60 : template <typename DataType, size_t Dim>
61 0 : auto variables(const tnsr::I<DataType, Dim>& x,
62 : tmpl::list<hydro::Tags::Temperature<DataType>> /*meta*/) const
63 : -> tuples::TaggedTuple<hydro::Tags::Temperature<DataType>> {
64 : return variables_impl(x, tmpl::list<hydro::Tags::Temperature<DataType>>{});
65 : }
66 :
67 : template <typename DataType, size_t Dim>
68 0 : auto variables(const tnsr::I<DataType, Dim>& x, const double t,
69 : tmpl::list<hydro::Tags::Temperature<DataType>> /*meta*/) const
70 : -> tuples::TaggedTuple<hydro::Tags::Temperature<DataType>> {
71 : return variables_impl(x, tmpl::list<hydro::Tags::Temperature<DataType>>{},
72 : t);
73 : }
74 :
75 : template <typename ExtraVars, typename DataType, size_t Dim, typename... Args>
76 0 : auto variables(ExtraVars& extra_variables, const tnsr::I<DataType, Dim>& x,
77 : Args&... extra_args,
78 : tmpl::list<hydro::Tags::Temperature<DataType>> /*meta*/) const
79 : -> tuples::TaggedTuple<hydro::Tags::Temperature<DataType>> {
80 : const auto* derived = static_cast<DerivedSolution const*>(this);
81 : const auto& eos = derived->equation_of_state();
82 : if constexpr (std::decay_t<decltype(eos)>::thermodynamic_dim == 1) {
83 : return eos.temperature_from_density(
84 : get<hydro::Tags::RestMassDensity<DataType>>(derived->variables(
85 : extra_variables, x, extra_args...,
86 : tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})));
87 : } else if constexpr (std::decay_t<decltype(eos)>::thermodynamic_dim == 2) {
88 : return eos.temperature_from_density_and_energy(
89 : get<hydro::Tags::RestMassDensity<DataType>>(derived->variables(
90 : extra_variables, x, extra_args...,
91 : tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})),
92 : get<hydro::Tags::SpecificInternalEnergy<DataType>>(derived->variables(
93 : extra_variables, x, extra_args...,
94 : tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>>{})));
95 : } else {
96 : return eos.temperature_from_density_and_energy(
97 : get<hydro::Tags::RestMassDensity<DataType>>(derived->variables(
98 : extra_variables, x, extra_args...,
99 : tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})),
100 : get<hydro::Tags::SpecificInternalEnergy<DataType>>(derived->variables(
101 : extra_variables, x, extra_args...,
102 : tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>>{})),
103 : get<hydro::Tags::ElectronFraction<DataType>>(derived->variables(
104 : extra_variables, x, extra_args...,
105 : tmpl::list<hydro::Tags::ElectronFraction<DataType>>{})));
106 : }
107 : }
108 : };
109 : /// @}
110 :
111 : } // namespace hydro
|