12 NasaThermo::NasaThermo() :
20 "Cantera 2.2. Use GeneralSpeciesThermo instead.");
24 NasaThermo::NasaThermo(
const NasaThermo& right) :
33 NasaThermo& NasaThermo::operator=(
const NasaThermo& right)
42 SpeciesThermo::operator=(right);
63 doublereal min_temp, doublereal max_temp,
64 doublereal ref_pressure)
68 "Incompatible thermo parameterization: Got " +
76 std::vector<NasaPoly1> v;
87 doublereal tlow = min_temp;
88 doublereal tmid = c[0];
89 doublereal thigh = max_temp;
98 ref_pressure, &chigh[0]));
100 ref_pressure, &clow[0]));
104 if (
m_tlow.size() < index + 1) {
105 m_tlow.resize(index + 1, tlow);
106 m_thigh.resize(index + 1, thigh);
112 }
else if (fabs(
m_p0 - ref_pressure) > 0.1) {
113 std::string logmsg =
" ERROR NasaThermo: New Species, " + name +
", has a different reference pressure, "
114 +
fp2str(ref_pressure) +
", than existing reference pressure, " +
fp2str(
m_p0) +
"\n";
116 logmsg =
" This is now a fatal error\n";
118 throw CanteraError(
"install()",
"species have different reference pressures");
125 doublereal* h_RT, doublereal* s_R)
const
136 const std::vector<NasaPoly1> &mlg =
m_low[grp-1];
139 doublereal tmid = nlow->
maxTemp();
143 const std::vector<NasaPoly1> &mhg =
m_high[grp-1];
150 doublereal* h_RT, doublereal* s_R)
const
161 std::vector<NasaPoly1>::const_iterator _begin, _end;
164 _begin =
m_high[i].begin();
167 _begin =
m_low[i].begin();
168 _end =
m_low[i].end();
170 for (; _begin != _end; ++_begin) {
171 _begin->updateProperties(&
m_t[0], cp_R, h_RT, s_R);
180 doublereal& refPressure)
const
186 const std::vector<NasaPoly1> &mlg =
m_low[grp-1];
187 const std::vector<NasaPoly1> &mhg =
m_high[grp-1];
191 doublereal tmid = lowPoly->
maxTemp();
198 throw CanteraError(
"NasaThermo::reportParams",
"Index mismatch");
200 if (itype !=
NASA1) {
202 "Thermo type mismatch for low-T polynomial");
207 throw CanteraError(
"NasaThermo::reportParams",
"Index mismatch");
209 if (itype !=
NASA1) {
211 "Thermo type mismatch for high-T polynomial");
214 throw CanteraError(
"NasaThermo::reportParams",
"Thermo type mismatch");
222 const std::vector<NasaPoly1> &mlg =
m_low[grp-1];
224 doublereal tmid = nlow->
maxTemp();
225 if (298.15 <= tmid) {
228 const std::vector<NasaPoly1> &mhg =
m_high[grp-1];
238 std::vector<NasaPoly1> &mlg =
m_low[grp-1];
240 std::vector<NasaPoly1> &mhg =
m_high[grp-1];
242 doublereal tmid = nlow->
maxTemp();
245 double delH = Hf298New - hnow;
246 if (298.15 <= tmid) {
249 double hnew = h + delH;
254 double hnew = h + delH;
261 return poly4(t, c+2);
265 return c[2] + 0.5*c[3]*t + 1.0/3.0*c[4]*t*t
266 + 0.25*c[5]*t*t*t + 0.2*c[6]*t*t*t*t
271 return c[2]*log(t) + c[3]*t + 0.5*c[4]*t*t
272 + 1.0/3.0*c[5]*t*t*t + 0.25*c[6]*t*t*t*t
277 doublereal* clow, doublereal* chigh)
280 doublereal cplow =
cp_R(tmid, clow);
281 doublereal cphigh =
cp_R(tmid, chigh);
282 doublereal delta = cplow - cphigh;
283 doublereal maxError = std::abs(delta);
284 if (fabs(delta/(fabs(cplow)+1.0E-4)) > 0.001) {
285 writelog(
"\n\n**** WARNING ****\nFor species "+name+
286 ", discontinuity in cp/R detected at Tmid = "
288 writelog(
"\tValue computed using low-temperature polynomial: "
290 writelog(
"\tValue computed using high-temperature polynomial: "
297 delta = hrtlow - hrthigh;
298 maxError = std::max(std::abs(delta), maxError);
299 if (fabs(delta/(fabs(hrtlow)+cplow*tmid)) > 0.001) {
300 writelog(
"\n\n**** WARNING ****\nFor species "+name+
301 ", discontinuity in h/RT detected at Tmid = "
303 writelog(
"\tValue computed using low-temperature polynomial: "
305 writelog(
"\tValue computed using high-temperature polynomial: "
310 doublereal srlow =
entropy_R(tmid, clow);
311 doublereal srhigh =
entropy_R(tmid, chigh);
312 delta = srlow - srhigh;
313 maxError = std::max(std::abs(delta), maxError);
314 if (fabs(delta/(fabs(srlow)+cplow)) > 0.001) {
315 writelog(
"\n\n**** WARNING ****\nFor species "+name+
316 ", discontinuity in s/R detected at Tmid = "
318 writelog(
"\tValue computed using low-temperature polynomial: "
320 writelog(
"\tValue computed using high-temperature polynomial: "
328 doublereal Thigh, doublereal* clow,
378 const size_t nTemps = 12;
379 const size_t nCols = 11;
380 const size_t nRows = 3*nTemps;
383 doublereal sqrtDeltaT = sqrt(Thigh) - sqrt(Tlow);
385 for (
size_t j = 0; j < nTemps; j++) {
386 double T = pow(sqrt(Tlow) + sqrtDeltaT * j / (nTemps - 1.0), 2);
388 double logt = std::log(t);
390 for (
int i = 1; i <= 4; i++) {
405 for (
int i = 1; i <= 4; i++) {
407 M(n+1,i) = tpow[i] / (i+1);
408 M(n+2,i) = tpow[i] / i;
410 b[n] =
cp_R(T, clow);
414 for (
int i = 1; i <= 4; i++) {
416 M(n,i+6) = tpow[i] - 1.0;
417 M(n+1,i) = 1 - i / ((i + 1.0) * t);
418 M(n+1,i+6) = -1 + tpow[i] / (i+1) + i / ((i+1) * t);
419 M(n+2,i) = logt + 1.0 / i;
420 M(n+2,i+6) = -logt + (tpow[i] - 1.0) / i;
422 b[n] =
cp_R(T, chigh);
435 ct_dgelss(nRows, nCols, 1, &M(0,0), nRows, &b[0], nRows,
436 &sigma[0], -1, rank, &work[0], lwork, info);
437 work.resize(static_cast<size_t>(work[0]));
438 lwork =
static_cast<int>(work[0]);
439 ct_dgelss(nRows, nCols, 1, &M(0,0), nRows, &b[0], nRows,
440 &sigma[0], -1, rank, &work[0], lwork, info);
451 clow[2] = chigh[2] = b[0];
452 clow[0] = chigh[0] = b[5];
453 clow[1] = chigh[1] = b[6];
454 for (
int i = 1; i <= 4; i++) {
457 chigh[2] += clow[2+i] - chigh[2+i];
458 chigh[0] += i / (i + 1.0) * (chigh[2+i] - clow[2+i]);
459 chigh[1] += (clow[2+i] - chigh[2+i]) / i;
463 for (
int i = 1; i <= 4; i++) {
464 clow[2+i] /= pow(Tmid, i);
465 chigh[2+i] /= pow(Tmid, i);
469 clow[1] -= clow[2] * std::log(Tmid);
470 chigh[1] -= chigh[2] * std::log(Tmid);
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1) ...
virtual doublereal reportOneHf298(const size_t k) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
doublereal m_thigh_min
Minimum value of the high temperature limit.
#define NASA
Two regions of 7 coefficient NASA Polynomials This is implemented in the class NasaPoly2 in NasaPoly2...
std::vector< std::vector< NasaPoly1 > > m_high
Vector of vector of NasaPoly1's for the high temp region.
virtual void update(doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
virtual int reportType(size_t index) const
This utility function reports the type of parameterization used for the species with index number ind...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
virtual void reportParams(size_t index, int &type, doublereal *const c, doublereal &minTemp, doublereal &maxTemp, doublereal &refPressure) const
doublereal m_tlow_max
Maximum value of the low temperature limit.
doublereal entropy_R(double t, const doublereal *c)
Compute the nondimensional entropy using the given NASA polynomial.
R poly4(D x, R *c)
Evaluates a polynomial of order 4.
void markInstalled(size_t k)
Mark species k as having its thermodynamic data installed.
#define NASA1
7 coefficient NASA Polynomials This is implemented in the class NasaPoly1 in NasaPoly1.h
virtual doublereal maxTemp() const
Returns the maximum temperature that the thermo parameterization is valid.
double checkContinuity(const std::string &name, double tmid, doublereal *clow, doublereal *chigh)
Adjust polynomials to be continuous at the midpoint temperature.
doublereal m_p0
Reference pressure (Pa)
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
doublereal cp_R(double t, const doublereal *c)
Compute the nondimensional heat capacity using the given NASA polynomial.
std::map< int, int > m_index
Map between the midpoint temperature, as an int, to the group number.
virtual void install(const std::string &name, size_t index, int type, const doublereal *c, doublereal min_temp, doublereal max_temp, doublereal ref_pressure)
install a new species thermodynamic property parameterization for one species.
Header for the 2 regime 7 coefficient NASA thermodynamic polynomials for multiple species in a phase...
vector_fp m_tmid
Vector of log temperature limits.
Base class for exceptions thrown by Cantera classes.
int m_ngroups
number of groups
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
vector_fp m_t
Vector of temperature polynomials.
virtual void modifyOneHf298(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of the standard state of one species in the phase (J ...
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
doublereal enthalpy_RT(double t, const doublereal *c)
Compute the nondimensional enthalpy using the given NASA polynomial.
std::map< size_t, size_t > m_posInGroup_map
std::map< size_t, std::string > m_name
Species name as a function of the species index.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
std::map< size_t, size_t > m_group_map
void fixDiscontinuities(doublereal Tlow, doublereal Tmid, doublereal Thigh, doublereal *clow, doublereal *chigh)
Adjust polynomials to be continuous at the midpoint temperature.
virtual void reportParameters(size_t &n, int &type, doublereal &tlow, doublereal &thigh, doublereal &pref, doublereal *const coeffs) const
This utility function reports back the type of parameterization and all of the parameters for the spe...
void writelog(const std::string &msg)
Write a message to the screen.
vector_fp m_thigh
Vector of low temperature limits (species index)
The NASA polynomial parameterization for one temperature range.
vector_fp m_tlow
Vector of low temperature limits (species index)
virtual doublereal reportHf298(doublereal *const h298=0) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
virtual void updateProperties(const doublereal *tt, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Update the properties for this species, given a temperature polynomial.
virtual void update_one(size_t k, doublereal t, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Like update(), but only updates the single species k.
std::vector< std::vector< NasaPoly1 > > m_low
Vector of vector of NasaPoly1's for the low temp region.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...