19 MultiPhase::MultiPhase() :
81 for (n = 0; n < mix.
m_np; n++) {
89 size_t np = phases.size();
91 for (n = 0; n < np; n++) {
102 "phases cannot be added after init() has been called.");
124 for (m = 0; m < nel; m++) {
137 if (ename ==
"E" || ename ==
"e") {
178 size_t ip, kp, k = 0, nsp, m;
190 for (m = 0; m <
m_nel; m++) {
194 for (ip = 0; ip <
m_np; ip++) {
198 for (kp = 0; kp < nsp; kp++) {
199 if (mlocal !=
npos) {
216 for (k = 0; k <
m_nsp; k++) {
218 for (m = 0; m <
m_nel; m++) {
269 doublereal sum = 0.0, phasesum;
270 size_t i, k = 0, ik, nsp;
271 for (i = 0; i <
m_np; i++) {
274 for (ik = 0; ik < nsp; ik++) {
285 doublereal sum = 0.0;
287 for (i = 0; i <
m_np; i++) {
300 throw CanteraError(
"MultiPhase::speciesIndex",
"phase not found: " + phaseName);
302 size_t k =
m_phase[p]->speciesIndex(speciesName);
304 throw CanteraError(
"MultiPhase::speciesIndex",
"species not found: " + speciesName);
311 doublereal phasesum = 0.0;
312 size_t ik, k, nsp =
m_phase[p]->nSpecies();
313 for (ik = 0; ik < nsp; ik++) {
317 return Faraday*phasesum*
m_moles[p];
324 for (i = 0; i <
m_np; i++) {
325 m_phase[i]->getChemPotentials(mu + loc);
331 doublereal* mu,
bool standard)
const
337 for (i = 0; i <
m_np; i++) {
340 m_phase[i]->getChemPotentials(mu + loc);
342 m_phase[i]->getStandardChemPotentials(mu + loc);
363 doublereal sum = 0.0;
365 for (i = 0; i <
m_np; i++) {
376 doublereal sum = 0.0;
378 for (i = 0; i <
m_np; i++) {
389 doublereal sum = 0.0;
391 for (i = 0; i <
m_np; i++) {
402 doublereal sum = 0.0;
404 for (i = 0; i <
m_np; i++) {
415 doublereal sum = 0.0;
417 for (i = 0; i <
m_np; i++) {
433 for (
size_t k = 0; k < p->
nSpecies(); k++) {
443 for (
size_t k = 0; k < kk; k++) {
466 doublereal* dtmp = molNum;
467 for (
size_t ip = 0; ip <
m_np; ip++) {
468 doublereal phasemoles =
m_moles[ip];
471 for (ik = 0; ik < nsp; ik++) {
472 *(dtmp++) *= phasemoles;
483 size_t ik, k = 0, nsp;
484 doublereal phasemoles;
485 for (ip = 0; ip <
m_np; ip++) {
489 for (ik = 0; ik < nsp; ik++) {
495 if (phasemoles > 0.0) {
512 tmpMoles[indexS] += addedMoles;
513 if (tmpMoles[indexS] < 0.0) {
514 tmpMoles[indexS] = 0.0;
541 for (eGlobal = 0; eGlobal <
m_nel; eGlobal++) {
552 for (eGlobal = 0; eGlobal <
m_nel; eGlobal++) {
555 for (
size_t ip = 0; ip <
m_np; ip++) {
558 doublereal phasemoles =
m_moles[ip];
559 for (ik = 0; ik < nspPhase; ik++) {
562 for (eGlobal = 0; eGlobal <
m_nel; eGlobal++) {
574 for (i = 0; i < int(
m_np); i++) {
575 double vol = 1.0/
m_phase[i]->molarDensity();
582 int maxsteps,
int maxiter,
int loglevel)
588 doublereal hnow, herr = 1.0;
589 doublereal snow, serr = 1.0, s0;
590 doublereal Tlow = -1.0, Thigh = -1.0;
592 doublereal dta=0.0, dtmax, cpb;
612 e->equilibrate(XY, err, maxsteps, loglevel);
633 for (n = 0; n < maxiter; n++) {
649 e->equilibrate(TP, err, maxsteps, loglevel);
669 cpb = (Hhigh - Hlow)/(Thigh - Tlow);
670 dt = (h0 - hnow)/cpb;
672 dtmax = 0.5*fabs(Thigh - Tlow);
677 tnew = sqrt(Tlow*Thigh);
682 herr = fabs((h0 - hnow)/h0);
721 "try estimating starting composition");
724 tnew = 0.5*(
m_temp + Thigh);
725 if (fabs(tnew -
m_temp) < 1.0) {
745 "No convergence for T");
746 }
else if (XY == SP) {
756 for (n = 0; n < maxiter; n++) {
764 e->equilibrate(TP, err, maxsteps, loglevel);
775 serr = fabs((s0 - snow)/s0);
783 dtmax = 0.5*fabs(Thigh - Tlow);
784 dtmax = (dtmax > 500.0 ? 500.0 : dtmax);
789 if (herr < err || dta < 1.0e-4) {
812 "setting strt to True");
816 tnew = 0.5*(
m_temp + Thigh);
835 "No convergence for T");
836 }
else if (XY == TV) {
843 doublereal vnow, pnow, verr;
844 for (n = 0; n < maxiter; n++) {
850 e.equilibrate(TP, err, maxsteps, loglevel);
852 verr = fabs((v0 - vnow)/v0);
865 dVdP = (
volume() - vnow)/(0.01*pnow);
874 throw CanteraError(
"MultiPhase::equilibrate",
"unknown option");
886 #ifdef MULTIPHASE_DEVEL
887 void importFromXML(
string infile,
string id)
894 if (x.name() !=
"multiphase")
895 throw CanteraError(
"MultiPhase::importFromXML",
896 "Current XML_Node is not a multiphase element.");
897 vector<XML_Node*> phases;
898 x.getChildren(
"phase",phases);
899 int np = phases.size();
902 for (n = 0; n < np; n++) {
903 XML_Node& ph = *phases[n];
905 if (ph.hasAttrib(
"src")) {
911 addPhase(p, ph.value());
947 for (
size_t e = 0; e <
m_nel; e++) {
993 for (
int iph = 0; iph < (int)
m_np; iph++) {
1031 for (ip = 0; ip <
m_np; ip++) {
1041 size_t p, nsp, loc = 0;
1042 for (p = 0; p <
m_np; p++) {
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
XML_Node * get_XML_Node(const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
std::vector< size_t > m_spphase
Mapping between the global species number and the phase ID.
doublereal m_temp
Current value of the temperature (kelvin)
XML_Node * get_XML_File(const std::string &file, int debug)
Return a pointer to the XML tree for a Cantera input file.
doublereal equilibrate(int XY, doublereal err=1.0e-9, int maxsteps=1000, int maxiter=200, int loglevel=-99)
Set the mixture to a state of chemical equilibrium.
size_t nElements() const
Number of elements.
bool tempOK(size_t p) const
Return true if the phase p has valid thermo data for the current temperature.
void beginLogGroup(const std::string &title, int loglevel)
Create a new group for log messages.
bool m_init
True if the init() routine has been called, and the MultiPhase frozen.
virtual void setState_TPX(doublereal t, doublereal p, const doublereal *x)
Set the temperature (K), pressure (Pa), and mole fractions.
void setPhaseMoles(const size_t n, const doublereal moles)
Set the number of moles of phase with index n.
doublereal speciesMoles(size_t kGlob) const
Returns the moles of global species k. units = kmol.
void checkElementIndex(size_t m) const
Check that the specified element index is in range.
std::map< std::string, size_t > m_enamemap
Returns the global element index, given the element string name.
const size_t npos
index returned by functions to indicate "no position"
std::string speciesName(const size_t kGlob) const
Name of species with global index kGlob.
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies().
vector_int m_atomicNumber
Atomic number of each element.
doublereal phaseMoles(const size_t n) const
Return the number of moles in phase n.
doublereal temperature() const
Temperature [K].
void addPhase(ThermoPhase *p, doublereal moles)
Add a phase to the mixture.
Class XML_Node is a tree-based representation of the contents of an XML file.
doublereal phaseCharge(size_t p) const
Charge (Coulombs) of phase with index p.
int phaseIndex(const std::string &pName) const
Returns the index, given the phase name.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Equilib...
void getChemPotentials(doublereal *mu) const
Returns a vector of Chemical potentials.
virtual ~MultiPhase()
Destructor.
void checkPhaseArraySize(size_t mm) const
Check that an array size is at least nPhases() Throws an exception if mm is less than nPhases()...
const doublereal Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
vector_fp m_moles
Vector of the number of moles in each phase.
Base class for a phase with thermodynamic properties.
void getMoleFractions(doublereal *const x) const
Returns the global Species mole fractions.
size_t speciesPhaseIndex(const size_t kGlob) const
Returns the phase index of the Kth "global" species.
std::vector< std::string > m_enames
String names of the global elements.
doublereal gibbs() const
The Gibbs function of the mixture [J].
void addSpeciesMoles(const int indexS, const doublereal addedMoles)
Adds moles of a certain species to the mixture.
vector_fp m_moleFractions
Locally stored vector of mole fractions of all species comprising the MultiPhase object.
void uploadMoleFractionsFromPhases()
Update the locally-stored composition within this object to match the current compositions of the pha...
A class for multiphase mixtures.
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the matrix.
void checkPhaseIndex(size_t m) const
Check that the specified phase index is in range Throws an exception if m is greater than nPhases() ...
doublereal charge() const
Total charge summed over all phases (Coulombs).
std::vector< bool > m_temp_OK
Vector of bools indicating whether temperatures are ok for phases.
void setState_TPMoles(const doublereal T, const doublereal Pres, const doublereal *Moles)
Set the state of the underlying ThermoPhase objects in one call.
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
std::string elementName(size_t m) const
Returns the name of the global element m.
size_t m_eloc
Global ID of the element corresponding to the electronic charge.
void getValidChemPotentials(doublereal not_mu, doublereal *mu, bool standard=false) const
Returns a vector of Valid chemical potentials.
doublereal entropy() const
The entropy of the mixture [J/K].
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
void addPhases(std::vector< ThermoPhase * > &phases, const vector_fp &phaseMoles)
Add a vector of phases to the mixture.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
DenseMatrix m_atoms
Global Stoichiometric Coefficient array.
int atomicNumber(size_t m) const
Atomic number of element m.
std::vector< size_t > m_spstart
Vector of ints containing of first species index in the global list of species for each phase...
void setPhaseMoleFractions(const size_t n, const doublereal *const x)
Set the Mole fractions of the nth phase.
size_t m_nsp
Number of distinct species in all of the phases.
void calcElemAbundances() const
Calculate the element abundance vector.
std::string id() const
Return the string id for the phase.
size_t m_nel
Number of distinct elements in all of the phases.
void setTemperature(const doublereal T)
Set the temperature [K].
Base class for exceptions thrown by Cantera classes.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
void checkElementArraySize(size_t mm) const
Check that an array size is at least nElements().
size_t elementIndex(const std::string &name) const
Returns the index of the element with name name.
doublereal IntEnergy() const
The internal energy of the mixture [J].
size_t m_np
Number of phases in the MultiPhase object.
vector_fp m_elemAbundances
Vector of element abundances.
std::vector< ThermoPhase * > m_phase
Vector of the ThermoPhase pointers.
void getMoles(doublereal *molNum) const
Get the mole numbers of all species in the multiphase object.
doublereal nAtoms(const size_t kGlob, const size_t mGlob) const
Returns the Number of atoms of global element mGlob in global species kGlob.
void setPressure(doublereal P)
Set the pressure [Pa].
doublereal moleFraction(const size_t kGlob) const
Returns the mole fraction of global species k.
void endLogGroup(const std::string &title)
Close the current group of log messages.
size_t nSpecies() const
Returns the number of species in the phase.
void updatePhases() const
Set the states of the phase objects to the locally-stored state within this MultiPhase object...
void setState_TP(const doublereal T, const doublereal Pres)
Set the state of the underlying ThermoPhase objects in one call.
void addLogEntry(const std::string &tag, const std::string &value)
Add an entry to an HTML log file.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
void setMolesByName(compositionMap &xMap)
Set the number of moles of species in the mixture.
doublereal temperature() const
Temperature (K).
doublereal enthalpy() const
The enthalpy of the mixture [J].
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
doublereal maxTemp() const
Maximum temperature for which all solution phases have valid thermo data.
doublereal cp() const
Heat capacity at constant pressure [J/K].
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
std::string phaseName(const size_t iph) const
Returns the name of the n'th phase.
doublereal elementMoles(size_t m) const
Total moles of global element m, summed over all phases.
void init()
Process phases and build atomic composition array.
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
std::vector< std::string > m_snames
Vector of species names in the problem.
std::string elementName(size_t m) const
Name of the element with index m.
An array index is out of range.
bool solutionSpecies(size_t kGlob) const
Return true is species kGlob is a species in a multicomponent solution phase.
thermo_t & phase(size_t n)
Return a reference to phase n.
doublereal minTemp() const
Minimum temperature for which all solution phases have valid thermo data.
doublereal m_press
Current value of the pressure (Pa)
doublereal pressure() const
Pressure [Pa].
void getElemAbundances(doublereal *elemAbundances) const
Retrieves a vector of element abundances.
size_t nSpecies() const
Number of species, summed over all phases.
size_t speciesIndex(size_t k, size_t p) const
Return the global index of the species belonging to phase number p with local index k within the phas...
doublereal m_Tmax
Minimum temperature for which thermo parameterizations are valid.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
doublereal m_Tmin
Minimum temperature for which thermo parameterizations are valid.
std::string speciesName(size_t k) const
Name of the species with index k.
void setMoles(const doublereal *n)
Sets all of the global species mole numbers.
doublereal volume() const
The total mixture volume [m^3].
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid...
size_t nPhases() const
Number of phases.
void save()
Function to put this error onto Cantera's error stack.