Skip to content

Commit 43744af

Browse files
I think I got all the corrections done.
1 parent f3c0951 commit 43744af

File tree

3 files changed

+129
-101
lines changed

3 files changed

+129
-101
lines changed

doc/sphinx/src/models.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,11 @@ The constructor for the Simple MACAW EOS is
13671367
where ``A`` is :math:`A`, ``B`` is :math:`B`, ``Cvinf`` is :math:`C^\infty_v`,
13681368
``v0`` is :math:`v_0`, ``T0`` is :math:`T_0`, ``Gc`` is :math:`\Gamma_c`.
13691369

1370-
In order to maintain thermodynamic consistency, a sufficient set of constraints
1370+
In order to maintain thermodynamic stability, a sufficient set of constraints
13711371
is given by :math:`A > 0`, :math:`B > 0`, :math:`C^\infty_v > 0`, :math:`v_0 >
1372-
0`, :math:`T_0 > 0`, and :math:`\Gamma_c > 0`. If one wants to maintain
1373-
thermodynamic consistency, we also require :math:`\Gamma_c \in (0,1)`.
1374-
1372+
0`, :math:`T_0 > 0`, and :math:`\Gamma_c \in (0,1]`. One can still select
1373+
:math:`\Gamma_c > 1`, just note that the isothermal bulk modulus can be
1374+
negative (the isentropic bulk modulus will still be positive though).
13751375

13761376
JWL EOS
13771377
``````````

singularity-eos/eos/eos_simple_macaw.hpp

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
4545
PORTABLE_INLINE_FUNCTION
4646
SimpleMACAW(Real A, Real B, Real Cvinf, Real v0, Real T0, Real Gc,
4747
const MeanAtomicProperties &AZbar = MeanAtomicProperties())
48-
: _A(A), _B(B), _Cvinf(Cvinf), _v0(v0), _T0(T0), _Gc(Gc), _AZbar(AZbar) {
48+
: A_(A), B_(B), Cvinf_(Cvinf), v0_(v0), T0_(T0), Gc_(Gc), _AZbar(AZbar) {
4949
CheckParams();
5050
}
5151
SimpleMACAW GetOnDevice() { return *this; }
@@ -55,45 +55,45 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
5555
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
5656
/* Equation (18) */
5757
const Real Delta_e = sie - SieColdCurve(rho);
58-
const Real discriminant = Delta_e * (Delta_e + 4.0 * _Cvinf * _T0 * std::pow(rho * _v0, _Gc));
59-
return robust::ratio((Delta_e + std::sqrt(discriminant)), 2.0 * _Cvinf);
58+
const Real discriminant = Delta_e * (Delta_e + 4.0 * Cvinf_ * T0_ * std::pow(rho * v0_, Gc_));
59+
return robust::ratio((Delta_e + std::sqrt(discriminant)), 2.0 * Cvinf_);
6060
}
6161
PORTABLE_INLINE_FUNCTION void CheckParams() const {
62-
PORTABLE_ALWAYS_REQUIRE(_A >= 0, "Parameter, 'A', must be non-negative");
63-
PORTABLE_ALWAYS_REQUIRE(_B >= 0, "Parameter, 'B', must be non-negative");
64-
PORTABLE_ALWAYS_REQUIRE(_Cvinf > 0, "Specific heat capacity (at constant volume), `Cvinf`, must be positive");
65-
PORTABLE_ALWAYS_REQUIRE(_v0 > 0, "Reference specific volume, 'v0', must be positive");
66-
PORTABLE_ALWAYS_REQUIRE(_T0 >= 0, "Reference temperature, 'T0', must be non-negative");
67-
PORTABLE_ALWAYS_REQUIRE(_Gc > 0, "Gruneisen parameter, 'Gc', must be positive");
68-
if (_Gc > 1) {PORTABLE_WARN("Warning: Gruneisen coefficient greater than 1. Thermodynamic stability may be violated.");}
62+
PORTABLE_ALWAYS_REQUIRE(A_ >= 0, "Parameter, 'A', must be non-negative");
63+
PORTABLE_ALWAYS_REQUIRE(B_ >= 0, "Parameter, 'B', must be non-negative");
64+
PORTABLE_ALWAYS_REQUIRE(Cvinf_ > 0, "Specific heat capacity (at constant volume), `Cvinf`, must be positive");
65+
PORTABLE_ALWAYS_REQUIRE(v0_ > 0, "Reference specific volume, 'v0', must be positive");
66+
PORTABLE_ALWAYS_REQUIRE(T0_ >= 0, "Reference temperature, 'T0', must be non-negative");
67+
PORTABLE_ALWAYS_REQUIRE(Gc_ > 0, "Gruneisen parameter, 'Gc', must be positive");
68+
if (Gc_ > 1) {PORTABLE_WARN("Warning: Gruneisen coefficient greater than 1. Thermodynamic stability may be violated.");}
6969
_AZbar.CheckParams();
7070
}
7171
template <typename Indexer_t = Real *>
7272
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature(
7373
const Real rho, const Real temperature,
7474
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
7575
/* Equation (16) */
76-
return rho * (SieColdCurve(rho) + SieThermalPortion(rho, temperature));
76+
return SieColdCurve(rho) + _SieThermalPortion(rho, temperature);
7777
}
7878
template <typename Indexer_t = Real *>
7979
PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature(
8080
const Real rho, const Real temperature,
8181
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
8282
/* Equation (15) */
83-
return PressureColdCurve(rho) + PressureThermalPortion(rho, temperature);
83+
return PressureColdCurve(rho) + _PressureThermalPortion(rho, temperature);
8484
}
8585
template <typename Indexer_t = Real *>
8686
PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy(
8787
const Real rho, const Real sie,
8888
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
8989
/* Equation (19) */
90-
return PressureColdCurve(rho) + _Gc * rho * (sie - SieColdCurve(rho));
90+
return PressureColdCurve(rho) + Gc_ * rho * (sie - SieColdCurve(rho));
9191
}
9292
template <typename Indexer_t = Real *>
9393
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure(
9494
const Real rho, const Real P,
9595
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
96-
return SieColdCurve(rho) + robust::ratio(P - PressureColdCurve(rho), _Gc * rho);
96+
return SieColdCurve(rho) + robust::ratio(P - PressureColdCurve(rho), Gc_ * rho);
9797
}
9898

9999
// Entropy member functions
@@ -102,8 +102,8 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
102102
EntropyFromDensityTemperature(const Real rho, const Real temperature,
103103
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
104104
/* Equation (8) */
105-
const Real tau = robust::ratio(temperature, TemperatureScale(rho));
106-
return _Cvinf * (robust::ratio(tau, 1.0 + tau) + std::log(1.0 + tau));
105+
const Real tau = robust::ratio(temperature, _TemperatureScale(rho));
106+
return Cvinf_ * (robust::ratio(tau, 1.0 + tau) + std::log(1.0 + tau));
107107
}
108108
template <typename Indexer_t = Real *>
109109
PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy(
@@ -120,35 +120,14 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
120120
template <typename Indexer_t = Real *>
121121
PORTABLE_INLINE_FUNCTION Real SieColdCurve(
122122
const Real rho, Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
123-
const Real ratio = rho * _v0;
124-
return _A * _v0 * (std::pow(ratio, _B) + robust::ratio(_B, ratio) - (_B + 1.));
125-
}
126-
template <typename Indexer_t = Real *>
127-
PORTABLE_INLINE_FUNCTION Real SieThermalPortion(
128-
const Real rho, const Real T,
129-
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
130-
const Real ratio = rho * _v0;
131-
return _Cvinf * T * (1.0 - robust::ratio(_T0, _T0 + T * std::pow(ratio, -_Gc)));
123+
const Real ratio = rho * v0_;
124+
return A_ * v0_ * (std::pow(ratio, B_) + robust::ratio(B_, ratio) - (B_ + 1.));
132125
}
133126
template <typename Indexer_t = Real *>
134127
PORTABLE_INLINE_FUNCTION Real PressureColdCurve(
135128
const Real rho, Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
136-
const Real ratio = rho * _v0;
137-
return _A * _B * (std::pow(ratio, _B + 1.0) - 1.0);
138-
}
139-
template <typename Indexer_t = Real *>
140-
PORTABLE_INLINE_FUNCTION Real PressureThermalPortion(
141-
const Real rho, const Real T,
142-
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
143-
const Real numerator = rho * _Cvinf * _Gc * math_utils::pow<2>(T);
144-
const Real denominator = _T0 * std::pow(rho * _v0, _Gc) + T;
145-
return robust::ratio(numerator, denominator);
146-
}
147-
template <typename Indexer_t = Real *>
148-
PORTABLE_INLINE_FUNCTION Real TemperatureScale(
149-
const Real rho, Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
150-
/* Equation (13) */
151-
return _T0 * std::pow(rho * _v0, _Gc);
129+
const Real ratio = rho * v0_;
130+
return A_ * B_ * (std::pow(ratio, B_ + 1.0) - 1.0);
152131
}
153132

154133
// Specific heat capacity at constant volume
@@ -157,10 +136,10 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
157136
const Real rho, const Real temperature,
158137
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
159138
/* Equation (6) */
160-
const Real tau = robust::ratio(temperature, TemperatureScale(rho));
139+
const Real tau = robust::ratio(temperature, _TemperatureScale(rho));
161140
const Real numerator = math_utils::pow<2>(tau) + 2.0 * tau;
162141
const Real denominator = math_utils::pow<2>(tau + 1.0);
163-
return _Cvinf * robust::ratio(numerator, denominator);
142+
return Cvinf_ * robust::ratio(numerator, denominator);
164143
}
165144
template <typename Indexer_t = Real *>
166145
PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy(
@@ -182,8 +161,8 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
182161
const Real rho, const Real sie,
183162
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
184163
/* Equation (21) (multiplied by $\rho$ to get bulk mod) */
185-
const Real term1 = _A * _B * (_B + 1.0) * std::pow(rho * _v0, _B + 1.0);
186-
const Real term2 = _Gc * (_Gc + 1.0) * rho * (sie - SieColdCurve(rho));
164+
const Real term1 = A_ * B_ * (B_ + 1.0) * std::pow(rho * v0_, B_ + 1.0);
165+
const Real term2 = Gc_ * (Gc_ + 1.0) * rho * (sie - SieColdCurve(rho));
187166
return term1 + term2;
188167
}
189168
// Isothermal bulk modulus
@@ -194,10 +173,10 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
194173
/* Equation (22) (multiplied by $\rho$ to get bulk mod)
195174
* As mentioned in the paper, from the constraints on the parameters,
196175
* the isothermal bulk modulus is guaranteed to be positive. */
197-
const Real term1 = _A * _B * (_B + 1.0) * std::pow(rho * _v0, _B + 1.0);
198-
const Real numerator = rho * _T0 * (1.0 - _Gc) * std::pow(rho * _v0, 2.0 * _Gc) + temperature;
199-
const Real denominator = _T0 * std::pow(rho * _v0, _Gc) + temperature;
200-
return term1 + _Cvinf * _Gc * temperature * temperature * robust::ratio(numerator, denominator * denominator);
176+
const Real term1 = A_ * B_ * (B_ + 1.0) * std::pow(rho * v0_, B_ + 1.0);
177+
const Real numerator = rho * T0_ * (1.0 - Gc_) * std::pow(rho * v0_, 2.0 * Gc_) + temperature;
178+
const Real denominator = T0_ * std::pow(rho * v0_, Gc_) + temperature;
179+
return term1 + Cvinf_ * Gc_ * temperature * temperature * robust::ratio(numerator, denominator * denominator);
201180
}
202181
// Specific heat capacity at constant pressure
203182
template <typename Indexer_t = Real *>
@@ -215,28 +194,26 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
215194
PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature(
216195
const Real rho, const Real temperature,
217196
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
218-
return _Gc;
197+
return Gc_;
219198
}
220199
template <typename Indexer_t = Real *>
221200
PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy(
222201
const Real rho, const Real sie,
223202
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
224-
return _Gc;
203+
return Gc_;
225204
}
226205
template <typename Indexer_t = Real *>
227206
PORTABLE_INLINE_FUNCTION void
228207
FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod,
229208
const unsigned long output, Indexer_t &&lambda) const {
230209
if (output & thermalqs::density && output & thermalqs::specific_internal_energy) {
231-
if (output & thermalqs::pressure || output & thermalqs::temperature) {
232-
UNDEFINED_ERROR;
233-
}
210+
PORTABLE_ALWAYS_REQUIRE(!(output & thermalqs::pressure || output & thermalqs::temperature),
211+
"Cannot request more than two thermodynamic variables (rho, T, e, P)");
234212
DensityEnergyFromPressureTemperature(press, temp, lambda, rho, sie);
235213
}
236214
if (output & thermalqs::pressure && output & thermalqs::specific_internal_energy) {
237-
if (output & thermalqs::density || output & thermalqs::temperature) {
238-
UNDEFINED_ERROR;
239-
}
215+
PORTABLE_ALWAYS_REQUIRE(!(output & thermalqs::density || output & thermalqs::temperature),
216+
"Cannot request more than two thermodynamic variables (rho, T, e, P)");
240217
sie = InternalEnergyFromDensityTemperature(rho, temp, lambda);
241218
}
242219
if (output & thermalqs::temperature && output & thermalqs::specific_internal_energy) {
@@ -256,8 +233,8 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
256233
Real &bmod, Real &dpde, Real &dvdt,
257234
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
258235
// v_0 and T_0 are the only user selected reference state parameters
259-
rho = 1.0 / _v0;
260-
temp = _T0;
236+
rho = 1.0 / v0_;
237+
temp = T0_;
261238
press = PressureFromDensityTemperature(rho, temp);
262239
sie = InternalEnergyFromDensityTemperature(rho, temp);
263240

@@ -274,7 +251,7 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
274251
PORTABLE_INLINE_FUNCTION void PrintParams() const {
275252
printf("Simple MACAW Parameters:\nA = %g\nB = %g\nCvinf = %g\nv0 = %g\nT0 = %g\nGc = "
276253
"%g\n",
277-
_A, _B, _Cvinf, _v0, _T0, _Gc);
254+
A_, B_, Cvinf_, v0_, T0_, Gc_);
278255
_AZbar.PrintParams();
279256
}
280257
template <typename Indexer_t>
@@ -286,19 +263,19 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
286263

287264
// Setup lambda function for rho
288265
auto f = [=](const Real x /* density */){
289-
const Real term1 = _A * _B * (std::pow(_v0 * x, _B + 1.0) - 1.0) - press;
290-
const Real term2 = _T0 * std::pow(_v0 * x, _Gc) + temp;
291-
const Real term3 = _Cvinf * _Gc * temp * temp * x;
266+
const Real term1 = A_ * B_ * (std::pow(v0_ * x, B_ + 1.0) - 1.0) - press;
267+
const Real term2 = T0_ * std::pow(v0_ * x, Gc_) + temp;
268+
const Real term3 = Cvinf_ * Gc_ * temp * temp * x;
292269
return term1 * term2 + term3;
293270
};
294271

295272
const RootFinding1D::RootCounts root_info;
296273

297274
// Finding the density on pressure cold curve is a guaranteed upper bound
298-
const Real rho_high = std::pow(press / (_A * _B) + 1.0, 1.0 / (_B + 1.0)) / _v0;
275+
const Real rho_high = std::pow(press / (A_ * B_) + 1.0, 1.0 / (B_ + 1.0)) / v0_;
299276
const Real rho_low = 0.0; // zero density is valid for `f` defined above.
300277

301-
regula_falsi(f, 0.0 /*target*/, 1.0 / _v0 /*guess*/,
278+
regula_falsi(f, 0.0 /*target*/, 1.0 / v0_ /*guess*/,
302279
rho_low /*left bracket*/, rho_high /*right bracket*/,
303280
1.0e-9 /*x? tol*/, 1.0e-9 /*y? tol*/,
304281
rho, &root_info, true);
@@ -310,10 +287,35 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
310287
static std::string EosPyType() { return EosType(); }
311288

312289
private:
313-
Real _A, _B, _Cvinf, _v0, _T0, _Gc;
290+
Real A_, B_, Cvinf_, v0_, T0_, Gc_;
314291
MeanAtomicProperties _AZbar;
315292
static constexpr const unsigned long _preferred_input =
316293
thermalqs::density | thermalqs::specific_internal_energy;
294+
295+
template <typename Indexer_t = Real *>
296+
PORTABLE_INLINE_FUNCTION Real _TemperatureScale(
297+
const Real rho, Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
298+
/* Equation (13) */
299+
return T0_ * std::pow(rho * v0_, Gc_);
300+
}
301+
302+
template <typename Indexer_t = Real *>
303+
PORTABLE_INLINE_FUNCTION Real _SieThermalPortion(
304+
const Real rho, const Real T,
305+
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
306+
const Real ratio = rho * v0_;
307+
return Cvinf_ * T * (1.0 - robust::ratio(T0_, T0_ + T * std::pow(ratio, -Gc_)));
308+
}
309+
310+
template <typename Indexer_t = Real *>
311+
PORTABLE_INLINE_FUNCTION Real _PressureThermalPortion(
312+
const Real rho, const Real T,
313+
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
314+
const Real numerator = rho * Cvinf_ * Gc_ * math_utils::pow<2>(T);
315+
const Real denominator = T0_ * std::pow(rho * v0_, Gc_) + T;
316+
return robust::ratio(numerator, denominator);
317+
}
318+
317319
};
318320

319321
} // namespace singularity

0 commit comments

Comments
 (0)