@@ -45,7 +45,7 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
45
45
PORTABLE_INLINE_FUNCTION
46
46
SimpleMACAW (Real A, Real B, Real Cvinf, Real v0, Real T0, Real Gc,
47
47
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) {
49
49
CheckParams ();
50
50
}
51
51
SimpleMACAW GetOnDevice () { return *this ; }
@@ -55,45 +55,45 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
55
55
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
56
56
/* Equation (18) */
57
57
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_ );
60
60
}
61
61
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." );}
69
69
_AZbar.CheckParams ();
70
70
}
71
71
template <typename Indexer_t = Real *>
72
72
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature (
73
73
const Real rho, const Real temperature,
74
74
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
75
75
/* Equation (16) */
76
- return rho * ( SieColdCurve (rho) + SieThermalPortion (rho, temperature) );
76
+ return SieColdCurve (rho) + _SieThermalPortion (rho, temperature);
77
77
}
78
78
template <typename Indexer_t = Real *>
79
79
PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature (
80
80
const Real rho, const Real temperature,
81
81
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
82
82
/* Equation (15) */
83
- return PressureColdCurve (rho) + PressureThermalPortion (rho, temperature);
83
+ return PressureColdCurve (rho) + _PressureThermalPortion (rho, temperature);
84
84
}
85
85
template <typename Indexer_t = Real *>
86
86
PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy (
87
87
const Real rho, const Real sie,
88
88
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
89
89
/* Equation (19) */
90
- return PressureColdCurve (rho) + _Gc * rho * (sie - SieColdCurve (rho));
90
+ return PressureColdCurve (rho) + Gc_ * rho * (sie - SieColdCurve (rho));
91
91
}
92
92
template <typename Indexer_t = Real *>
93
93
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure (
94
94
const Real rho, const Real P,
95
95
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);
97
97
}
98
98
99
99
// Entropy member functions
@@ -102,8 +102,8 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
102
102
EntropyFromDensityTemperature (const Real rho, const Real temperature,
103
103
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
104
104
/* 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));
107
107
}
108
108
template <typename Indexer_t = Real *>
109
109
PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy (
@@ -120,35 +120,14 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
120
120
template <typename Indexer_t = Real *>
121
121
PORTABLE_INLINE_FUNCTION Real SieColdCurve (
122
122
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 .));
132
125
}
133
126
template <typename Indexer_t = Real *>
134
127
PORTABLE_INLINE_FUNCTION Real PressureColdCurve (
135
128
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 );
152
131
}
153
132
154
133
// Specific heat capacity at constant volume
@@ -157,10 +136,10 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
157
136
const Real rho, const Real temperature,
158
137
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
159
138
/* Equation (6) */
160
- const Real tau = robust::ratio (temperature, TemperatureScale (rho));
139
+ const Real tau = robust::ratio (temperature, _TemperatureScale (rho));
161
140
const Real numerator = math_utils::pow<2 >(tau) + 2.0 * tau;
162
141
const Real denominator = math_utils::pow<2 >(tau + 1.0 );
163
- return _Cvinf * robust::ratio (numerator, denominator);
142
+ return Cvinf_ * robust::ratio (numerator, denominator);
164
143
}
165
144
template <typename Indexer_t = Real *>
166
145
PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy (
@@ -182,8 +161,8 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
182
161
const Real rho, const Real sie,
183
162
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
184
163
/* 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));
187
166
return term1 + term2;
188
167
}
189
168
// Isothermal bulk modulus
@@ -194,10 +173,10 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
194
173
/* Equation (22) (multiplied by $\rho$ to get bulk mod)
195
174
* As mentioned in the paper, from the constraints on the parameters,
196
175
* 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);
201
180
}
202
181
// Specific heat capacity at constant pressure
203
182
template <typename Indexer_t = Real *>
@@ -215,28 +194,26 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
215
194
PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature (
216
195
const Real rho, const Real temperature,
217
196
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
218
- return _Gc ;
197
+ return Gc_ ;
219
198
}
220
199
template <typename Indexer_t = Real *>
221
200
PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy (
222
201
const Real rho, const Real sie,
223
202
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
224
- return _Gc ;
203
+ return Gc_ ;
225
204
}
226
205
template <typename Indexer_t = Real *>
227
206
PORTABLE_INLINE_FUNCTION void
228
207
FillEos (Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod,
229
208
const unsigned long output, Indexer_t &&lambda) const {
230
209
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)" );
234
212
DensityEnergyFromPressureTemperature (press, temp, lambda, rho, sie);
235
213
}
236
214
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)" );
240
217
sie = InternalEnergyFromDensityTemperature (rho, temp, lambda);
241
218
}
242
219
if (output & thermalqs::temperature && output & thermalqs::specific_internal_energy) {
@@ -256,8 +233,8 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
256
233
Real &bmod, Real &dpde, Real &dvdt,
257
234
Indexer_t &&lambda = static_cast <Real *>(nullptr )) const {
258
235
// 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_ ;
261
238
press = PressureFromDensityTemperature (rho, temp);
262
239
sie = InternalEnergyFromDensityTemperature (rho, temp);
263
240
@@ -274,7 +251,7 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
274
251
PORTABLE_INLINE_FUNCTION void PrintParams () const {
275
252
printf (" Simple MACAW Parameters:\n A = %g\n B = %g\n Cvinf = %g\n v0 = %g\n T0 = %g\n Gc = "
276
253
" %g\n " ,
277
- _A, _B, _Cvinf, _v0, _T0, _Gc );
254
+ A_, B_, Cvinf_, v0_, T0_, Gc_ );
278
255
_AZbar.PrintParams ();
279
256
}
280
257
template <typename Indexer_t>
@@ -286,19 +263,19 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
286
263
287
264
// Setup lambda function for rho
288
265
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;
292
269
return term1 * term2 + term3;
293
270
};
294
271
295
272
const RootFinding1D::RootCounts root_info;
296
273
297
274
// 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_ ;
299
276
const Real rho_low = 0.0 ; // zero density is valid for `f` defined above.
300
277
301
- regula_falsi (f, 0.0 /* target*/ , 1.0 / _v0 /* guess*/ ,
278
+ regula_falsi (f, 0.0 /* target*/ , 1.0 / v0_ /* guess*/ ,
302
279
rho_low /* left bracket*/ , rho_high /* right bracket*/ ,
303
280
1.0e-9 /* x? tol*/ , 1.0e-9 /* y? tol*/ ,
304
281
rho, &root_info, true );
@@ -310,10 +287,35 @@ class SimpleMACAW : public EosBase<SimpleMACAW> {
310
287
static std::string EosPyType () { return EosType (); }
311
288
312
289
private:
313
- Real _A, _B, _Cvinf, _v0, _T0, _Gc ;
290
+ Real A_, B_, Cvinf_, v0_, T0_, Gc_ ;
314
291
MeanAtomicProperties _AZbar;
315
292
static constexpr const unsigned long _preferred_input =
316
293
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
+
317
319
};
318
320
319
321
} // namespace singularity
0 commit comments