Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <boost/preprocessor/arithmetic/dec.hpp> 7 : #include <boost/preprocessor/arithmetic/inc.hpp> 8 : #include <boost/preprocessor/control/expr_iif.hpp> 9 : #include <boost/preprocessor/list/adt.hpp> 10 : #include <boost/preprocessor/repetition/for.hpp> 11 : #include <boost/preprocessor/repetition/repeat.hpp> 12 : #include <boost/preprocessor/tuple/to_list.hpp> 13 : #include <cstddef> 14 : #include <limits> 15 : #include <pup.h> 16 : 17 : #include "DataStructures/Tensor/TypeAliases.hpp" 18 : #include "Options/String.hpp" 19 : #include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp" 20 : #include "PointwiseFunctions/Hydro/Units.hpp" 21 : #include "Utilities/Serialization/CharmPupable.hpp" 22 : #include "Utilities/TMPL.hpp" 23 : 24 : /// \cond 25 : class DataVector; 26 : /// \endcond 27 : 28 : namespace EquationsOfState { 29 : /*! 30 : * \ingroup EquationsOfStateGroup 31 : * 32 : * \brief Hybrid equation of state combining a barotropic EOS for cold 33 : * (zero-temperature) part with a simple thermal part 34 : * 35 : * The hybrid equation of state: 36 : * 37 : * \f[ 38 : * p = p_{cold}(\rho) + \rho (\Gamma_{th}-1) (\epsilon - \epsilon_{cold}(\rho)) 39 : * \f] 40 : * 41 : * where \f$p\f$ is the pressure, \f$\rho\f$ is the rest mass density, 42 : * \f$\epsilon\f$ is the specific internal energy, \f$p_{cold}\f$ and 43 : * \f$\epsilon_{cold}\f$ are the pressure and specific internal energy evaluated 44 : * using the cold EOS, and \f$\Gamma_{th}\f$ is the adiabatic index for the 45 : * thermal part. 46 : * 47 : * The temperature \f$T\f$ is defined as 48 : * 49 : * \f[ 50 : * T = (\Gamma_{th} - 1) (\epsilon - \epsilon_{cold}) 51 : * \f] 52 : * 53 : * This is the amount of internal energy above that of the cold EOS. 54 : * 55 : * For a hybrid EOS with the cold EOS being a polytrope we have 56 : * 57 : * \f{align} 58 : * p &= \kappa \rho^\Gamma + \rho T 59 : * =\kappa\rho^\Gamma+\rho 60 : * (\Gamma-1)\left(\epsilon-\frac{K\rho^{\Gamma-1}}{\Gamma-1}\right), \\ 61 : * T&=(\Gamma-1)\left(\epsilon-\frac{K\rho^{\Gamma-1}}{\Gamma-1}\right), \\ 62 : * \epsilon &= \frac{1}{(\Gamma-1)}\frac{p}{\rho} 63 : * \f} 64 : */ 65 : template <typename ColdEquationOfState> 66 1 : class HybridEos 67 : : public EquationOfState<ColdEquationOfState::is_relativistic, 2> { 68 : public: 69 0 : static constexpr size_t thermodynamic_dim = 2; 70 0 : static constexpr bool is_relativistic = ColdEquationOfState::is_relativistic; 71 : 72 0 : struct ColdEos { 73 0 : using type = ColdEquationOfState; 74 0 : static constexpr Options::String help = {"Cold equation of state"}; 75 0 : static std::string name() { 76 : return pretty_type::short_name<ColdEquationOfState>(); 77 : } 78 : }; 79 : 80 0 : struct ThermalAdiabaticIndex { 81 0 : using type = double; 82 0 : static constexpr Options::String help = {"Adiabatic index Gamma_th"}; 83 : }; 84 : 85 0 : static constexpr Options::String help = { 86 : "A hybrid equation of state combining a cold EOS with a simple thermal " 87 : "part. The pressure is related to the rest mass density by " 88 : " p = p_cold(rho) + rho * (Gamma_th - 1) * (epsilon - " 89 : "epsilon_cold(rho)), where p is the pressure, rho is the rest mass " 90 : "density, epsilon is the specific internal energy, p_cold and " 91 : "epsilon_cold are the pressure and specific internal energy evaluated " 92 : "using the cold EOS and Gamma_th is the adiabatic index for the thermal " 93 : "part."}; 94 : 95 0 : using options = tmpl::list<ColdEos, ThermalAdiabaticIndex>; 96 : 97 0 : HybridEos() = default; 98 0 : HybridEos(const HybridEos&) = default; 99 0 : HybridEos& operator=(const HybridEos&) = default; 100 0 : HybridEos(HybridEos&&) = default; 101 0 : HybridEos& operator=(HybridEos&&) = default; 102 0 : ~HybridEos() override = default; 103 : 104 0 : HybridEos(ColdEquationOfState cold_eos, double thermal_adiabatic_index); 105 : 106 : EQUATION_OF_STATE_FORWARD_DECLARE_MEMBERS(HybridEos, 2) 107 : 108 0 : WRAPPED_PUPable_decl_base_template( // NOLINT 109 : SINGLE_ARG(EquationOfState<is_relativistic, 2>), HybridEos); 110 : 111 0 : std::unique_ptr<EquationOfState<is_relativistic, 2>> get_clone() 112 : const override; 113 : 114 0 : std::unique_ptr<EquationOfState<is_relativistic, 3>> promote_to_3d_eos() 115 : const override; 116 : 117 : /// \brief Returns `true` if the EOS is barotropic 118 1 : bool is_barotropic() const override { return false; } 119 : 120 0 : bool operator==(const HybridEos<ColdEquationOfState>& rhs) const; 121 : 122 0 : bool operator!=(const HybridEos<ColdEquationOfState>& rhs) const; 123 : 124 0 : bool is_equal(const EquationOfState<is_relativistic, 2>& rhs) const override; 125 : 126 0 : static std::string name() { 127 : return "HybridEos(" + pretty_type::name<ColdEquationOfState>() + ")"; 128 : } 129 : 130 : /// The lower bound of the rest mass density that is valid for this EOS 131 1 : double rest_mass_density_lower_bound() const override { 132 : return cold_eos_.rest_mass_density_lower_bound(); 133 : } 134 : 135 : /// The upper bound of the rest mass density that is valid for this EOS 136 1 : double rest_mass_density_upper_bound() const override { 137 : return cold_eos_.rest_mass_density_upper_bound(); 138 : } 139 : 140 : /// The lower bound of the specific internal energy that is valid for this EOS 141 : /// at the given rest mass density \f$\rho\f$ 142 1 : double specific_internal_energy_lower_bound( 143 : const double rest_mass_density) const override { 144 : return get(cold_eos_.specific_internal_energy_from_density( 145 : Scalar<double>{rest_mass_density})); 146 : } 147 : 148 : /// The upper bound of the specific internal energy that is valid for this EOS 149 : /// at the given rest mass density \f$\rho\f$ 150 1 : double specific_internal_energy_upper_bound( 151 : const double /*rest_mass_density*/) const override { 152 : return std::numeric_limits<double>::max(); 153 : } 154 : 155 : /// The lower bound of the specific enthalpy that is valid for this EOS 156 1 : double specific_enthalpy_lower_bound() const override { 157 : return cold_eos_.specific_enthalpy_lower_bound(); 158 : } 159 : 160 : /// The vacuum baryon mass for this EoS 161 1 : double baryon_mass() const override { return cold_eos_.baryon_mass(); } 162 : 163 : private: 164 : EQUATION_OF_STATE_FORWARD_DECLARE_MEMBER_IMPLS(2) 165 : 166 0 : ColdEquationOfState cold_eos_; 167 0 : double thermal_adiabatic_index_ = 168 : std::numeric_limits<double>::signaling_NaN(); 169 : }; 170 : 171 : /// \cond 172 : template <typename ColdEquationOfState> 173 : PUP::able::PUP_ID EquationsOfState::HybridEos<ColdEquationOfState>::my_PUP_ID = 174 : 0; 175 : /// \endcond 176 : } // namespace EquationsOfState