Added "getParameter" routines to most of the species and phase
thermo objects. Fixed a bug in NasaThermo::update_one() and ShomateThermo::update_one() that occurred because m_low_map and m_high_map contained bad information. They were maps to fixed pointers, but the location of the objects that they referred to changed during vector resizing operations.
This commit is contained in:
parent
efdfdf83cd
commit
366928ba51
12 changed files with 290 additions and 55 deletions
|
|
@ -170,6 +170,12 @@ namespace Cantera {
|
|||
setDensity(c[0]);
|
||||
}
|
||||
|
||||
virtual void getParameters(int &n, doublereal * const c) {
|
||||
double d = density();
|
||||
c[0] = d;
|
||||
n = 1;
|
||||
}
|
||||
|
||||
virtual void setParametersFromXML(const XML_Node& eosdata);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace Cantera {
|
|||
copy(coeffs, coeffs + 7, m_coeff.begin());
|
||||
}
|
||||
|
||||
virtual ~NasaPoly1(){}
|
||||
~NasaPoly1(){}
|
||||
|
||||
doublereal minTemp() const { return m_lowT;}
|
||||
doublereal maxTemp() const { return m_highT;}
|
||||
|
|
@ -67,9 +67,12 @@ namespace Cantera {
|
|||
|
||||
/**
|
||||
* Update the properties for this species. This method is called
|
||||
* with a pointer to an array containing the functions of temperature needed by this
|
||||
* parameterization, and three pointers to arrays where the computed property values
|
||||
* should be written. This method updates only one value in each array.
|
||||
* with a pointer to an array containing the functions of
|
||||
* temperature needed by this
|
||||
* parameterization, and three pointers to arrays where the
|
||||
* computed property values
|
||||
* should be written. This method updates only one value in
|
||||
* each array.
|
||||
*/
|
||||
void updateProperties(const doublereal* tt,
|
||||
doublereal* cp_R, doublereal* h_RT, doublereal* s_R) const {
|
||||
|
|
@ -94,6 +97,18 @@ namespace Cantera {
|
|||
s_R[m_index] = s;
|
||||
}
|
||||
|
||||
void reportParameters(int &n, doublereal &tlow, doublereal &thigh,
|
||||
doublereal &pref,
|
||||
doublereal* const coeffs) const {
|
||||
n = m_index;
|
||||
tlow = m_lowT;
|
||||
thigh = m_highT;
|
||||
pref = m_Pref;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
coeffs[i] = m_coeff[i];
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_lowT; // lowest valid temperature
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ namespace Cantera {
|
|||
* - c[8] - c[14] coefficients for high T range
|
||||
*/
|
||||
virtual void install(int index, int type, const doublereal* c,
|
||||
doublereal minTemp, doublereal maxTemp, doublereal refPressure) {
|
||||
doublereal minTemp, doublereal maxTemp,
|
||||
doublereal refPressure) {
|
||||
|
||||
int imid = int(c[0]); // midpoint temp converted to integer
|
||||
int igrp = m_index[imid]; // has this value been seen before?
|
||||
|
|
@ -77,6 +78,10 @@ namespace Cantera {
|
|||
m_index[imid] = igrp = static_cast<int>(m_high.size());
|
||||
m_ngroups++;
|
||||
}
|
||||
|
||||
m_group_map[index] = igrp;
|
||||
m_posInGroup_map[index] = (int) m_low[igrp-1].size();
|
||||
|
||||
doublereal tlow = minTemp;
|
||||
doublereal tmid = c[0];
|
||||
doublereal thigh = maxTemp;
|
||||
|
|
@ -92,13 +97,12 @@ namespace Cantera {
|
|||
pref, chigh.begin()));
|
||||
m_low[igrp-1].push_back(NasaPoly1(index, tlow, tmid,
|
||||
pref, clow));
|
||||
|
||||
if (tlow > m_tlow_max) m_tlow_max = tlow;
|
||||
if (thigh < m_thigh_min) m_thigh_min = thigh;
|
||||
m_tlow.push_back(tlow);
|
||||
m_thigh.push_back(thigh);
|
||||
m_p0 = pref;
|
||||
m_high_map[index] = &m_high[igrp-1].back();
|
||||
m_low_map[index] = &m_low[igrp-1].back();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,11 +118,17 @@ namespace Cantera {
|
|||
m_t[4] = 1.0/t;
|
||||
m_t[5] = log(t);
|
||||
|
||||
doublereal tmid = m_low_map[k]->maxTemp();
|
||||
if (t < tmid)
|
||||
m_low_map[k]->updateProperties(m_t.begin(), cp_R, h_RT, s_R);
|
||||
else
|
||||
m_high_map[k]->updateProperties(m_t.begin(), cp_R, h_RT, s_R);
|
||||
int grp = m_group_map[k];
|
||||
int pos = m_posInGroup_map[k];
|
||||
const NasaPoly1 *nlow = &(m_low[grp-1].at(pos));
|
||||
|
||||
doublereal tmid = nlow->maxTemp();
|
||||
if (t < tmid) {
|
||||
nlow->updateProperties(m_t.begin(), cp_R, h_RT, s_R);
|
||||
} else {
|
||||
const NasaPoly1 *nhigh = &(m_high[grp-1].at(pos));
|
||||
nhigh->updateProperties(m_t.begin(), cp_R, h_RT, s_R);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -173,10 +183,53 @@ namespace Cantera {
|
|||
|
||||
virtual doublereal refPressure() const {return m_p0;}
|
||||
|
||||
/**
|
||||
* This utility function reports the type of parameterization
|
||||
* used for the species, index.
|
||||
*/
|
||||
virtual int reportType(int index) const { return NASA; }
|
||||
|
||||
/**
|
||||
* This utility function reports back the type of
|
||||
* parameterization and all of the parameters for the
|
||||
* species, index.
|
||||
* For the NASA object, there are 15 coefficients.
|
||||
*/
|
||||
virtual void reportParams(int index, int &type,
|
||||
doublereal * const c,
|
||||
doublereal &minTemp,
|
||||
doublereal &maxTemp,
|
||||
doublereal &refPressure) {
|
||||
type = reportType(index);
|
||||
if (type == NASA) {
|
||||
int grp = m_group_map[index];
|
||||
int pos = m_posInGroup_map[index];
|
||||
const NasaPoly1 *lowPoly = &(m_low[grp-1].at(pos));
|
||||
const NasaPoly1 *highPoly = &(m_high[grp-1].at(pos));
|
||||
|
||||
doublereal tmid = lowPoly->maxTemp();
|
||||
c[0] = tmid;
|
||||
int n;
|
||||
double ttemp;
|
||||
lowPoly->reportParameters(n, minTemp, ttemp, refPressure,
|
||||
c + 1);
|
||||
if (n != index) {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
highPoly->reportParameters(n, ttemp, maxTemp, refPressure,
|
||||
c + 8);
|
||||
if (n != index) {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
} else {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
mutable map<int, NasaPoly1*> m_low_map;
|
||||
mutable map<int, NasaPoly1*> m_high_map;
|
||||
// mutable map<int, NasaPoly1*> m_low_map;
|
||||
// mutable map<int, NasaPoly1*> m_high_map;
|
||||
vector<vector<NasaPoly1> > m_high;
|
||||
vector<vector<NasaPoly1> > m_low;
|
||||
map<int, int> m_index;
|
||||
|
|
@ -189,6 +242,9 @@ namespace Cantera {
|
|||
int m_ngroups;
|
||||
mutable vector_fp m_t;
|
||||
|
||||
mutable map<int, int> m_group_map;
|
||||
mutable map<int, int> m_posInGroup_map;
|
||||
|
||||
private:
|
||||
|
||||
// see SpeciesThermoFactory.cpp for the definition
|
||||
|
|
@ -215,32 +271,3 @@ namespace Cantera {
|
|||
|
||||
#endif
|
||||
|
||||
// $Log$
|
||||
// Revision 1.6 2004-07-01 23:47:45 hkmoffa
|
||||
// static_cast to eliminate VC++ warnings.
|
||||
//
|
||||
// Revision 1.5 2004/04/24 12:53:00 dggoodwin
|
||||
// *** empty log message ***
|
||||
//
|
||||
// Revision 1.4 2004/04/23 19:03:22 dggoodwin
|
||||
// *** empty log message ***
|
||||
//
|
||||
// Revision 1.3 2004/04/22 21:44:36 dggoodwin
|
||||
// *** empty log message ***
|
||||
//
|
||||
// Revision 1.2 2003/11/01 04:50:35 dggoodwin
|
||||
// *** empty log message ***
|
||||
//
|
||||
// Revision 1.1.1.1 2003/04/14 17:57:51 dggoodwin
|
||||
// Initial import.
|
||||
//
|
||||
// Revision 1.16 2003/01/13 10:14:32 dgg
|
||||
// *** empty log message ***
|
||||
//
|
||||
//
|
||||
// Revision 1.3 2001/12/19 03:14:27 dgg
|
||||
// Added an offset to the high temperature cp constant coefficient so
|
||||
// that the high and low cp fits agree precisely at Tmid. This is
|
||||
// necessary to avoid spurious errors that can occur when integrators
|
||||
// begin at an initial temperature precisely equal to Tmid.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ namespace Cantera {
|
|||
virtual doublereal minTemp(int k=-1) const {return m_minTemp;}
|
||||
virtual doublereal maxTemp(int k=-1) const {return m_maxTemp;}
|
||||
virtual doublereal refPressure() const {return m_p0;}
|
||||
virtual int reportType(int index) const { return POLYNOMIAL_4;}
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace Cantera {
|
|||
copy(coeffs, coeffs + 7, m_coeff.begin());
|
||||
}
|
||||
|
||||
virtual ~ShomatePoly(){}
|
||||
~ShomatePoly(){}
|
||||
|
||||
doublereal minTemp() const { return m_lowT;}
|
||||
doublereal maxTemp() const { return m_highT;}
|
||||
|
|
@ -87,6 +87,18 @@ namespace Cantera {
|
|||
s_R[m_index] = 1.e3 * s * tt[5];
|
||||
}
|
||||
|
||||
|
||||
void reportParameters(int &n, doublereal &tlow, doublereal &thigh,
|
||||
doublereal &pref,
|
||||
doublereal* const coeffs) const {
|
||||
n = m_index;
|
||||
tlow = m_lowT;
|
||||
thigh = m_highT;
|
||||
pref = m_Pref;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
coeffs[i] = m_coeff[i];
|
||||
}
|
||||
}
|
||||
protected:
|
||||
|
||||
doublereal m_lowT, m_highT, m_Pref;
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ namespace Cantera {
|
|||
m_index[imid] = igrp = static_cast<int>(m_high.size());
|
||||
m_ngroups++;
|
||||
}
|
||||
m_group_map[index] = igrp;
|
||||
m_posInGroup_map[index] = (int) m_low[igrp-1].size();
|
||||
doublereal tlow = minTemp;
|
||||
doublereal tmid = c[0];
|
||||
doublereal thigh = maxTemp;
|
||||
|
|
@ -83,6 +85,33 @@ namespace Cantera {
|
|||
m_p0 = pref;
|
||||
}
|
||||
|
||||
/**
|
||||
* update the properties for only one species.
|
||||
*/
|
||||
virtual void update_one(int k, doublereal t, doublereal* cp_R,
|
||||
doublereal* h_RT, doublereal* s_R) const {
|
||||
|
||||
doublereal tt = 1.e-3*t;
|
||||
m_t[0] = tt;
|
||||
m_t[1] = tt*tt;
|
||||
m_t[2] = m_t[1]*tt;
|
||||
m_t[3] = 1.0/m_t[1];
|
||||
m_t[4] = log(tt);
|
||||
m_t[5] = 1.0/GasConstant;
|
||||
m_t[6] = 1.0/(GasConstant * t);
|
||||
|
||||
int grp = m_group_map[k];
|
||||
int pos = m_posInGroup_map[k];
|
||||
const ShomatePoly *nlow = &(m_low[grp-1].at(pos));
|
||||
|
||||
doublereal tmid = nlow->maxTemp();
|
||||
if (t < tmid) {
|
||||
nlow->updateProperties(m_t.begin(), cp_R, h_RT, s_R);
|
||||
} else {
|
||||
const ShomatePoly *nhigh = &(m_high[grp-1].at(pos));
|
||||
nhigh->updateProperties(m_t.begin(), cp_R, h_RT, s_R);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void update(doublereal t, doublereal* cp_R,
|
||||
doublereal* h_RT, doublereal* s_R) const {
|
||||
|
|
@ -129,8 +158,48 @@ namespace Cantera {
|
|||
|
||||
virtual doublereal refPressure() const {return m_p0;}
|
||||
|
||||
virtual int reportType(int index) const { return SHOMATE; }
|
||||
|
||||
/**
|
||||
* This utility function reports back the type of
|
||||
* parameterization and all of the parameters for the
|
||||
* species, index.
|
||||
* For the NASA object, there are 15 coefficients.
|
||||
*/
|
||||
virtual void reportParams(int index, int &type,
|
||||
doublereal * const c,
|
||||
doublereal &minTemp,
|
||||
doublereal &maxTemp,
|
||||
doublereal &refPressure) {
|
||||
type = reportType(index);
|
||||
if (type == NASA) {
|
||||
int grp = m_group_map[index];
|
||||
int pos = m_posInGroup_map[index];
|
||||
const ShomatePoly *lowPoly = &(m_low[grp-1].at(pos));
|
||||
const ShomatePoly *highPoly = &(m_high[grp-1].at(pos));
|
||||
doublereal tmid = lowPoly->maxTemp();
|
||||
c[0] = tmid;
|
||||
int n;
|
||||
double ttemp;
|
||||
lowPoly->reportParameters(n, minTemp, ttemp, refPressure,
|
||||
c + 1);
|
||||
if (n != index) {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
highPoly->reportParameters(n, ttemp, maxTemp, refPressure,
|
||||
c + 8);
|
||||
if (n != index) {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
} else {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//mutable map<int, ShomatePoly*> m_low_map;
|
||||
//mutable map<int, ShomatePoly*> m_high_map;
|
||||
vector<vector<ShomatePoly> > m_high;
|
||||
vector<vector<ShomatePoly> > m_low;
|
||||
map<int, int> m_index;
|
||||
|
|
@ -142,6 +211,9 @@ namespace Cantera {
|
|||
doublereal m_p0;
|
||||
int m_ngroups;
|
||||
mutable vector_fp m_t;
|
||||
|
||||
mutable map<int, int> m_group_map;
|
||||
mutable map<int, int> m_posInGroup_map;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef CT_SIMPLETHERMO_H
|
||||
|
|
@ -57,6 +57,15 @@ namespace Cantera {
|
|||
}
|
||||
}
|
||||
|
||||
virtual void update_one(int k, doublereal t, doublereal* cp_R,
|
||||
doublereal* h_RT, doublereal* s_R) const {
|
||||
doublereal logt = log(t);
|
||||
doublereal rt = 1.0/t;
|
||||
cp_R[k] = m_cp0_R[k];
|
||||
h_RT[k] = rt*(m_h0_R[k] + (t - m_t0[k]) * m_cp0_R[k]);
|
||||
s_R[k] = m_s0_R[k] + m_cp0_R[k] * (logt - m_logt0[k]);
|
||||
}
|
||||
|
||||
virtual doublereal minTemp(int k=-1) const {
|
||||
if (k < 0)
|
||||
return m_tlow_max;
|
||||
|
|
@ -73,6 +82,32 @@ namespace Cantera {
|
|||
|
||||
virtual doublereal refPressure() const {return m_p0;}
|
||||
|
||||
virtual int reportType(int index) const { return SIMPLE; }
|
||||
|
||||
/**
|
||||
* This utility function reports back the type of
|
||||
* parameterization and all of the parameters for the
|
||||
* species, index.
|
||||
* For the SimpleThermo object, there are 4 coefficients.
|
||||
*/
|
||||
virtual void reportParams(int index, int &type,
|
||||
doublereal * const c,
|
||||
doublereal &minTemp,
|
||||
doublereal &maxTemp,
|
||||
doublereal &refPressure) {
|
||||
type = reportType(index);
|
||||
if (type == SIMPLE) {
|
||||
c[0] = m_t0[index];
|
||||
c[1] = m_h0_R[index] * GasConstant;
|
||||
c[2] = m_s0_R[index] * GasConstant;
|
||||
c[3] = m_cp0_R[index] * GasConstant;
|
||||
minTemp = m_tlow[index];
|
||||
maxTemp = m_thigh[index];
|
||||
refPressure = m_p0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
map<int, int> m_index;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ namespace Cantera {
|
|||
virtual void update_one(int k, doublereal T,
|
||||
doublereal* cp_R,
|
||||
doublereal* h_RT,
|
||||
doublereal* s_R) const {}
|
||||
doublereal* s_R) const {
|
||||
update(T, cp_R, h_RT, s_R);
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum temperature. If no argument is supplied, this
|
||||
|
|
@ -109,13 +111,25 @@ namespace Cantera {
|
|||
* for the same standard-state pressure.
|
||||
*/
|
||||
virtual doublereal refPressure() const =0;
|
||||
|
||||
/**
|
||||
* This utility function reports the type of parameterization
|
||||
* used for the species, index.
|
||||
*/
|
||||
virtual int reportType(int index) const = 0;
|
||||
|
||||
/**
|
||||
* This utility function reports back the type of
|
||||
* parameterization and all of the parameters for the
|
||||
* species, index.
|
||||
*/
|
||||
virtual void reportParams(int index, int &type,
|
||||
doublereal * const c,
|
||||
doublereal &minTemp,
|
||||
doublereal &maxTemp,
|
||||
doublereal &refPressure)=0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
#include "ctexceptions.h"
|
||||
#include "stringUtils.h"
|
||||
#include "SpeciesThermo.h"
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
namespace Cantera {
|
||||
|
||||
|
|
@ -111,12 +113,15 @@ namespace Cantera {
|
|||
|
||||
virtual void install(int sp, int type, const doublereal* c,
|
||||
doublereal minTemp, doublereal maxTemp, doublereal refPressure) {
|
||||
if (type == m_thermo1.ID)
|
||||
if (type == m_thermo1.ID) {
|
||||
m_thermo1.install(sp, 0, c, minTemp, maxTemp, refPressure);
|
||||
else if (type == m_thermo2.ID)
|
||||
speciesToType[sp] = m_thermo1.ID;
|
||||
} else if (type == m_thermo2.ID) {
|
||||
m_thermo2.install(sp, 0, c, minTemp, maxTemp, refPressure);
|
||||
else
|
||||
speciesToType[sp] = m_thermo2.ID;
|
||||
} else {
|
||||
throw UnknownSpeciesThermo("SpeciesThermoDuo:install",type);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void update(doublereal t, doublereal* cp_R,
|
||||
|
|
@ -141,10 +146,37 @@ namespace Cantera {
|
|||
return m_thermo1.refPressure();
|
||||
}
|
||||
|
||||
virtual int reportType(int k) const {
|
||||
map<int, int>::const_iterator p = speciesToType.find(k);
|
||||
if (p != speciesToType.end()) {
|
||||
const int type = p->second;
|
||||
return type;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual void reportParams(int index, int &type,
|
||||
doublereal * const c,
|
||||
doublereal &minTemp,
|
||||
doublereal &maxTemp,
|
||||
doublereal &refPressure) {
|
||||
int ctype = reportType(index);
|
||||
if (ctype == m_thermo1.ID) {
|
||||
m_thermo1.reportParams(index, type, c, minTemp, maxTemp,
|
||||
refPressure);
|
||||
} else if (ctype == m_thermo1.ID) {
|
||||
m_thermo2.reportParams(index, type, c, minTemp, maxTemp,
|
||||
refPressure);
|
||||
} else {
|
||||
throw CanteraError(" ", "confused");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T1 m_thermo1;
|
||||
T2 m_thermo2;
|
||||
map<int, int> speciesToType;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -200,6 +232,13 @@ namespace Cantera {
|
|||
return m_pref;
|
||||
}
|
||||
|
||||
|
||||
virtual int reportType(int k) const {
|
||||
return m_thermo[k]->reportType(k);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
vector<T> m_thermo;
|
||||
doublereal m_pref;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,16 @@ namespace Cantera {
|
|||
}
|
||||
}
|
||||
|
||||
void StoichSubstance::setParameters(int n, double * c) {
|
||||
double rho = c[0];
|
||||
setDensity(rho);
|
||||
}
|
||||
|
||||
void StoichSubstance::getParameters(int &n, double * const c) {
|
||||
double rho = density();
|
||||
c[0] = rho;
|
||||
}
|
||||
|
||||
void StoichSubstance::setParametersFromXML(const XML_Node& eosdata) {
|
||||
eosdata.require("model","StoichSubstance");
|
||||
doublereal rho = getFloat(eosdata, "density", "-");
|
||||
|
|
|
|||
|
|
@ -189,7 +189,10 @@ namespace Cantera {
|
|||
|
||||
virtual void initThermo();
|
||||
|
||||
virtual void setParametersFromXML(const XML_Node& eosdata);
|
||||
virtual void setParameters(int n, double *c);
|
||||
virtual void getParameters(int &n, double * const c);
|
||||
|
||||
virtual void setParametersFromXML(const XML_Node& eosdata);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
|||
|
|
@ -519,6 +519,7 @@ namespace Cantera {
|
|||
* @param c array of \i n coefficients
|
||||
*/
|
||||
virtual void setParameters(int n, doublereal* c) {}
|
||||
virtual void getParameters(int &n, doublereal * const c) {}
|
||||
virtual void setParametersFromXML(const XML_Node& eosdata) {}
|
||||
virtual void setStateFromXML(const XML_Node& state);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue