Skip to content

Commit 1dd4793

Browse files
committed
Add lower bound for temperature for IdealFluid
1 parent b04c5fe commit 1dd4793

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

src/PointwiseFunctions/Hydro/EquationsOfState/IdealFluid.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
namespace EquationsOfState {
1414
template <bool IsRelativistic>
15-
IdealFluid<IsRelativistic>::IdealFluid(const double adiabatic_index)
16-
: adiabatic_index_(adiabatic_index) {}
15+
IdealFluid<IsRelativistic>::IdealFluid(const double adiabatic_index,
16+
const double min_temperature)
17+
: adiabatic_index_(adiabatic_index), min_temperature_(min_temperature) {}
1718

1819
EQUATION_OF_STATE_MEMBER_DEFINITIONS(template <bool IsRelativistic>,
1920
IdealFluid<IsRelativistic>, double, 2)
@@ -44,7 +45,8 @@ bool IdealFluid<IsRelativistic>::is_equal(
4445
template <bool IsRelativistic>
4546
bool IdealFluid<IsRelativistic>::operator==(
4647
const IdealFluid<IsRelativistic>& rhs) const {
47-
return adiabatic_index_ == rhs.adiabatic_index_;
48+
return (adiabatic_index_ == rhs.adiabatic_index_) and
49+
(min_temperature_ == rhs.min_temperature_);
4850
}
4951

5052
template <bool IsRelativistic>
@@ -61,6 +63,7 @@ template <bool IsRelativistic>
6163
void IdealFluid<IsRelativistic>::pup(PUP::er& p) {
6264
EquationOfState<IsRelativistic, 2>::pup(p);
6365
p | adiabatic_index_;
66+
p | min_temperature_;
6467
}
6568

6669
template <bool IsRelativistic>

src/PointwiseFunctions/Hydro/EquationsOfState/IdealFluid.hpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ class IdealFluid : public EquationOfState<IsRelativistic, 2> {
5555
static constexpr Options::String help = {"Adiabatic index gamma"};
5656
};
5757

58+
struct MinTemperature {
59+
using type = double;
60+
static type lower_bound() { return 0.0; }
61+
static constexpr Options::String help = {
62+
"Minimum temperature. "
63+
"This value must not be greater than or equal to 0.0"};
64+
};
65+
5866
static constexpr Options::String help = {
5967
"An ideal fluid equation of state.\n"
6068
"The pressure is related to the rest mass density by p = rho * epsilon * "
@@ -63,7 +71,7 @@ class IdealFluid : public EquationOfState<IsRelativistic, 2> {
6371
"index.\n"
6472
"The temperature T is defined as T=epsilon."};
6573

66-
using options = tmpl::list<AdiabaticIndex>;
74+
using options = tmpl::list<AdiabaticIndex, MinTemperature>;
6775

6876
IdealFluid() = default;
6977
IdealFluid(const IdealFluid&) = default;
@@ -72,7 +80,7 @@ class IdealFluid : public EquationOfState<IsRelativistic, 2> {
7280
IdealFluid& operator=(IdealFluid&&) = default;
7381
~IdealFluid() override = default;
7482

75-
explicit IdealFluid(double adiabatic_index);
83+
explicit IdealFluid(double adiabatic_index, double min_temperature = 0.0);
7684

7785
EQUATION_OF_STATE_FORWARD_DECLARE_MEMBERS(IdealFluid, 2)
7886

@@ -104,9 +112,13 @@ class IdealFluid : public EquationOfState<IsRelativistic, 2> {
104112

105113
/// The lower bound of the specific internal energy that is valid for this EOS
106114
/// at the given rest mass density \f$\rho\f$
115+
/// If non-zero lower bound for temperature is provided, then the lower bound
116+
/// for specific internal energy is also non-zero.
107117
double specific_internal_energy_lower_bound(
108118
const double /* rest_mass_density */) const override {
109-
return 0.0;
119+
return (min_temperature_ == 0.0)
120+
? 0.0
121+
: (min_temperature_) / (adiabatic_index_ - 1.0);
110122
}
111123

112124
/// The upper bound of the specific internal energy that is valid for this EOS
@@ -119,6 +131,11 @@ class IdealFluid : public EquationOfState<IsRelativistic, 2> {
119131
return IsRelativistic ? 1.0 : 0.0;
120132
}
121133

134+
/// The lower bound of the temperature that is valid for this EOS.
135+
/// Non-zero lower bound could be set to impose floor for the specific
136+
/// internal energy.
137+
double temperature_lower_bound() const override { return min_temperature_; }
138+
122139
/// The vacuum baryon mass for this EoS
123140
double baryon_mass() const override {
124141
return hydro::units::geometric::default_baryon_mass;
@@ -128,6 +145,7 @@ class IdealFluid : public EquationOfState<IsRelativistic, 2> {
128145
EQUATION_OF_STATE_FORWARD_DECLARE_MEMBER_IMPLS(2)
129146

130147
double adiabatic_index_ = std::numeric_limits<double>::signaling_NaN();
148+
double min_temperature_ = std::numeric_limits<double>::signaling_NaN();
131149
};
132150

133151
/// \cond

tests/Unit/PointwiseFunctions/Hydro/EquationsOfState/Test_Equilibrium3D.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SPECTRE_TEST_CASE("Unit.PointwiseFunctions.EquationsOfState.Equilibrium3D",
2727
const double ideal_adiabatic_index = 2.0;
2828
const double cold_polytropic_index = 2.0;
2929
const EoS::PolytropicFluid<true> cold_eos{100.0, cold_polytropic_index};
30-
const EoS::IdealFluid<true> eos_ideal_fluid{ideal_adiabatic_index};
30+
const EoS::IdealFluid<true> eos_ideal_fluid{ideal_adiabatic_index, 0.0};
3131

3232
EoS::Equilibrium3D<EoS::IdealFluid<true>> eos_ideal_fluid_3d{eos_ideal_fluid};
3333
const EoS::HybridEos<EoS::PolytropicFluid<true>> underlying_eos{

tests/Unit/PointwiseFunctions/Hydro/EquationsOfState/Test_IdealFluid.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ void check_bounds() {
6060
approx(hydro::units::geometric::default_baryon_mass));
6161
}
6262

63+
template <bool IsRelativistic>
64+
void check_nonzero_bounds() {
65+
const auto seed = std::random_device{}();
66+
MAKE_GENERATOR(generator, seed);
67+
CAPTURE(seed);
68+
const auto adiabatic_index = 1.5;
69+
CAPTURE(adiabatic_index);
70+
auto distribution = std::uniform_real_distribution<>{1.e-9, 1.e-5};
71+
auto min_temp = distribution(generator);
72+
CAPTURE(min_temp);
73+
const auto eos =
74+
EquationsOfState::IdealFluid<IsRelativistic>{adiabatic_index, min_temp};
75+
CHECK(min_temp == eos.temperature_lower_bound());
76+
CHECK(min_temp / (adiabatic_index - 1) ==
77+
eos.specific_internal_energy_lower_bound(1.0));
78+
}
79+
6380
} // namespace
6481

6582
SPECTRE_TEST_CASE("Unit.PointwiseFunctions.EquationsOfState.IdealFluid",
@@ -101,29 +118,35 @@ SPECTRE_TEST_CASE("Unit.PointwiseFunctions.EquationsOfState.IdealFluid",
101118
TestHelpers::test_creation<
102119
std::unique_ptr<EoS::EquationOfState<true, 2>>>(
103120
{"IdealFluid:\n"
104-
" AdiabaticIndex: 1.6666666666666667\n"}),
121+
" AdiabaticIndex: 1.6666666666666667\n"
122+
" MinTemperature: 0.0\n"}),
105123
"IdealFluid", "ideal_fluid", d_for_size, 5.0 / 3.0);
106124
TestHelpers::EquationsOfState::check(
107125
TestHelpers::test_creation<
108126
std::unique_ptr<EoS::EquationOfState<true, 2>>>(
109127
{"IdealFluid:\n"
110-
" AdiabaticIndex: 1.3333333333333333\n"}),
128+
" AdiabaticIndex: 1.3333333333333333\n"
129+
" MinTemperature: 0.0\n"}),
111130
"IdealFluid", "ideal_fluid", dv_for_size, 4.0 / 3.0);
112131

113132
TestHelpers::EquationsOfState::check(
114133
TestHelpers::test_creation<
115134
std::unique_ptr<EoS::EquationOfState<false, 2>>>(
116135
{"IdealFluid:\n"
117-
" AdiabaticIndex: 1.6666666666666667\n"}),
136+
" AdiabaticIndex: 1.6666666666666667\n"
137+
" MinTemperature: 0.0\n"}),
118138
"IdealFluid", "ideal_fluid", d_for_size, 5.0 / 3.0);
119139
TestHelpers::EquationsOfState::check(
120140
TestHelpers::test_creation<
121141
std::unique_ptr<EoS::EquationOfState<false, 2>>>(
122142
{"IdealFluid:\n"
123-
" AdiabaticIndex: 1.3333333333333333\n"}),
143+
" AdiabaticIndex: 1.3333333333333333\n"
144+
" MinTemperature: 0.0\n"}),
124145
"IdealFluid", "ideal_fluid", dv_for_size, 4.0 / 3.0);
125146

126147
check_bounds<true>();
127148
check_bounds<false>();
149+
check_nonzero_bounds<true>();
150+
check_nonzero_bounds<false>();
128151
check_dominant_energy_condition_at_bound();
129152
}

0 commit comments

Comments
 (0)