22 m_undefinedElementBehavior(UndefElement::
error),
38 m_undefinedElementBehavior(right.m_undefinedElementBehavior),
98 (rroot)->copy(root_xml);
101 throw CanteraError(
"Phase::operator=()",
"Confused: Couldn't find original phase " + right.
m_xml->
id());
104 throw CanteraError(
"Phase::operator=()",
"confused: root changed");
132 (xroot)->copy(root_xml);
140 throw CanteraError(
"Phase::setXMLdata()",
"XML 'phase' node not found");
143 throw CanteraError(
"Phase::setXMLdata()",
"Root XML node not found");
194 for (
size_t i = 0; i <
m_mm; i++) {
215 "Elements::entropy298",
216 "Entropy at 298 K of element is unknown");
252 for (
size_t m = 0; m <
m_mm; m++) {
259 if (nameStr.find(
':') !=
npos) {
334 doublereal norm = 0.0;
339 for (
size_t k = 0; k <
m_kk; k++) {
340 double xk = std::max(x[k], 0.0);
349 const doublereal invSum = 1.0/sum;
350 for (
size_t k=0; k <
m_kk; k++) {
357 for (
size_t k=0; k <
m_kk; k++) {
372 m_y.begin(), multiplies<double>());
379 for (
size_t k = 0; k <
m_kk; k++) {
392 for (
size_t k = 0; k <
m_kk; k++) {
393 m_y[k] = std::max(y[k], 0.0);
395 doublereal norm = accumulate(
m_y.begin(),
m_y.end(), 0.0);
399 m_ym.begin(), multiplies<double>());
406 doublereal sum = 0.0;
407 copy(y, y +
m_kk,
m_y.begin());
409 multiplies<double>());
410 sum = accumulate(
m_ym.begin(),
m_ym.end(), 0.0);
418 for (
size_t k = 0; k <
m_kk; k++) {
503 if (weights.size() < mw.size()) {
504 weights.resize(mw.size());
506 copy(mw.begin(), mw.end(), weights.begin());
512 copy(mw.begin(), mw.end(), weights);
523 "To be removed after Cantera 2.2. Use"
524 " 'compositionMap getMoleFractionsByName(double threshold)'"
527 for (
size_t k = 0; k <
m_kk; k++) {
535 for (
size_t k = 0; k <
m_kk; k++) {
547 for (
size_t k = 0; k <
m_kk; k++) {
600 copy(
m_y.begin(),
m_y.end(), y);
617 doublereal sum = 0.0, norm = 0.0;
618 for (
size_t k = 0; k !=
m_kk; ++k) {
619 double ck = std::max(conc[k], 0.0);
626 doublereal rsum = 1.0/sum;
627 for (
size_t k = 0; k !=
m_kk; ++k) {
637 doublereal Z_m = 0.0;
638 for (
size_t k = 0; k !=
m_kk; ++k) {
649 for (
size_t k = 0; k <
m_kk; k++) {
651 for (
size_t j = 0; j <
nElements(); j++) {
656 doublereal numerator = 0.0;
657 for (
size_t k = 0; k !=
m_kk; ++k) {
660 return numerator / denom;
680 doublereal cdens = 0.0;
681 for (
size_t k = 0; k <
m_kk; k++) {
684 return cdens * Faraday;
689 return m_mmw*std::inner_product(
m_ym.begin(),
m_ym.end(), Q, 0.0);
694 return m_mmw*std::inner_product(
m_ym.begin(),
m_ym.end(), Q.begin(), 0.0);
710 warn_deprecated(
"Phase::sum_xlogQ",
"To be removed after Cantera 2.2.");
715 int atomic_number, doublereal entropy298,
719 if (weight == -12345.0) {
723 "No atomic weight found for element: " + symbol);
728 vector<string>::const_iterator iter = find(
m_elementNames.begin(),
735 "Duplicate elements (" + symbol +
") have different weights");
759 for (
size_t k = 0; k <
m_kk; k++) {
760 size_t m_old = m_mm - 1;
761 for (
size_t m = 0; m < m_old; m++) {
774 "To be removed after Cantera 2.2.");
775 doublereal weight = 0.0;
781 anum = atoi(
stripws(e[
"atomicNumber"]).c_str());
783 string symbol = e[
"name"];
799 int atomic_number, doublereal entropy298,
803 "Equivalent to Phase::addElement. "
804 "To be removed after Cantera 2.2.");
805 addElement(symbol, weight, atomic_number, entropy298, elem_type);
811 "To be removed after Cantera 2.2.");
818 "Use 'addElements' function. "
819 "To be removed after Cantera 2.2.");
825 warn_deprecated(
"Phase::freezeElements",
"To be removed after Cantera 2.2.");
830 warn_deprecated(
"Phase::elementsFrozen",
"To be removed after Cantera 2.2.");
835 doublereal weight,
int atomicNumber,
836 doublereal entropy298,
int elem_type)
839 "Equivalent to Phase::addElement. "
840 "To be removed after Cantera 2.2");
841 return addElement(symbol, weight, atomicNumber, entropy298, elem_type);
845 m_species[spec->name] = spec;
847 for (map<string, double>::const_iterator iter = spec->composition.begin();
848 iter != spec->composition.end();
853 case UndefElement::ignore:
856 case UndefElement::add:
865 "Species '" + spec->name +
"' contains an "
866 "undefined element '" + iter->first +
"'.");
869 comp[m] = iter->second;
880 if (spec->charge != 0.0) {
882 if (eindex !=
npos) {
883 doublereal ecomp = comp[eindex];
884 if (fabs(spec->charge + ecomp) > 0.001) {
887 "Input charge and element E compositions differ "
888 "for species " + spec->name);
892 comp[eindex] = -spec->charge;
900 comp[ne - 1] = - spec->charge;
903 for (
size_t m = 0; m < ne; m++) {
905 wt += comp[m] * aw[m];
911 wt = std::max(wt,
Tiny);
931 doublereal charge_, doublereal size_)
934 "Use AddSpecies(shared_ptr<Species> spec) instead. To be removed "
935 "after Cantera 2.2.");
937 for (
size_t i = 0; i <
nElements(); i++) {
942 shared_ptr<Species> sp(
new Species(name_, cmap, charge_, size_));
947 doublereal charge_, doublereal size_)
950 "Use AddSpecies(shared_ptr<Species> spec) instead. To be removed "
951 "after Cantera 2.2.");
952 for (
size_t k = 0; k <
m_kk; k++) {
955 for (
size_t i = 0; i <
m_mm; i++) {
958 "Duplicate species have different "
959 "compositions: " + name_);
964 "Duplicate species have different "
965 "charges: " + name_);
969 "Duplicate species have different "
Phase()
Default constructor.
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
doublereal fpValue(const std::string &val)
Translate a string into one doublereal value.
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
vector_fp m_y
Mass fractions of the species.
void setState_RY(doublereal rho, doublereal *y)
Set the density (kg/m^3) and mass fractions.
std::vector< std::string > m_elementNames
element names
virtual doublereal density() const
Density (kg/m^3).
doublereal LookupWtElements(const std::string &ename)
Function to look up an atomic weight This function looks up the argument string in the database above...
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
void setState_TRY(doublereal t, doublereal dens, const doublereal *y)
Set the internally stored temperature (K), density, and mass fractions.
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
size_t nElements() const
Number of elements.
vector_fp m_atomicWeights
element atomic weights (kg kmol-1)
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
const size_t npos
index returned by functions to indicate "no position"
vector_fp m_speciesCharge
Vector of species charges. length m_kk.
Header file for class Phase.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
vector_fp m_entropy298
Entropy at 298.15 K and 1 bar of stable state pure elements (J kmol-1)
doublereal atomicWeight(size_t m) const
Atomic weight of element m.
Class XML_Node is a tree-based representation of the contents of an XML file.
std::map< std::string, size_t > m_speciesIndices
Map of species names to indices.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
vector_fp m_speciesSize
Vector of species sizes.
doublereal m_mmw
mean molecular weight of the mixture (kg kmol-1)
Class Phase is the base class for phases of matter, managing the species and elements in a phase...
#define CT_ELEM_TYPE_ELECTRONCHARGE
This refers to conservation of electrons.
doublereal molarDensity() const
Molar density (kmol/m^3).
void getMoleFractionsByName(compositionMap &x) const
Get the mole fractions by name.
Unary operator to multiply the argument by a constant.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
void checkElementIndex(size_t m) const
Check that the specified element index is in range Throws an exception if m is greater than nElements...
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
std::string name() const
Return the name of the phase.
UndefElement::behavior m_undefinedElementBehavior
Flag determining behavior when adding species with an undefined element.
std::string m_name
Name of the phase.
void checkElementArraySize(size_t mm) const
Check that an array size is at least nElements() Throws an exception if mm is less than nElements()...
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
doublereal concentration(const size_t k) const
Concentration of species k.
#define AssertThrowMsg(expr, procedure, message)
Assertion must be true or an error is thrown.
doublereal sum_xlogQ(doublereal *const Q) const
Evaluate .
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
doublereal entropyElement298(size_t m) const
Entropy of the element in its standard state at 298 K and 1 bar.
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range Throws an exception if k is greater than nSpecies(...
void setName(const std::string &nm)
Sets the string name for the phase.
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
const vector_fp & atomicWeights() const
Return a read-only reference to the vector of atomic weights.
virtual bool ready() const
Returns a bool indicating whether the object is ready for use.
void throwUndefinedElements()
Set the behavior when adding a species containing undefined elements to throw an exception.
int m_stateNum
State Change variable.
size_t m_ndim
Dimensionality of the phase.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
void ignoreUndefinedElements()
Set behavior when adding a species containing undefined elements to just skip the species...
std::vector< std::string > m_speciesNames
Vector of the species names.
void setState_TRX(doublereal t, doublereal dens, const doublereal *x)
Set the internally stored temperature (K), density, and mole fractions.
void getAtoms(size_t k, double *atomArray) const
Get a vector containing the atomic composition of species k.
bool elementsFrozen()
True if freezeElements has been called.
std::string stripws(const std::string &s)
Strip the leading and trailing white space from a string.
void addUniqueElement(const std::string &symbol, doublereal weight=-12345.0, int atomicNumber=0, doublereal entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element, checking for uniqueness The uniqueness is checked by comparing the string symbol...
doublereal molarVolume() const
Molar volume (m^3/kmol).
doublereal sum_xlogx() const
Evaluate .
enum CT_RealNumber_Range_Behavior realNumberRangeBehavior_
Overflow behavior of real number calculations involving this thermo object.
int atomicNumber(size_t m) const
Atomic number of element m.
void error(const std::string &msg)
Write an error message and quit.
doublereal chargeDensity() const
Charge density [C/m^3].
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
void setMoleFractionsByName(const compositionMap &xMap)
Set the species mole fractions by name.
std::string id() const
Return the string id for the phase.
void setMassFractionsByName(const compositionMap &yMap)
Set the species mass fractions by name.
Base class for exceptions thrown by Cantera classes.
doublereal sum_xlogQ(InputIter1 begin, InputIter1 end, InputIter2 Q_begin)
Compute .
void setState_TNX(doublereal t, doublereal n, const doublereal *x)
Set the internally stored temperature (K), molar density (kmol/m^3), and mole fractions.
void addElementsFromXML(const XML_Node &phase)
Add all elements referenced in an XML_Node tree.
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values There is no restriction on the sum of the mole fractio...
virtual ~Phase()
Destructor.
std::string parseSpeciesName(const std::string &nameStr, std::string &phaseName)
Parse a name string, separating out the phase name from the species name.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
doublereal sum_xlogx(InputIter begin, InputIter end)
Compute .
const std::vector< std::string > & elementNames() const
Return a read-only reference to the vector of element names.
doublereal massFraction(size_t k) const
Return the mass fraction of a single species.
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
doublereal elementalMoleFraction(const size_t m) const
Elemental mole fraction of element m.
virtual void setMolarDensity(const doublereal molarDensity)
Set the internally stored molar density (kmol/m^3) of the phase.
void installElements(Phase &th, const XML_Node &phaseNode)
Add the elements given in an XML_Node tree to the specified phase.
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
#define ENTROPY298_UNKNOWN
Number indicating we don't know the entropy of the element in its most stable state at 298...
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
size_t nSpecies() const
Returns the number of species in the phase.
void setState_TX(doublereal t, doublereal *x)
Set the internally stored temperature (K) and mole fractions.
vector_int m_elem_type
Vector of element types.
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.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
doublereal temperature() const
Temperature (K).
void freezeElements()
Prohibit addition of more elements, and prepare to add species.
size_t addElement(const std::string &symbol, doublereal weight=-12345.0, int atomicNumber=0, doublereal entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element.
std::string id() const
Return the id attribute, if present.
vector_fp m_molwts
species molecular weights (kg kmol-1)
void setState_TY(doublereal t, doublereal *y)
Set the internally stored temperature (K) and mass fractions.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies() Throws an exception if kk is less than nSpecies()...
XML_Node & xml() const
Returns a const reference to the XML_Node that describes the phase.
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
Templates for operations on vector-like objects.
Phase & operator=(const Phase &right)
Assignment operator.
void addUndefinedElements()
Set behavior when adding a species containing undefined elements to add those elements to the phase...
size_t m_mm
Number of elements.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
const doublereal Tiny
Small number to compare differences of mole fractions against.
compositionMap getMassFractionsByName(double threshold=0.0) const
Get the mass fractions by name.
std::string m_id
ID of the phase.
doublereal m_dens
Density (kg m-3).
vector_fp m_ym
m_ym[k] = mole fraction of species k divided by the mean molecular weight of mixture.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
XML_Node * m_xml
XML node containing the XML info for this phase.
vector_int m_atomicNumbers
element atomic numbers
Contains declarations for string manipulation functions within Cantera.
std::string speciesSPName(int k) const
Returns the expanded species name of a species, including the phase name This is guaranteed to be uni...
void getMolecularWeights(vector_fp &weights) const
Copy the vector of molecular weights into vector weights.
std::string elementName(size_t m) const
Name of the element with index m.
doublereal m_temp
Temperature (K). This is an independent variable.
void saveState(vector_fp &state) const
Save the current internal state of the phase Write to vector 'state' the current internal state...
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
int elementType(size_t m) const
Return the element constraint type Possible types include:
Contains data about a single chemical species.
vector_fp m_rmolwts
inverse of species molecular weights (kmol kg-1)
vector_fp m_speciesComp
Atomic composition of the species.
void setXMLdata(XML_Node &xmlPhase)
Stores the XML tree information for the current phase.
void setState_RX(doublereal rho, doublereal *x)
Set the density (kg/m^3) and mole fractions.
size_t m_kk
Number of species in the phase.
size_t addUniqueElementAfterFreeze(const std::string &symbol, doublereal weight, int atomicNumber, doublereal entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element after elements have been frozen, checking for uniqueness The uniqueness is checked by ...
An array index is out of range.
int changeElementType(int m, int elem_type)
Change the element type of the mth constraint Reassigns an element type.
void setID(const std::string &id)
Set the string id for the phase.
Cantera will throw an error in debug mode but will not in production mode.
XML_Node & root() const
Return the root of the current XML_Node tree.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
void setState_TR(doublereal t, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
std::string speciesName(size_t k) const
Name of the species with index k.
void addUniqueSpecies(const std::string &name, const doublereal *comp, doublereal charge=0.0, doublereal size=1.0)
Add a species to the phase, checking for uniqueness of the name This routine checks for uniqueness of...
const doublereal * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
doublereal mean_Y(const doublereal *const Q) const
Evaluate the mass-fraction-weighted mean of an array Q.
bool hasAttrib(const std::string &a) const
Tests whether the current node has an attribute with a particular name.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
doublereal elementalMassFraction(const size_t m) const
Elemental mass fraction of element m.