38        throw IndexError(
"Phase::checkElementIndex", 
"elements", m, 
m_mm-1);
 
   57    for (
size_t i = 0; i < 
m_mm; i++) {
 
  121                               "Lowercase species name '{}' is not unique. " 
  122                               "Set Phase::caseSensitiveSpecies to true to " 
  123                               "enforce case sensitive species names", nLower);
 
  156        throw IndexError(
"Phase::checkSpeciesIndex", 
"species", k, 
m_kk-1);
 
  171            return { {
"T", 0}, {
"D", 1} };
 
  173            return { {
"T", 0}, {
"P", 1} };
 
  177            return { {
"T", 0}, {
"D", 1}, {
"Y", 2} };
 
  179            return { {
"T", 0}, {
"P", 1}, {
"Y", 2} };
 
  186    map<size_t, string> states; 
 
  188        states[value] = 
name;
 
  191    for (
auto& [value, 
name] : states) {
 
  201            return {
"TD", 
"TP", 
"UV", 
"DP", 
"HP", 
"SP", 
"SV"};
 
  203            return {
"TP", 
"HP", 
"SP"};
 
  207            return {
"TDX", 
"TDY", 
"TPX", 
"TPY", 
"UVX", 
"UVY", 
"DPX", 
"DPY",
 
  208                    "HPX", 
"HPY", 
"SPX", 
"SPY", 
"SVX", 
"SVY"};
 
  210            return {
"TPX", 
"TPY", 
"HPX", 
"HPY", 
"SPX", 
"SPY"};
 
  221            return {
"TD", 
"TP", 
"UV", 
"DP", 
"HP", 
"SP", 
"SV"};
 
  223            return {
"TP", 
"HP", 
"SP"};
 
  249        state[native.at(
"D")] = 
density();
 
  253    if (native.count(
"X")) {
 
  255    } 
else if (native.count(
"Y")) {
 
  281    if (native.count(
"X")) {
 
  283    } 
else if (native.count(
"Y")) {
 
  295    for (
size_t k = 0; k < 
m_kk; k++) {
 
  296        double xk = std::max(x[k], 0.0); 
 
  305    const double invSum = 1.0/sum;
 
  306    for (
size_t k=0; k < 
m_kk; k++) {
 
  312    for (
size_t k=0; k < 
m_kk; k++) {
 
  326              m_y.begin(), multiplies<double>());
 
  343    for (
size_t k = 0; k < 
m_kk; k++) {
 
  344        m_y[k] = std::max(y[k], 0.0); 
 
  346    double norm = accumulate(
m_y.begin(), 
m_y.end(), 0.0);
 
  350              m_ym.begin(), multiplies<double>());
 
  358    copy(y, y + 
m_kk, 
m_y.begin());
 
  360              multiplies<double>());
 
  361    sum = accumulate(
m_ym.begin(), 
m_ym.end(), 0.0);
 
  392    copy(mw.begin(), mw.end(), weights);
 
  413    for (
size_t k = 0; k < 
m_kk; k++) {
 
  425    for (
size_t k = 0; k < 
m_kk; k++) {
 
  473    copy(
m_y.begin(), 
m_y.end(), y);
 
  492    double sum = 0.0, norm = 0.0;
 
  493    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  494        double ck = std::max(conc[k], 0.0); 
 
  501    double rsum = 1.0/sum;
 
  502    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  513    double sum = 0.0, norm = 0.0;
 
  514    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  520    double rsum = 1.0/sum;
 
  521    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  522        m_ym[k] = conc[k] * rsum;
 
  532    double totalMoles = accumulate(
m_ym.begin(), 
m_ym.end(), 0.0);
 
  534    copy(N, N + 
m_kk, 
m_y.begin());
 
  535    transform(
m_y.begin(), 
m_y.end(), 
m_molwts.begin(), 
m_y.begin(), multiplies<double>());
 
  536    double totalMass = accumulate(
m_y.begin(), 
m_y.end(), 0.0);
 
  538    m_mmw = totalMass/totalMoles;
 
  551    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  562    for (
size_t k = 0; k < 
m_kk; k++) {
 
  564        for (
size_t j = 0; j < 
nElements(); j++) {
 
  569    double numerator = 0.0;
 
  570    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  573    return numerator / denom;
 
  589    if (density_ > 0.0) {
 
  593            "density must be positive. density = {}", density_);
 
  599    if (density_ > 0.0) {
 
  603            "density must be positive. density = {}", density_);
 
  610    for (
size_t k = 0; k < 
m_kk; k++) {
 
  618    return m_mmw*std::inner_product(
m_ym.begin(), 
m_ym.end(), Q, 0.0);
 
  623    return m_mmw*std::inner_product(
m_ym.begin(), 
m_ym.end(), Q.begin(), 0.0);
 
  629    for (
size_t k = 0; k < 
m_kk; k++) {
 
  636                         double entropy298, 
int elem_type)
 
  645    } 
else if (weight == -12345.0) {
 
  653                "element-standard-entropies.yaml");
 
  654            const AnyMap& elem = db[
"elements"].getMapWhere(
"symbol", symbol);
 
  666                "Duplicate elements ({}) have different weights", symbol);
 
  689        for (
size_t k = 0; k < 
m_kk; k++) {
 
  690            size_t m_old = 
m_mm - 1;
 
  691            for (
size_t m = 0; m < m_old; m++) {
 
  705                "Cannot add species to ThermoPhase '{}' because it is being " 
  706                "used by another object,\nsuch as a Reactor, Domain1D (flame), " 
  707                "SolutionArray, or MultiPhase (Mixture) object.", 
m_name);
 
  712            "Phase '{}' already contains a species named '{}'.",
 
  717    for (
const auto& [eName, stoich] : spec->composition) {
 
  721            case UndefElement::ignore:
 
  724            case UndefElement::add:
 
  730            case UndefElement::error:
 
  733                    "Species '{}' contains an undefined element '{}'.",
 
  742    if (spec->charge != 0.0) {
 
  744        if (eindex != 
npos) {
 
  745            double ecomp = comp[eindex];
 
  746            if (fabs(spec->charge + ecomp) > 0.001) {
 
  749                                       "Input charge and element E compositions differ " 
  750                                       "for species " + spec->name);
 
  754                    comp[eindex] = -spec->charge;
 
  762            comp[ne - 1] = - spec->charge;
 
  767    for (
size_t m = 0; m < ne; m++) {
 
  768        wt += comp[m] * aw[m];
 
  774    wt = std::max(wt, 
Tiny);
 
  776    spec->setMolecularWeight(wt);
 
  781    for (
size_t m = 0; m < ne; m++) {
 
  817            "New species name '{}' does not match existing name '{}'",
 
  820    const shared_ptr<Species>& old = 
m_species[spec->name];
 
  821    if (spec->composition != old->composition) {
 
  823            "New composition for '{}' does not match existing composition",
 
  834            "Invalid alias '{}': species already exists", alias);
 
  841            "Unable to add alias '{}' " 
  842            "(original species '{}' not found).", alias, 
name);
 
  850                "ThermoPhase '{}' has no current species locks.", 
m_name);
 
  857    vector<string> isomerNames;
 
  860        if (
species->composition == compMap) {
 
  861            isomerNames.emplace_back(
name);
 
  880                           "Unknown species '{}'", 
name);
 
  918              multiplies<double>());
 
  928    vector<double> X(
m_kk);
 
  929    for (
const auto& [
name, value] : comp) {
 
  933                               "Unknown species '{}'", 
name);
 
  943    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  947        throw CanteraError(
"Phase::massFractionsToMoleFractions",
 
  948                           "no input composition given");
 
  950    for (
size_t k = 0; k != 
m_kk; ++k) {
 
  959        throw CanteraError(
"Phase::moleFractionsToMassFractions",
 
  960                           "no input composition given");
 
  962    double rmmw = 1.0/mmw;
 
  963    for (
size_t k = 0; k != 
m_kk; ++k) {
 
#define CT_ELEM_TYPE_ELECTRONCHARGE
This refers to conservation of electrons.
#define ENTROPY298_UNKNOWN
Number indicating we don't know the entropy of the element in its most stable state at 298....
Header file for class Phase.
Declaration for class Cantera::Species.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
double convert(const string &key, const string &units) const
Convert the item stored by the given key to the units specified in units.
static AnyMap fromYamlFile(const string &name, const string &parent_name="")
Create an AnyMap from a YAML file.
Base class for exceptions thrown by Cantera classes.
An array index is out of range.
virtual vector< string > partialStates() const
Return a vector of settable partial property sets within a phase.
void getCharges(double *charges) const
Copy the vector of species charges into array charges.
virtual void getConcentrations(double *const c) const
Get the species concentrations (kmol/m^3).
map< string, size_t > m_speciesLower
Map of lower-case species names to indices.
double massFraction(size_t k) const
Return the mass fraction of a single species.
virtual double molarDensity() const
Molar density (kmol/m^3).
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
int changeElementType(int m, int elem_type)
Change the element type of the mth constraint Reassigns an element type.
const vector< double > & atomicWeights() const
Return a read-only reference to the vector of atomic weights.
virtual vector< string > fullStates() const
Return a vector containing full states defining a phase.
void assertCompressible(const string &setter) const
Ensure that phase is compressible.
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
vector< double > m_speciesComp
Atomic composition of the species.
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
size_t m_nSpeciesLocks
Reference counter preventing species addition.
vector< string > m_speciesNames
Vector of the species names.
size_t nSpecies() const
Returns the number of species in the phase.
bool m_caseSensitiveSpecies
Flag determining whether case sensitive species names are enforced.
vector< string > m_elementNames
element names
void ignoreUndefinedElements()
Set behavior when adding a species containing undefined elements to just skip the species.
UndefElement::behavior m_undefinedElementBehavior
Flag determining behavior when adding species with an undefined element.
virtual void setMassFractions_NoNorm(const double *const y)
Set the mass fractions to the specified values without normalizing.
virtual map< string, size_t > nativeState() const
Return a map of properties defining the native state of a substance.
double chargeDensity() const
Charge density [C/m^3].
void addUndefinedElements()
Set behavior when adding a species containing undefined elements to add those elements to the phase.
virtual void setConcentrationsNoNorm(const double *const conc)
Set the concentrations without ignoring negative concentrations.
vector< int > m_atomicNumbers
element atomic numbers
size_t m_kk
Number of species in the phase.
int atomicNumber(size_t m) const
Atomic number of element m.
virtual void modifySpecies(size_t k, shared_ptr< Species > spec)
Modify the thermodynamic data associated with a species.
double m_mmw
mean molecular weight of the mixture (kg kmol-1)
double elementalMoleFraction(const size_t m) const
Elemental mole fraction of element m.
void setState_TD(double t, double rho)
Set the internally stored temperature (K) and density (kg/m^3)
vector< double > m_rmolwts
inverse of species molecular weights (kmol kg-1)
double temperature() const
Temperature (K).
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
virtual bool isCompressible() const
Return whether phase represents a compressible substance.
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
void moleFractionsToMassFractions(const double *X, double *Y) const
Converts a mixture composition from mass fractions to mole fractions.
virtual void setConcentrations(const double *const conc)
Set the concentrations to the specified values within the phase.
void removeSpeciesLock()
Decrement species lock counter.
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Composition getMoleFractionsByName(double threshold=0.0) const
Get the mole fractions by name.
size_t elementIndex(const string &name) const
Return the index of element named 'name'.
virtual double concentration(const size_t k) const
Concentration of species k.
double atomicWeight(size_t m) const
Atomic weight of element m.
void checkElementArraySize(size_t mm) const
Check that an array size is at least nElements().
void setMassFractionsByName(const Composition &yMap)
Set the species mass fractions by name.
int elementType(size_t m) const
Return the element constraint type Possible types include:
string speciesName(size_t k) const
Name of the species with index k.
map< string, size_t > m_speciesIndices
Map of species names to indices.
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
Composition getMassFractionsByName(double threshold=0.0) const
Get the mass fractions by name.
virtual size_t stateSize() const
Return size of vector defining internal state of the phase.
string nativeMode() const
Return string acronym representing the native state of a Phase.
vector< double > getCompositionFromMap(const Composition &comp) const
Converts a Composition to a vector with entries for each species Species that are not specified are s...
map< string, shared_ptr< Species > > m_species
Map of Species objects.
size_t findSpeciesLower(const string &nameStr) const
Find lowercase species name in m_speciesIndices when case sensitive species names are not enforced an...
vector< double > m_molwts
species molecular weights (kg kmol-1)
virtual vector< string > findIsomers(const Composition &compMap) const
Return a vector with isomers names matching a given composition map.
const vector< double > & inverseMolecularWeights() const
Return a const reference to the internal vector of molecular weights.
virtual bool isPure() const
Return whether phase represents a pure (single species) substance.
vector< double > m_y
Mass fractions of the species.
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
void setMoleFractionsByName(const Composition &xMap)
Set the species mole fractions by name.
const double * massFractions() const
Return a const pointer to the mass fraction array.
vector< int > m_elem_type
Vector of element types.
double sum_xlogx() const
Evaluate .
string m_name
Name of the phase.
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
double moleFraction(size_t k) const
Return the mole fraction of a single species.
double m_dens
Density (kg m-3).
const vector< string > & elementNames() const
Return a read-only reference to the vector of element names.
virtual double density() const
Density (kg/m^3).
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
vector< double > m_atomicWeights
element atomic weights (kg kmol-1)
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies().
void getMolecularWeights(double *weights) const
Copy the vector of molecular weights into array weights.
double nAtoms(size_t k, size_t m) const
Number of atoms of element m in species k.
void addSpeciesAlias(const string &name, const string &alias)
Add a species alias (that is, a user-defined alternative species name).
virtual void setMolesNoTruncate(const double *const N)
Set the state of the object with moles in [kmol].
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
size_t nElements() const
Number of elements.
void setMolecularWeight(const int k, const double mw)
Set the molecular weight of a single species to a given value.
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
vector< double > m_entropy298
Entropy at 298.15 K and 1 bar of stable state pure elements (J kmol-1)
vector< double > m_ym
m_ym[k] = mole fraction of species k divided by the mean molecular weight of mixture.
virtual void setMassFractions(const double *const y)
Set the mass fractions to the specified values and normalize them.
const vector< string > & speciesNames() const
Return a const reference to the vector of species names.
virtual bool ready() const
Returns a bool indicating whether the object is ready for use.
double molecularWeight(size_t k) const
Molecular weight of species k.
double elementalMassFraction(const size_t m) const
Elemental mass fraction of element m.
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
virtual double molarVolume() const
Molar volume (m^3/kmol).
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
void checkElementIndex(size_t m) const
Check that the specified element index is in range.
void getMassFractions(double *const y) const
Get the species mass fractions.
int m_stateNum
State Change variable.
void throwUndefinedElements()
Set the behavior when adding a species containing undefined elements to throw an exception.
void setName(const string &nm)
Sets the string name for the phase.
size_t m_mm
Number of elements.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
string elementName(size_t m) const
Name of the element with index m.
double charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
void massFractionsToMoleFractions(const double *Y, double *X) const
Converts a mixture composition from mole fractions to mass fractions.
double entropyElement298(size_t m) const
Entropy of the element in its standard state at 298 K and 1 bar.
virtual void setMoleFractions_NoNorm(const double *const x)
Set the mole fractions to the specified values without normalizing.
vector< double > m_speciesCharge
Vector of species charges. length m_kk.
size_t addElement(const string &symbol, double weight=-12345.0, int atomicNumber=0, double entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element.
string name() const
Return the name of the phase.
void clear()
Clear all cached values.
string toLowerCopy(const string &input)
Convert to lower case.
Composition parseCompString(const string &ss, const vector< string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
double dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
const double Faraday
Faraday constant  [C/kmol].
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
double getElementWeight(const string &ename)
Get the atomic weight of an element.
const double Tiny
Small number to compare differences of mole fractions against.
const double SmallNumber
smallest number to compare to zero.
map< string, double > Composition
Map from string names to doubles.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...