23 m_undefinedElementBehavior(UndefElement::error),
38 m_undefinedElementBehavior(right.m_undefinedElementBehavior),
52 Phase& Phase::operator=(
const Phase& right)
92 XML_Node *rroot = &right.m_xml->
root();
93 XML_Node *root_xml =
new XML_Node();
94 rroot->copy(root_xml);
97 throw CanteraError(
"Phase::operator=()",
"Confused: Couldn't find original phase " + right.m_xml->id());
100 throw CanteraError(
"Phase::operator=()",
"confused: root changed");
126 xroot->
copy(root_xml);
134 throw CanteraError(
"Phase::setXMLdata()",
"XML 'phase' node not found");
137 throw CanteraError(
"Phase::setXMLdata()",
"Root XML node not found");
188 for (
size_t i = 0; i <
m_mm; i++) {
209 "Elements::entropy298",
210 "Entropy at 298 K of element is unknown");
246 for (
size_t m = 0; m <
m_mm; m++) {
254 if (loc ==
npos && nameStr.find(
':') !=
npos) {
330 doublereal norm = 0.0;
333 for (
size_t k = 0; k <
m_kk; k++) {
334 double xk = std::max(x[k], 0.0);
343 const doublereal invSum = 1.0/sum;
344 for (
size_t k=0; k <
m_kk; k++) {
350 for (
size_t k=0; k <
m_kk; k++) {
364 m_y.begin(), multiplies<double>());
371 for (
const auto& sp : xMap) {
374 }
catch (std::out_of_range&) {
376 "Unknown species '{}'", sp.first);
389 for (
size_t k = 0; k <
m_kk; k++) {
390 m_y[k] = std::max(y[k], 0.0);
392 doublereal norm = accumulate(
m_y.begin(),
m_y.end(), 0.0);
396 m_ym.begin(), multiplies<double>());
403 doublereal sum = 0.0;
404 copy(y, y +
m_kk,
m_y.begin());
406 multiplies<double>());
407 sum = accumulate(
m_ym.begin(),
m_ym.end(), 0.0);
415 for (
const auto& sp : yMap) {
418 }
catch (std::out_of_range&) {
420 "Unknown species '{}'", sp.first);
510 copy(mw.begin(), mw.end(), weights);
521 for (
size_t k = 0; k <
m_kk; k++) {
533 for (
size_t k = 0; k <
m_kk; k++) {
586 copy(
m_y.begin(),
m_y.end(), y);
603 doublereal sum = 0.0, norm = 0.0;
604 for (
size_t k = 0; k !=
m_kk; ++k) {
605 double ck = std::max(conc[k], 0.0);
612 doublereal rsum = 1.0/sum;
613 for (
size_t k = 0; k !=
m_kk; ++k) {
622 doublereal sum = 0.0, norm = 0.0;
623 for (
size_t k = 0; k !=
m_kk; ++k) {
629 doublereal rsum = 1.0/sum;
630 for (
size_t k = 0; k !=
m_kk; ++k) {
631 m_ym[k] = conc[k] * rsum;
640 doublereal Z_m = 0.0;
641 for (
size_t k = 0; k !=
m_kk; ++k) {
652 for (
size_t k = 0; k <
m_kk; k++) {
654 for (
size_t j = 0; j <
nElements(); j++) {
659 doublereal numerator = 0.0;
660 for (
size_t k = 0; k !=
m_kk; ++k) {
663 return numerator / denom;
683 doublereal cdens = 0.0;
684 for (
size_t k = 0; k <
m_kk; k++) {
687 return cdens * Faraday;
692 return m_mmw*std::inner_product(
m_ym.begin(),
m_ym.end(), Q, 0.0);
697 return m_mmw*std::inner_product(
m_ym.begin(),
m_ym.end(), Q.begin(), 0.0);
706 int atomic_number, doublereal entropy298,
716 }
else if (weight == -12345.0) {
726 "Duplicate elements ({}) have different weights", symbol);
749 for (
size_t k = 0; k <
m_kk; k++) {
750 size_t m_old =
m_mm - 1;
751 for (
size_t m = 0; m < m_old; m++) {
762 if (m_species.find(ba::to_lower_copy(spec->name)) != m_species.end()) {
764 "Phase '{}' already contains a species named '{}'.",
768 for (
const auto& elem : spec->composition) {
772 case UndefElement::ignore:
775 case UndefElement::add:
781 case UndefElement::error:
784 "Species '{}' contains an undefined element '{}'.",
785 spec->name, elem.first);
788 comp[m] = elem.second;
792 m_species[ba::to_lower_copy(spec->name)] = spec;
800 if (spec->charge != 0.0) {
802 if (eindex !=
npos) {
803 doublereal ecomp = comp[eindex];
804 if (fabs(spec->charge + ecomp) > 0.001) {
807 "Input charge and element E compositions differ " 808 "for species " + spec->name);
812 comp[eindex] = -spec->charge;
820 comp[ne - 1] = - spec->charge;
823 for (
size_t m = 0; m < ne; m++) {
825 wt += comp[m] * aw[m];
831 wt = std::max(wt,
Tiny);
855 "New species name '{}' does not match existing name '{}'",
858 const shared_ptr<Species>& old = m_species[ba::to_lower_copy(spec->name)];
859 if (spec->composition != old->composition) {
861 "New composition for '{}' does not match existing composition",
864 m_species[ba::to_lower_copy(spec->name)] = spec;
870 return m_species.at(ba::to_lower_copy(
name));
Phase()
Default constructor.
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
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.
doublereal molarVolume() const
Molar volume (m^3/kmol).
std::vector< std::string > m_elementNames
element names
size_t nElements() const
Number of elements.
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.
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
vector_fp m_atomicWeights
element atomic weights (kg kmol-1)
doublereal temperature() const
Temperature (K).
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
void saveState(vector_fp &state) const
Save the current internal state of the phase.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
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.
size_t elementIndex(const std::string &name) const
Return the index of element named 'name'.
doublereal sum_xlogx() const
Evaluate .
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)
compositionMap getMoleFractionsByName(double threshold=0.0) const
Get the mole fractions by name.
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 checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
vector_fp m_speciesSize
Vector of species sizes.
size_t nSpecies() const
Returns the number of species in the phase.
virtual doublereal density() const
Density (kg/m^3).
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.
virtual bool ready() const
Returns a bool indicating whether the object is ready for use.
Unary operator to multiply the argument by a constant.
UndefElement::behavior m_undefinedElementBehavior
Flag determining behavior when adding species with an undefined element.
std::string m_name
Name of the phase.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
int atomicNumber(size_t m) const
Atomic number of element m.
void setName(const std::string &nm)
Sets the string name for the phase.
doublereal elementalMoleFraction(const size_t m) const
Elemental mole fraction of element m.
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.
doublereal atomicWeight(size_t m) const
Atomic weight of element m.
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.
void checkElementArraySize(size_t mm) const
Check that an array size is at least nElements().
doublereal molarDensity() const
Molar density (kmol/m^3).
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
std::string speciesName(size_t k) const
Name of the species with index k.
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
doublereal entropyElement298(size_t m) const
Entropy of the element in its standard state at 298 K and 1 bar.
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 clear()
Clear all cached values.
const doublereal * moleFractdivMMW() const
Returns a const pointer to the start of the moleFraction/MW array.
void setMoleFractionsByName(const compositionMap &xMap)
Set the species mole fractions by name.
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
void setMassFractionsByName(const compositionMap &yMap)
Set the species mass fractions by name.
virtual void modifySpecies(size_t k, shared_ptr< Species > spec)
Modify the thermodynamic data associated with a species.
Base class for exceptions thrown by Cantera classes.
void setState_TNX(doublereal t, doublereal n, const doublereal *x)
Set the internally stored temperature (K), molar density (kmol/m^3), and mole fractions.
double getElementWeight(const std::string &ename)
Get the atomic weight of an element.
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
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.
std::string parseSpeciesName(const std::string &nameStr, std::string &phaseName)
Parse a name string, separating out the phase name from the species name.
doublereal sum_xlogx(InputIter begin, InputIter end)
Compute .
doublereal concentration(const size_t k) const
Concentration of species k.
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
virtual void setMolarDensity(const doublereal molarDensity)
Set the internally stored molar density (kmol/m^3) of the phase.
XML_Node & xml() const
Returns a const reference to the XML_Node that describes the phase.
virtual void setConcentrationsNoNorm(const double *const conc)
Set the concentrations without ignoring negative concentrations.
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
compositionMap getMassFractionsByName(double threshold=0.0) const
Get the mass fractions by name.
void copy(XML_Node *const node_dest) const
Copy all of the information in the current XML_Node tree into the destination XML_Node tree...
#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.
void setState_TX(doublereal t, doublereal *x)
Set the internally stored temperature (K) and mole fractions.
XML_Node & root() const
Return the root of the current XML_Node tree.
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.
doublereal elementalMassFraction(const size_t m) const
Elemental mass fraction of element m.
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
doublereal chargeDensity() const
Charge density [C/m^3].
std::string id() const
Return the string id for the phase.
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.
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies().
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.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
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.
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.
int elementType(size_t m) const
Return the element constraint type Possible types include:
std::string id() const
Return the id attribute, if present.
void getMolecularWeights(vector_fp &weights) const
Copy the vector of molecular weights into vector weights.
XML_Node * m_xml
XML node containing the XML info for this phase.
std::string name() const
Return the name of the phase.
vector_int m_atomicNumbers
element atomic numbers
Contains declarations for string manipulation functions within Cantera.
doublereal m_temp
Temperature (K). This is an independent variable.
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
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.
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.
doublereal molecularWeight(size_t k) const
Molecular weight of species k.
Namespace for the Cantera kernel.
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
doublereal nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
void setState_TR(doublereal t, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
const std::vector< std::string > & elementNames() const
Return a read-only reference to the vector of element names.
const vector_fp & atomicWeights() const
Return a read-only reference to the vector of atomic weights.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
std::string elementName(size_t m) const
Name of the element with index m.
void checkElementIndex(size_t m) const
Check that the specified element index is in range.
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase.
doublereal massFraction(size_t k) const
Return the mass fraction of a single species.