added some consts, and a routine to read a multiphase mixture from an input file, but this is not yet active

This commit is contained in:
Dave Goodwin 2006-07-11 15:33:30 +00:00
parent 7da64f4af7
commit d7cf9cc53a
2 changed files with 79 additions and 35 deletions

View file

@ -13,6 +13,14 @@ namespace Cantera {
m_Tmin(1.0), m_Tmax(100000.0) {
}
void MultiPhase::
addPhases(MultiPhase& mix) {
index_t n;
for (n = 0; n < mix.m_np; n++) {
addPhase(mix.m_phase[n], mix.m_moles[n]);
}
}
void MultiPhase::
addPhases(phase_list& phases, const vector_fp& phaseMoles) {
index_t np = phases.size();
@ -162,14 +170,14 @@ namespace Cantera {
}
/// Moles of species \c k.
doublereal MultiPhase::speciesMoles(index_t k) {
doublereal MultiPhase::speciesMoles(index_t k) const {
index_t ip = m_spphase[k];
return m_moles[ip]*m_moleFractions[k];
}
/// Total moles of element m, summed over all
/// phases
doublereal MultiPhase::elementMoles(index_t m) {
doublereal MultiPhase::elementMoles(index_t m) const {
doublereal sum = 0.0, phasesum;
index_t i, k = 0, ik, nsp;
for (i = 0; i < m_np; i++) {
@ -185,7 +193,7 @@ namespace Cantera {
}
/// Total charge, summed over all phases
doublereal MultiPhase::charge() {
doublereal MultiPhase::charge() const {
doublereal sum = 0.0;
index_t i;
for (i = 0; i < m_np; i++) {
@ -198,7 +206,7 @@ namespace Cantera {
/// \f[ Q_p = N_p \sum_k F z_k X_k \f]
/// where the sum runs only over species in phase \a p.
/// @param p index of the phase for which the charge is desired.
doublereal MultiPhase::phaseCharge(index_t p) {
doublereal MultiPhase::phaseCharge(index_t p) const {
doublereal phasesum = 0.0;
int ik, k, nsp = m_phase[p]->nSpecies();
for (ik = 0; ik < nsp; ik++) {
@ -210,7 +218,7 @@ namespace Cantera {
/// Get the chemical potentials of all species in all phases.
void MultiPhase::getChemPotentials(doublereal* mu) {
void MultiPhase::getChemPotentials(doublereal* mu) const {
index_t i, loc = 0;
updatePhases();
for (i = 0; i < m_np; i++) {
@ -247,7 +255,7 @@ namespace Cantera {
/// potentials.
///
void MultiPhase::getValidChemPotentials(doublereal not_mu,
doublereal* mu, bool standard) {
doublereal* mu, bool standard) const {
index_t i, loc = 0;
updatePhases();
@ -266,7 +274,7 @@ namespace Cantera {
}
/// True if species \a k belongs to a solution phase.
bool MultiPhase::solutionSpecies(index_t k) {
bool MultiPhase::solutionSpecies(index_t k) const {
if (m_phase[m_spphase[k]]->nSpecies() > 1)
return true;
else
@ -387,7 +395,7 @@ namespace Cantera {
}
/// The total mixture volume [m^3].
doublereal MultiPhase::volume() {
doublereal MultiPhase::volume() const {
int i;
doublereal sum = 0;
for (i = 0; i < int(m_np); i++) {
@ -416,6 +424,9 @@ namespace Cantera {
if (XY == TP) {
addLogEntry("problem type","fixed T,P");
addLogEntry("Temperature",temperature());
addLogEntry("Pressure", pressure());
// create an equilibrium manager
e = new MultiPhaseEquil(this);
@ -714,7 +725,31 @@ done:
return err;
}
#ifdef MULTIPHASE_DEVEL
void importFromXML(string infile, string id) {
XML_Node* root = get_XML_File(infile);
if (id == "-") id = "";
XML_Node* x = get_XML_Node(string("#")+id, root);
if (x.name() != "multiphase")
throw CanteraError("MultiPhase::importFromXML",
"Current XML_Node is not a multiphase element.");
vector<XML_Node*> phases;
x.getChildren("phase",phases);
int np = phases.size();
int n;
ThermoPhase* p;
for (n = 0; n < np; n++) {
XML_Node& ph = *phases[n];
srcfile = infile;
if (ph.hasAttrib("src")) srcfile = ph["src"];
idstr = ph["id"];
p = newPhase(srcfile, idstr);
if (p) {
addPhase(p, ph.value());
}
}
}
#endif
//-------------------------------------------------------------
//

View file

@ -42,27 +42,31 @@ namespace Cantera {
/// phase objects.
virtual ~MultiPhase() {}
void addPhases(phase_list& phases, const vector_fp& phaseMoles);
/// Add all phases present in 'mix' to this mixture.
void addPhases(MultiPhase& mix);
/// Add a phase to the mixture.
/// @param p pointer to the phase object
/// @param moles total number of moles of all species in this phase
void addPhase(phase_t* p, doublereal moles);
/// Number of elements.
int nElements() { return int(m_nel); }
int nElements() const { return int(m_nel); }
/// Name of element \a m.
string elementName(int m) { return m_enames[m]; }
string elementName(int m) const { return m_enames[m]; }
/// Index of element with name \a name.
int elementIndex(string name) { return m_enamemap[name] - 1;}
int elementIndex(string name) const { return m_enamemap[name] - 1;}
/// Number of species, summed over all phases.
int nSpecies() { return int(m_nsp); }
int nSpecies() const { return int(m_nsp); }
/// Name of species with index \a k.
string speciesName(int k) { return m_snames[k]; }
string speciesName(int k) const { return m_snames[k]; }
/// Number of atoms of element \a m in species \a k.
doublereal nAtoms(int k, int m) {
@ -73,7 +77,7 @@ namespace Cantera {
/// Species mole fractions. Write the array of species mole
/// fractions into array \c x. The mole fractions are
/// normalized to sum to one in each phase.
void getMoleFractions(doublereal* x) {
void getMoleFractions(doublereal* x) const {
copy(m_moleFractions.begin(), m_moleFractions.end(), x);
}
@ -82,7 +86,7 @@ namespace Cantera {
void init();
/// Moles of phase n.
doublereal phaseMoles(index_t n) {
doublereal phaseMoles(index_t n) const {
return m_moles[n];
}
@ -97,11 +101,11 @@ namespace Cantera {
phase_t& phase(index_t n);
/// Moles of species \c k.
doublereal speciesMoles(index_t k);
doublereal speciesMoles(index_t k) const;
/// Index of the species belonging to phase number \c p
/// with index \c k within the phase.
int speciesIndex(index_t k, index_t p) {
int speciesIndex(index_t k, index_t p) const {
return m_spstart[p] + k;
}
@ -109,28 +113,28 @@ namespace Cantera {
/// valid thermo data. Stoichiometric phases are not
/// considered, since they may have thermo data only valid for
/// conditions for which they are stable.
doublereal minTemp() { return m_Tmin; }
doublereal minTemp() const { return m_Tmin; }
/// Maximum temperature for which all solution phases have
/// valid thermo data. Stoichiometric phases are not
/// considered, since they may have thermo data only valid for
/// conditions for which they are stable.
doublereal maxTemp() { return m_Tmax; }
doublereal maxTemp() const { return m_Tmax; }
/// Total charge (Coulombs).
doublereal charge();
doublereal charge() const;
/// Charge (Coulombs) of phase with index \a p.
doublereal phaseCharge(index_t p);
doublereal phaseCharge(index_t p) const;
/// Total moles of element \a m, summed over all phases.
doublereal elementMoles(index_t m);
doublereal elementMoles(index_t m) const;
/// Chemical potentials. Write into array \a mu the chemical
/// potentials of all species [J/kmol]. The chemical
/// potentials are related to the activities by
/// \f[ \mu_k = \mu_k^0(T, P) + RT \ln a_k. \f].
void getChemPotentials(doublereal* mu);
void getChemPotentials(doublereal* mu) const;
/// Valid chemical potentials. Write into array \a mu the
/// chemical potentials of all species with thermo data valid
@ -139,10 +143,10 @@ namespace Cantera {
/// standard is set to true, then the values returned are
/// standard chemical potentials.
void getValidChemPotentials(doublereal not_mu, doublereal* mu,
bool standard = false);
bool standard = false) const;
/// Temperature [K].
doublereal temperature() { return m_temp; }
doublereal temperature() const { return m_temp; }
/// Set the mixture to a state of chemical equilibrium.
/// @param XY Integer flag specifying properties to hold fixed.
@ -166,12 +170,12 @@ namespace Cantera {
}
/// Pressure [Pa].
doublereal pressure() {
doublereal pressure() const {
return m_press;
}
/// Volume [m^3].
doublereal volume();
doublereal volume() const;
/// Set the pressure [Pa].
void setPressure(doublereal P) {
@ -192,19 +196,19 @@ namespace Cantera {
doublereal cp() const;
/// Number of phases.
index_t nPhases() {
index_t nPhases() const {
return m_np;
}
/// Return true is species \a k is a species in a
/// multicomponent solution phase.
bool solutionSpecies(index_t k);
bool solutionSpecies(index_t k) const;
index_t speciesPhaseIndex(index_t k) {
index_t speciesPhaseIndex(index_t k) const{
return m_spphase[k];
}
doublereal moleFraction(index_t k) {
doublereal moleFraction(index_t k) const{
return m_moleFractions[k];
}
@ -218,7 +222,7 @@ namespace Cantera {
/// Return true if the phase \a p has valid thermo data for
/// the current temperature.
bool tempOK(index_t p) {
bool tempOK(index_t p) const {
return m_temp_OK[p];
}
@ -244,7 +248,7 @@ namespace Cantera {
vector<string> m_enames;
vector_int m_atomicNumber;
vector<string> m_snames;
map<string, int> m_enamemap;
mutable map<string, int> m_enamemap;
index_t m_np;
doublereal m_temp;
doublereal m_press;
@ -259,7 +263,12 @@ namespace Cantera {
inline std::ostream& operator<<(std::ostream& s, Cantera::MultiPhase& x) {
size_t ip;
for (ip = 0; ip < x.nPhases(); ip++) {
s << "*************** Phase " << ip << " *****************" << endl;
if (x.phase(ip).name() != "") {
s << "*************** " << x.phase(ip).name() << " *****************" << endl;
}
else {
s << "*************** Phase " << ip << " *****************" << endl;
}
s << "Moles: " << x.phaseMoles(ip) << endl;
s << report(x.phase(ip)) << endl;