13 NasaThermo::NasaThermo() :
22 NasaThermo::NasaThermo(
const NasaThermo& right) :
31 NasaThermo& NasaThermo::operator=(
const NasaThermo& right)
60 doublereal min_temp, doublereal max_temp,
61 doublereal ref_pressure)
67 std::vector<NasaPoly1> v;
78 doublereal tlow = min_temp;
79 doublereal tmid = c[0];
80 doublereal thigh = max_temp;
85 if (!m_allow_discontinuities) {
87 if (maxError > 1e-6) {
90 "NasaThermo::install",
"Polynomials still not continuous");
95 ref_pressure, &chigh[0]));
97 ref_pressure, &clow[0]));
105 if (
m_tlow.size() < index + 1) {
106 m_tlow.resize(index + 1, tlow);
107 m_thigh.resize(index + 1, thigh);
113 }
else if (fabs(
m_p0 - ref_pressure) > 0.1) {
114 std::string logmsg =
" ERROR NasaThermo: New Species, " + name +
", has a different reference pressure, "
115 +
fp2str(ref_pressure) +
", than existing reference pressure, " +
fp2str(
m_p0) +
"\n";
117 logmsg =
" This is now a fatal error\n";
119 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
163 std::vector<NasaPoly1>::const_iterator _begin, _end;
166 _begin =
m_high[i].begin();
169 _begin =
m_low[i].begin();
170 _end =
m_low[i].end();
172 for (; _begin != _end; ++_begin) {
173 _begin->updateProperties(&
m_t[0], cp_R, h_RT, s_R);
182 doublereal& refPressure)
const
189 const std::vector<NasaPoly1> &mlg =
m_low[grp-1];
190 const std::vector<NasaPoly1> &mhg =
m_high[grp-1];
194 doublereal tmid = lowPoly->
maxTemp();
203 if (itype !=
NASA1) {
211 if (itype !=
NASA1) {
219 #ifdef H298MODIFY_CAPABILITY
220 doublereal NasaThermo::reportOneHf298(
const int k)
const
224 const std::vector<NasaPoly1> &mlg =
m_low[grp-1];
226 doublereal tmid = nlow->
maxTemp();
228 if (298.15 <= tmid) {
229 h = nlow->reportHf298(0);
231 const std::vector<NasaPoly1> &mhg =
m_high[grp-1];
232 const NasaPoly1* nhigh = &(mhg[pos]);
233 h = nhigh->reportHf298(0);
238 void NasaThermo::modifyOneHf298(
const int k,
const doublereal Hf298New)
242 std::vector<NasaPoly1> &mlg =
m_low[grp-1];
243 NasaPoly1* nlow = &(mlg[pos]);
244 std::vector<NasaPoly1> &mhg =
m_high[grp-1];
245 NasaPoly1* nhigh = &(mhg[pos]);
246 doublereal tmid = nlow->maxTemp();
248 double hnow = reportOneHf298(k);
249 double delH = Hf298New - hnow;
250 if (298.15 <= tmid) {
251 nlow->modifyOneHf298(k, Hf298New);
252 double h = nhigh->reportHf298(0);
253 double hnew = h + delH;
254 nhigh->modifyOneHf298(k, hnew);
256 nhigh->modifyOneHf298(k, Hf298New);
257 double h = nlow->reportHf298(0);
258 double hnew = h + delH;
259 nlow->modifyOneHf298(k, hnew);
266 return poly4(t, c+2);
270 return c[2] + 0.5*c[3]*t +
OneThird*c[4]*t*t
271 + 0.25*c[5]*t*t*t + 0.2*c[6]*t*t*t*t
276 return c[2]*log(t) + c[3]*t + 0.5*c[4]*t*t
277 +
OneThird*c[5]*t*t*t + 0.25*c[6]*t*t*t*t
282 doublereal* clow, doublereal* chigh)
285 doublereal cplow =
cp_R(tmid, clow);
286 doublereal cphigh =
cp_R(tmid, chigh);
287 doublereal delta = cplow - cphigh;
288 doublereal maxError = abs(delta);
289 if (fabs(delta/(fabs(cplow)+1.0E-4)) > 0.001) {
290 writelog(
"\n\n**** WARNING ****\nFor species "+name+
291 ", discontinuity in cp/R detected at Tmid = "
293 writelog(
"\tValue computed using low-temperature polynomial: "
295 writelog(
"\tValue computed using high-temperature polynomial: "
302 delta = hrtlow - hrthigh;
303 maxError = std::max(std::abs(delta), maxError);
304 if (fabs(delta/(fabs(hrtlow)+cplow*tmid)) > 0.001) {
305 writelog(
"\n\n**** WARNING ****\nFor species "+name+
306 ", discontinuity in h/RT detected at Tmid = "
308 writelog(
"\tValue computed using low-temperature polynomial: "
310 writelog(
"\tValue computed using high-temperature polynomial: "
315 doublereal srlow =
entropy_R(tmid, clow);
316 doublereal srhigh =
entropy_R(tmid, chigh);
317 delta = srlow - srhigh;
318 maxError = std::max(std::abs(delta), maxError);
319 if (fabs(delta/(fabs(srlow)+cplow)) > 0.001) {
320 writelog(
"\n\n**** WARNING ****\nFor species "+name+
321 ", discontinuity in s/R detected at Tmid = "
323 writelog(
"\tValue computed using low-temperature polynomial: "
325 writelog(
"\tValue computed using high-temperature polynomial: "
333 doublereal Thigh, doublereal* clow,
383 const size_t nTemps = 12;
384 const size_t nCols = 11;
385 const size_t nRows = 3*nTemps;
388 doublereal sqrtDeltaT = sqrt(Thigh) - sqrt(Tlow);
390 for (
size_t j = 0; j < nTemps; j++) {
391 double T = pow(sqrt(Tlow) + sqrtDeltaT * j / (nTemps - 1.0), 2);
393 double logt = std::log(t);
395 for (
int i = 1; i <= 4; i++) {
410 for (
int i = 1; i <= 4; i++) {
412 M(n+1,i) = tpow[i] / (i+1);
413 M(n+2,i) = tpow[i] / i;
415 b[n] =
cp_R(T, clow);
419 for (
int i = 1; i <= 4; i++) {
421 M(n,i+6) = tpow[i] - 1.0;
422 M(n+1,i) = 1 - i / ((i + 1.0) * t);
423 M(n+1,i+6) = -1 + tpow[i] / (i+1) + i / ((i+1) * t);
424 M(n+2,i) = logt + 1.0 / i;
425 M(n+2,i+6) = -logt + (tpow[i] - 1.0) / i;
427 b[n] =
cp_R(T, chigh);
440 ct_dgelss(nRows, nCols, 1, &M(0,0), nRows, &b[0], nRows,
441 &sigma[0], -1, rank, &work[0], lwork, info);
442 work.resize(work[0]);
444 ct_dgelss(nRows, nCols, 1, &M(0,0), nRows, &b[0], nRows,
445 &sigma[0], -1, rank, &work[0], lwork, info);
456 clow[2] = chigh[2] = b[0];
457 clow[0] = chigh[0] = b[5];
458 clow[1] = chigh[1] = b[6];
459 for (
int i = 1; i <= 4; i++) {
462 chigh[2] += clow[2+i] - chigh[2+i];
463 chigh[0] += i / (i + 1.0) * (chigh[2+i] - clow[2+i]);
464 chigh[1] += (clow[2+i] - chigh[2+i]) / i;
468 for (
int i = 1; i <= 4; i++) {
469 clow[2+i] /= pow(Tmid, i);
470 chigh[2+i] /= pow(Tmid, i);
474 clow[1] -= clow[2] * std::log(Tmid);
475 chigh[1] -= chigh[2] * std::log(Tmid);
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.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
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.
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
R poly4(D x, R *c)
Evaluates a polynomial of order 4.
#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.
const doublereal OneThird
1/3
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
vector_fp m_t
Vector of temperature polynomials.
#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...
NasaPoly2 & operator=(const NasaPoly2 &b)
Assignment operator.
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
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 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...