[Thermo] Make m_species a non-pointer member of ThermoPhase

This commit is contained in:
Ray Speth 2017-02-12 22:19:50 -05:00
parent dd521de254
commit 35679c2e9e
14 changed files with 40 additions and 49 deletions

View file

@ -114,7 +114,7 @@ public:
* that calls the species thermo refPressure function.
*/
virtual doublereal refPressure() const {
return m_spthermo->refPressure();
return m_spthermo.refPressure();
}
//! Minimum temperature for which the thermodynamic data for the species
@ -129,7 +129,7 @@ public:
* of the min value over all species.
*/
virtual doublereal minTemp(size_t k = npos) const {
return m_spthermo->minTemp(k);
return m_spthermo.minTemp(k);
}
//! Report the 298 K Heat of Formation of the standard state of one species
@ -144,7 +144,7 @@ public:
* and 1 bar
*/
doublereal Hf298SS(const size_t k) const {
return m_spthermo->reportOneHf298(k);
return m_spthermo.reportOneHf298(k);
}
//! Modify the value of the 298 K Heat of Formation of one species in the
@ -159,7 +159,7 @@ public:
* 298K and 1 bar
*/
virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New) {
m_spthermo->modifyOneHf298(k, Hf298New);
m_spthermo.modifyOneHf298(k, Hf298New);
invalidateCache();
}
@ -182,7 +182,7 @@ public:
* of the max value over all species.
*/
virtual doublereal maxTemp(size_t k = npos) const {
return m_spthermo->maxTemp(k);
return m_spthermo.maxTemp(k);
}
//! Returns the chargeNeutralityNecessity boolean
@ -1604,7 +1604,7 @@ protected:
* This class is called when the reference-state thermodynamic properties
* of all the species in the phase needs to be evaluated.
*/
MultiSpeciesThermo* m_spthermo;
MultiSpeciesThermo m_spthermo;
//! Vector of pointers to the species databases.
/*!

View file

@ -16,7 +16,7 @@ namespace Cantera
doublereal ConstDensityThermo::enthalpy_mole() const
{
doublereal p0 = m_spthermo->refPressure();
doublereal p0 = refPressure();
return RT() * mean_X(enthalpy_RT()) + (pressure() - p0)/molarDensity();
}
@ -64,7 +64,7 @@ doublereal ConstDensityThermo::standardConcentration(size_t k) const
void ConstDensityThermo::getChemPotentials(doublereal* mu) const
{
doublereal vdp = (pressure() - m_spthermo->refPressure())/
doublereal vdp = (pressure() - refPressure())/
molarDensity();
const vector_fp& g_RT = gibbs_RT();
for (size_t k = 0; k < m_kk; k++) {
@ -95,8 +95,8 @@ void ConstDensityThermo::_updateThermo() const
{
doublereal tnow = temperature();
if (m_tlast != tnow) {
m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0],
&m_s0_R[0]);
m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0],
&m_s0_R[0]);
m_tlast = tnow;
for (size_t k = 0; k < m_kk; k++) {
m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];

View file

@ -38,7 +38,7 @@ IdealGasPhase::IdealGasPhase(XML_Node& phaseRef, const std::string& id_) :
doublereal IdealGasPhase::entropy_mole() const
{
return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / m_spthermo->refPressure()));
return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / refPressure()));
}
doublereal IdealGasPhase::cp_mole() const
@ -67,7 +67,7 @@ void IdealGasPhase::getStandardChemPotentials(doublereal* muStar) const
{
const vector_fp& gibbsrt = gibbs_RT_ref();
scale(gibbsrt.begin(), gibbsrt.end(), muStar, RT());
double tmp = log(pressure() / m_spthermo->refPressure()) * RT();
double tmp = log(pressure() / refPressure()) * RT();
for (size_t k = 0; k < m_kk; k++) {
muStar[k] += tmp; // add RT*ln(P/P_0)
}
@ -94,7 +94,7 @@ void IdealGasPhase::getPartialMolarEntropies(doublereal* sbar) const
{
const vector_fp& _s = entropy_R_ref();
scale(_s.begin(), _s.end(), sbar, GasConstant);
doublereal logp = log(pressure() / m_spthermo->refPressure());
doublereal logp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
doublereal xx = std::max(SmallNumber, moleFraction(k));
sbar[k] += GasConstant * (-logp - log(xx));
@ -135,7 +135,7 @@ void IdealGasPhase::getEntropy_R(doublereal* sr) const
{
const vector_fp& _s = entropy_R_ref();
copy(_s.begin(), _s.end(), sr);
double tmp = log(pressure() / m_spthermo->refPressure());
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
sr[k] -= tmp;
}
@ -145,7 +145,7 @@ void IdealGasPhase::getGibbs_RT(doublereal* grt) const
{
const vector_fp& gibbsrt = gibbs_RT_ref();
copy(gibbsrt.begin(), gibbsrt.end(), grt);
double tmp = log(pressure() / m_spthermo->refPressure());
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
grt[k] += tmp;
}
@ -155,7 +155,7 @@ void IdealGasPhase::getPureGibbs(doublereal* gpure) const
{
const vector_fp& gibbsrt = gibbs_RT_ref();
scale(gibbsrt.begin(), gibbsrt.end(), gpure, RT());
double tmp = log(pressure() / m_spthermo->refPressure()) * RT();
double tmp = log(pressure() / refPressure()) * RT();
for (size_t k = 0; k < m_kk; k++) {
gpure[k] += tmp;
}
@ -284,7 +284,7 @@ void IdealGasPhase::_updateThermo() const
// If the temperature has changed since the last time these
// properties were computed, recompute them.
if (cached.state1 != tnow) {
m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
cached.state1 = tnow;
// update the species Gibbs functions

View file

@ -456,7 +456,7 @@ void IdealSolidSolnPhase::_updateThermo() const
if (m_tlast != tnow) {
// Update the thermodynamic functions of the reference state.
m_spthermo->update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data());
m_spthermo.update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data());
m_tlast = tnow;
doublereal rrt = 1.0 / RT();
for (size_t k = 0; k < m_kk; k++) {

View file

@ -286,7 +286,7 @@ void LatticePhase::_updateThermo() const
{
doublereal tnow = temperature();
if (m_tlast != tnow) {
m_spthermo->update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
m_spthermo.update(tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
m_tlast = tnow;
for (size_t k = 0; k < m_kk; k++) {
m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];

View file

@ -245,7 +245,7 @@ void MaskellSolidSolnPhase::_updateThermo() const
// Update the thermodynamic functions of the reference state.
doublereal tnow = temperature();
if (!cached.validate(tnow)) {
m_spthermo->update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data());
m_spthermo.update(tnow, m_cp0_R.data(), m_h0_RT.data(), m_s0_R.data());
for (size_t k = 0; k < m_kk; k++) {
m_g0_RT[k] = m_h0_RT[k] - m_s0_R[k];
}

View file

@ -60,7 +60,7 @@ void MixtureFugacityTP::getStandardChemPotentials(doublereal* g) const
{
_updateReferenceStateThermo();
copy(m_g0_RT.begin(), m_g0_RT.end(), g);
double tmp = log(pressure() /m_spthermo->refPressure());
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
g[k] = RT() * (g[k] + tmp);
}
@ -75,7 +75,7 @@ void MixtureFugacityTP::getEntropy_R(doublereal* sr) const
{
_updateReferenceStateThermo();
copy(m_s0_R.begin(), m_s0_R.end(), sr);
double tmp = log(pressure() /m_spthermo->refPressure());
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
sr[k] -= tmp;
}
@ -85,7 +85,7 @@ void MixtureFugacityTP::getGibbs_RT(doublereal* grt) const
{
_updateReferenceStateThermo();
copy(m_g0_RT.begin(), m_g0_RT.end(), grt);
double tmp = log(pressure() /m_spthermo->refPressure());
double tmp = log(pressure() / refPressure());
for (size_t k = 0; k < m_kk; k++) {
grt[k] += tmp;
}
@ -95,7 +95,7 @@ void MixtureFugacityTP::getPureGibbs(doublereal* g) const
{
_updateReferenceStateThermo();
scale(m_g0_RT.begin(), m_g0_RT.end(), g, RT());
double tmp = log(pressure() /m_spthermo->refPressure()) * RT();
double tmp = log(pressure() / refPressure()) * RT();
for (size_t k = 0; k < m_kk; k++) {
g[k] += tmp;
}
@ -796,7 +796,7 @@ void MixtureFugacityTP::_updateReferenceStateThermo() const
// If the temperature has changed since the last time these
// properties were computed, recompute them.
if (m_Tlast_ref != Tnow) {
m_spthermo->update(Tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
m_spthermo.update(Tnow, &m_cp0_R[0], &m_h0_RT[0], &m_s0_R[0]);
m_Tlast_ref = Tnow;
// update the species Gibbs functions

View file

@ -55,7 +55,7 @@ void PureFluidPhase::initThermo()
p = 0.001 * p;
m_sub->Set(tpx::PropertyPair::TP, T0, p);
m_spthermo->update_single(0, T0, &cp0_R, &h0_RT, &s0_R);
m_spthermo.update_single(0, T0, &cp0_R, &h0_RT, &s0_R);
double s_R = s0_R - log(p/refPressure());
m_sub->setStdState(h0_RT*GasConstant*298.15/m_mw,
s_R*GasConstant/m_mw, T0, p);
@ -221,7 +221,7 @@ void PureFluidPhase::getGibbs_RT_ref(doublereal* grt) const
{
double psave = pressure();
double t = temperature();
double pref = m_spthermo->refPressure();
double pref = refPressure();
double plow = 1.0E-8;
Set(tpx::PropertyPair::TP, t, plow);
getGibbs_RT(grt);
@ -239,7 +239,7 @@ void PureFluidPhase::getEntropy_R_ref(doublereal* er) const
{
double psave = pressure();
double t = temperature();
double pref = m_spthermo->refPressure();
double pref = refPressure();
double plow = 1.0E-8;
Set(tpx::PropertyPair::TP, t, plow);
getEntropy_R(er);

View file

@ -128,7 +128,7 @@ doublereal RedlichKwongMFTP::entropy_mole() const
{
_updateReferenceStateThermo();
doublereal sr_ideal = GasConstant * (mean_X(m_s0_R)
- sum_xlogx() - std::log(pressure()/m_spthermo->refPressure()));
- sum_xlogx() - std::log(pressure()/refPressure()));
doublereal sr_nonideal = sresid();
return sr_ideal + sr_nonideal;
}

View file

@ -262,7 +262,7 @@ void SingleSpeciesTP::_updateThermo() const
{
doublereal tnow = temperature();
if (m_tlast != tnow) {
m_spthermo->update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R);
m_spthermo.update(tnow, &m_cp0_R, &m_h0_RT, &m_s0_R);
m_tlast = tnow;
}
}

View file

@ -292,7 +292,7 @@ void SurfPhase::_updateThermo(bool force) const
{
doublereal tnow = temperature();
if (m_tlast != tnow || force) {
m_spthermo->update(tnow, m_cp0.data(), m_h0.data(), m_s0.data());
m_spthermo.update(tnow, m_cp0.data(), m_h0.data(), m_s0.data());
m_tlast = tnow;
for (size_t k = 0; k < m_kk; k++) {
m_h0[k] *= GasConstant * tnow;

View file

@ -25,7 +25,7 @@ namespace Cantera
{
ThermoPhase::ThermoPhase() :
m_spthermo(new MultiSpeciesThermo()), m_speciesData(0),
m_speciesData(0),
m_phi(0.0),
m_hasElementPotentials(false),
m_chargeNeutralityNecessary(false),
@ -39,15 +39,14 @@ ThermoPhase::~ThermoPhase()
for (size_t k = 0; k < m_speciesData.size(); k++) {
delete m_speciesData[k];
}
delete m_spthermo;
}
void ThermoPhase::resetHf298(size_t k) {
if (k != npos) {
m_spthermo->resetHf298(k);
m_spthermo.resetHf298(k);
} else {
for (size_t k = 0; k < nSpecies(); k++) {
m_spthermo->resetHf298(k);
m_spthermo.resetHf298(k);
}
}
invalidateCache();
@ -577,11 +576,7 @@ void ThermoPhase::setState_SPorSV(double Starget, double p,
MultiSpeciesThermo& ThermoPhase::speciesThermo(int k)
{
if (!m_spthermo) {
throw CanteraError("ThermoPhase::speciesThermo()",
"species reference state thermo manager was not set");
}
return *m_spthermo;
return m_spthermo;
}
void ThermoPhase::initThermoFile(const std::string& inputFile,
@ -607,7 +602,7 @@ void ThermoPhase::initThermoXML(XML_Node& phaseNode, const std::string& id)
void ThermoPhase::initThermo()
{
// Check to see that all of the species thermo objects have been initialized
if (!m_spthermo->ready(m_kk)) {
if (!m_spthermo.ready(m_kk)) {
throw CanteraError("ThermoPhase::initThermo()",
"Missing species thermo data");
}
@ -622,7 +617,7 @@ bool ThermoPhase::addSpecies(shared_ptr<Species> spec)
bool added = Phase::addSpecies(spec);
if (added) {
spec->thermo->validate(spec->name);
m_spthermo->install_STIT(m_kk-1, spec->thermo);
m_spthermo.install_STIT(m_kk-1, spec->thermo);
}
return added;
}
@ -640,7 +635,7 @@ void ThermoPhase::modifySpecies(size_t k, shared_ptr<Species> spec)
spec->name, speciesName(k), k);
}
spec->thermo->validate(spec->name);
m_spthermo->modifySpecies(k, spec->thermo);
m_spthermo.modifySpecies(k, spec->thermo);
}
void ThermoPhase::saveSpeciesData(const size_t k, const XML_Node* const data)

View file

@ -292,12 +292,12 @@ void VPStandardStateTP::createInstallPDSS(size_t k, const XML_Node& s,
if (use_STITbyPDSS) {
auto stit = make_shared<STITbyPDSS>(kPDSS);
m_spthermo->install_STIT(k, stit);
m_spthermo.install_STIT(k, stit);
} else {
shared_ptr<SpeciesThermoInterpType> stit(
newSpeciesThermoInterpType(s.child("thermo")));
stit->validate(s["name"]);
m_spthermo->install_STIT(k, stit);
m_spthermo.install_STIT(k, stit);
}
m_PDSS_storage[k].reset(kPDSS);

View file

@ -102,10 +102,6 @@ void WaterSSTP::initThermo()
m_waterProps.reset(new WaterProps(&m_sub));
// We have to do something with the thermo function here.
delete m_spthermo;
m_spthermo = 0;
// Set the flag to say we are ready to calculate stuff
m_ready = true;
}