[Thermo] Slightly simplify adding species

Eliminate the freezeSpecies and init methods of class Phase, instead adjusting
array sizes as new species are added.
This commit is contained in:
Ray Speth 2013-10-04 16:22:35 +00:00
parent 5720d7cf90
commit 5fff5ce99f
4 changed files with 21 additions and 68 deletions

View file

@ -682,15 +682,6 @@ public:
doublereal size = 1.0);
//!@} end group adding species and elements
//! Call when finished adding species.
//! Prepare to use them for calculation of mixture properties.
virtual void freezeSpecies();
//! True if freezeSpecies has been called.
bool speciesFrozen() {
return m_speciesFrozen;
}
virtual bool ready() const;
//! Return the State Mole Fraction Number
@ -699,12 +690,6 @@ public:
}
protected:
//! @internal Initialize.
//! Make a local copy of the vector of molecular weights, and resize the
//! composition arrays to the appropriate size.
//! @param mw Vector of molecular weights of the species.
void init(const vector_fp& mw);
//! Set the molecular weight of a single species to a given value
//! @param k id of the species
//! @param mw Molecular Weight (kg kmol-1)
@ -765,11 +750,6 @@ private:
//! this int is incremented.
int m_stateNum;
//! Boolean indicating whether the number of species has been frozen.
//! During the construction of the phase, this is false. After construction
//! of the the phase, this is true.
bool m_speciesFrozen;
//! If this is true, then no elements may be added to the object.
bool m_elementsFrozen;

View file

@ -99,7 +99,6 @@ FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
c[2] = 0.0;
c[3] = 0.0;
m_spthermo->install(pname, 0, SIMPLE, c, 0.0, 1.0E30, OneAtm);
freezeSpecies();
initThermo();
m_p0 = OneAtm;
m_tlast = 298.15;

View file

@ -25,7 +25,6 @@ Phase::Phase() :
m_dens(0.001),
m_mmw(0.0),
m_stateNum(-1),
m_speciesFrozen(false),
m_elementsFrozen(false),
m_mm(0),
m_elem_type(0)
@ -42,7 +41,6 @@ Phase::Phase(const Phase& right) :
m_dens(0.001),
m_mmw(0.0),
m_stateNum(-1),
m_speciesFrozen(false) ,
m_elementsFrozen(false),
m_mm(0),
m_elem_type(0)
@ -70,7 +68,6 @@ Phase& Phase::operator=(const Phase& right)
m_rmolwts = right.m_rmolwts;
m_stateNum = -1;
m_speciesFrozen = right.m_speciesFrozen;
m_speciesNames = right.m_speciesNames;
m_speciesComp = right.m_speciesComp;
m_speciesCharge = right.m_speciesCharge;
@ -877,8 +874,26 @@ void Phase::addSpecies(const std::string& name_, const doublereal* comp,
m_speciesComp.push_back(compNew[m]);
wt += compNew[m] * aw[m];
}
// Some surface phases may define species representing empty sites
// that have zero molecular weight. Give them a very small molecular
// weight to avoid dividing by zero.
wt = std::max(wt, Tiny);
m_molwts.push_back(wt);
m_rmolwts.push_back(1.0/wt);
m_kk++;
// Ensure that the Phase has a valid mass fraction vector that sums to
// one. We will assume that species 0 has a mass fraction of 1.0 and mass
// fraction of all other species is 0.0.
if (m_kk == 1) {
m_y.push_back(1.0);
m_ym.push_back(m_rmolwts[0]);
m_mmw = 1.0 / m_ym[0];
} else {
m_y.push_back(0.0);
m_ym.push_back(0.0);
}
}
void Phase::addUniqueSpecies(const std::string& name_, const doublereal* comp,
@ -910,48 +925,9 @@ void Phase::addUniqueSpecies(const std::string& name_, const doublereal* comp,
addSpecies(name_, comp, charge_, size_);
}
void Phase::freezeSpecies()
{
m_speciesFrozen = true;
init(molecularWeights());
}
void Phase::init(const vector_fp& mw)
{
m_kk = mw.size();
m_rmolwts.resize(m_kk);
m_y.resize(m_kk, 0.0);
m_ym.resize(m_kk, 0.0);
copy(mw.begin(), mw.end(), m_molwts.begin());
for (size_t k = 0; k < m_kk; k++) {
if (m_molwts[k] < 0.0) {
throw CanteraError("Phase::init",
"negative molecular weight for species number "
+ int2str(k));
}
// Some surface phases may define species representing empty sites
// that have zero molecular weight. Give them a very small molecular
// weight to avoid dividing by zero.
if (m_molwts[k] < Tiny) {
m_molwts[k] = Tiny;
}
m_rmolwts[k] = 1.0/m_molwts[k];
}
// Now that we have resized the State object, let's fill it with a valid
// mass fraction vector that sums to one. The Phase object should never
// have a mass fraction vector that doesn't sum to one. We will assume that
// species 0 has a mass fraction of 1.0 and mass fraction of all other
// species is 0.0.
m_y[0] = 1.0;
m_ym[0] = m_y[0] * m_rmolwts[0];
m_mmw = 1.0 / m_ym[0];
}
bool Phase::ready() const
{
return (m_kk > 0 && m_elementsFrozen && m_speciesFrozen);
return (m_kk > 0 && m_elementsFrozen);
}
} // namespace Cantera

View file

@ -602,10 +602,8 @@ bool importPhase(XML_Node& phase, ThermoPhase* th,
th->installSlavePhases(&phase);
}
// done adding species.
th->freezeSpecies();
// Perform any required subclass-specific initialization.
// Done adding species. Perform any required subclass-specific
// initialization.
th->initThermo();
// Perform any required subclass-specific initialization