Folded class Constituents into class Phase

This commit is contained in:
Ray Speth 2012-03-09 22:56:11 +00:00
parent e41f43300f
commit 78a093b485
49 changed files with 674 additions and 1141 deletions

View file

@ -144,16 +144,16 @@ private:
};
//! An element index is out of range.
//! An array index is out of range.
/*!
* @ingroup errorhandling
*/
class ElementRangeError : public CanteraError
class IndexError : public CanteraError
{
public:
//! Constructor
/*!
* This class indicates an out-of-bounds index.
* This class indicates an out-of-bounds array index.
*
* @param func String name for the function within which the error was
* generated.
@ -161,12 +161,15 @@ public:
* @param mmax This is the maximum allowed value of the index. The
* minimum allowed value is assumed to be 0.
*/
ElementRangeError(std::string func, size_t m, size_t mmax) :
CanteraError(func), m_(m), mmax_(mmax) {}
IndexError(std::string func, std::string arrayName, size_t m, size_t mmax) :
CanteraError(func), arrayName_(arrayName), m_(m), mmax_(mmax) {}
virtual ~IndexError() throw() {};
virtual std::string getMessage() const;
virtual std::string getClass() const { return "ElementRangeError"; }
virtual std::string getClass() const { return "IndexError"; }
private:
std::string arrayName_;
size_t m_, mmax_;
};

View file

@ -12,7 +12,7 @@
#include "cantera/base/ct_defs.h"
#include "cantera/base/ctexceptions.h"
#include "cantera/base/stringUtils.h"
namespace Cantera
{

View file

@ -1,427 +0,0 @@
/**
* @file Constituents.h
* Header file Class \link Cantera::Constituents Constitutents\endlink which
* manages a set of elements and species (see \ref phases).
*/
// Copyright 2001 California Institute of Technology
#ifndef CT_CONSTIT_H
#define CT_CONSTIT_H
#include "cantera/base/ct_defs.h"
#include "SpeciesThermo.h"
#include "cantera/base/ctexceptions.h"
#include "cantera/base/stringUtils.h"
#include "cantera/base/xml.h"
#include "Elements.h"
namespace Cantera
{
class Elements;
/************** DEFINITIONS OF ERRORS *****************************/
//! Specific fatal error indicating that the index of a species is out of range.
/*!
*
* @ingroup errorhandling
*/
class SpeciesRangeError : public CanteraError
{
public:
//! Constructor
/*!
* @param func Function where the error occurred.
* @param k current species index value
* @param kmax Maximum permissible species index value. The
* minimum permissible species index value is assumed to be 0
*
*/
SpeciesRangeError(std::string func, size_t k, size_t kmax) :
CanteraError(func, "Species index " + int2str(k) +
" outside valid range of 0 to " + int2str(kmax-1)) {}
};
/******************************************************************/
//! Class %Constituents manages a set of elements and species.
/*!
* Class %Constituents is designed to provide information
* about the elements and species in a phase - names, index
* numbers (location in arrays), atomic or molecular weights,
* etc. No computations are performed by the methods of this
* class. The set of elements must include all those that compose
* the species, but may include additional elements. The species
* all must belong to the same phase.
*
* @ingroup phases
*/
class Constituents
{
public:
//! Constructor.
/*!
* Constructor sets all base variable types to zero. Also, it
* sets the pointer to the Elements object for this object.
*
* @param ptr_Elements
* The default is that a new Elements object is created, so this
* Constituents object is independent of any other object. But if
* ptr_Elements is supplied, it will be used. This way, a class
* implementing a multi-phase mixture is responsible for
* maintaining the global elements list for the mixture, and no
* static global element list is required.
*/
Constituents(Elements* ptr_Elements = 0);
/// Destructor.
~Constituents();
/// This copy constructor just calls the assignment operator
/// for this class.
/*!
* @param right reference to the object to be copied.
*/
Constituents(const Constituents& right);
/// Assignment operator
/*!
* @param right Reference to the object to be copied.
*/
Constituents& operator=(const Constituents& right);
/// @name Element Information
// @{
/// Name of the element with index m.
/// This is a passthrough routine to the Element object.
/// \param m Element index.
/// \exception If m < 0 or m >= nElements(), the
/// exception, ElementRangeError, is thrown.
std::string elementName(size_t m) const;
/// Index of element named 'name'.
/// The index is an integer
/// assigned to each element in the order it was added,
/// beginning with 0 for the first element.
/// @param name name of the element
///
/// If 'name' is not
/// the name of an element in the set, then the value -1 is
/// returned.
size_t elementIndex(std::string name) const;
/// Atomic weight of element m.
/*!
* @param m Element index
*/
doublereal atomicWeight(size_t m) const;
/// Entropy of the element in its standard state at 298 K and 1 bar
/*!
* @param m Element index
*/
doublereal entropyElement298(size_t m) const;
/// Atomic number of element m.
/*!
* @param m Element index
*/
int atomicNumber(size_t m) const;
int elementType(size_t m) const;
/// Return a read-only reference to the vector of element names.
const std::vector<std::string>& elementNames() const;
/// Return a read-only reference to the vector of atomic weights.
const vector_fp& atomicWeights() const;
/// Number of elements.
size_t nElements() const;
// @}
/// @name Adding Elements and Species
/// These methods are used to add new elements or species.
/// These are not usually called by user programs.
///
/// Since species are checked to insure that they are only
/// composed of declared elements, it is necessary to first
/// add all elements before adding any species.
//@{
//! Add an element.
/*!
* @param symbol Atomic symbol std::string.
* @param weight Atomic mass in amu.
*/
void addElement(const std::string& symbol, doublereal weight);
//! Add an element from an XML specification.
/*!
* @param e Reference to the XML_Node where the element is described.
*/
void addElement(const XML_Node& e);
//! Add an element, checking for uniqueness
/*!
* The uniqueness is checked by comparing the string symbol. If
* not unique, nothing is done.
*
* @param symbol String symbol of the element
* @param weight Atomic weight of the element (kg kmol-1).
* @param atomicNumber Atomic number of the element (unitless)
* @param entropy298 Entropy of the element at 298 K and 1 bar
* in its most stable form. The default is
* the value ENTROPY298_UNKNOWN, which is
* interpreted as an unknown, and if used
* will cause Cantera to throw an error.
* @param elem_type Specifies the type of the element constraint equation. This defaults
* to CT_ELEM_TYPE_ABSPOS, i.e., an element.
*/
void addUniqueElement(const std::string& symbol, doublereal weight,
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. If
* not unique, nothing is done.
*
* @param e Reference to the XML_Node where the element is described.
*/
void addUniqueElement(const XML_Node& e);
//! Add all elements referenced in an XML_Node tree
/*!
* @param phase Reference to the top XML_Node of a phase
*/
void addElementsFromXML(const XML_Node& phase);
/// Prohibit addition of more elements, and prepare to add species.
void freezeElements();
/// True if freezeElements has been called.
bool elementsFrozen();
//! Add an element after the elements have been frozen, checking for uniqueness
/*!
* The uniqueness is checked by comparing the string symbol. If
* not unique, nothing is done.
*
* @param symbol String symbol of the element
* @param weight Atomic weight of the element (kg kmol-1).
* @param atomicNumber Atomic number of the element (unitless)
* @param entropy298 Entropy of the element at 298 K and 1 bar
* in its most stable form. The default is
* the value ENTROPY298_UNKNOWN, which is
* interpreted as an unknown, and if used
* will cause Cantera to throw an error.
* @param elem_type Specifies the type of the element constraint equation. This defaults
* to CT_ELEM_TYPE_ABSPOS, i.e., an element.
*/
size_t addUniqueElementAfterFreeze(const std::string& symbol, doublereal weight, int atomicNumber,
doublereal entropy298 = ENTROPY298_UNKNOWN, int elem_type = CT_ELEM_TYPE_ABSPOS);
//@}
/// Returns the number of species in the phase
size_t nSpecies() const {
return m_kk;
}
//! Molecular weight of species \c k.
/*!
* @param k index of species \c k
* @return
* Returns the molecular weight of species \c k.
*/
doublereal molecularWeight(size_t k) const;
//! Return the Molar mass of species \c k
/*!
* Preferred name for molecular weight.
*
* @param k index for species
* @return
* Return the molar mass of species k kg/kmol.
*/
doublereal molarMass(size_t k) const {
return molecularWeight(k);
}
/**
* Return a const reference to the vector of molecular weights
* of the species
*/
const vector_fp& molecularWeights() const;
/*!
* Electrical charge of one species k molecule, divided by
* the magnitude of the electron charge ( \f$ e = 1.602
* \times 10^{-19}\f$ Coulombs). Dimensionless.
*
* @param k species index
*/
doublereal charge(size_t k) const;
/**
* @name Adding Species
* These methods are used to add new species.
* They are not usually called by user programs.
*/
//@{
void addSpecies(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 the string name. It only
* adds the species if it is unique.
*
* @param name String name of the species
* @param comp Double vector containing the elemental composition of the
* species.
* @param charge Charge of the species. Defaults to zero.
* @param size Size of the species (meters). Defaults to 1 meter.
*/
void addUniqueSpecies(const std::string& name, const doublereal* comp,
doublereal charge = 0.0,
doublereal size = 1.0);
//! Returns the index of a species named 'name' within the Constituents object
/*!
* The first species in the phase will have an index 0, and the last one in the
* phase will have an index of nSpecies() - 1.
*
* @param name String name of the species
* @return Returns the index of the species. If the name is not found,
* the value of -1 is returned.
*/
size_t speciesIndex(std::string name) const;
//! Name of the species with index k
/*!
* @param k index of the species
*/
std::string speciesName(size_t k) const;
/// Return a const reference to the vector of species names
const std::vector<std::string>& speciesNames() const;
//! This routine returns the size of species k
/*!
* @param k index of the species
* @return
* Returns the size of the species. Units are meters.
*/
doublereal size(size_t k) const {
return m_speciesSize[k];
}
/**
* Prohibit addition of more species, and prepare for
* calculations with this set of elements and species.
*/
void freezeSpecies();
/// True if freezeSpecies has been called.
bool speciesFrozen() {
return m_speciesFrozen;
}
/// Remove all elements and species
void clear();
//@}
/// True if both elements and species have been frozen
bool ready() const;
//! Number of atoms of element \c m in species \c k.
/*!
* @param k species index
* @param m element index
*/
doublereal nAtoms(size_t k, size_t m) const;
//! Get a vector containing the atomic composition of species k
/*!
* @param k species index
* @param atomArray vector containing the atomic number in the species.
* Length: m_mm
*/
void getAtoms(size_t k, double* atomArray) const;
protected:
//! Number of species in the phase.
size_t m_kk;
//! Vector of molecular weights of the species
/*!
* This vector has length m_kk.
* The units of the vector are kg kmol-1.
*/
vector_fp m_weight;
//! Boolean indicating whether the number of species has been frozen.
/*!
* During the construction of the phase, this is false. After
* construction of the the phase, this is true.
*/
bool m_speciesFrozen;
/*!
* Pointer to the element object corresponding to this
* phase. Normally, this will be the default Element object
* common to all phases.
*/
Elements* m_Elements;
//! Vector of the species names
std::vector<std::string> m_speciesNames;
//! Atomic composition of the species.
/*!
* the number of atoms of i in species k is equal to
* m_speciesComp[k * m_mm + i]
* The length of this vector is equal to m_kk * m_mm
*/
vector_fp m_speciesComp;
/**
* m_speciesCharge: Vector of species charges
* length = m_kk
*/
vector_fp m_speciesCharge;
/**
* m_speciesSize(): Vector of species sizes.
* length m_kk
* This is used in some equations of state
* which employ the constant partial molar
* volume approximation. It's so fundamental
* we've put it at the Constituents class level
*/
vector_fp m_speciesSize;
private:
};
} // namespace
#endif

View file

@ -1549,12 +1549,6 @@ protected:
*/
vector_int m_electrolyteSpeciesType;
/**
* Species molar volumes \f$ m^3 kmol^-1 \f$
* -> m_speciesSize in Constituents.h
*/
//vector_fp m_speciesMolarVolume;
/**
* a_k = Size of the ionic species in the DH formulation
* units = meters

View file

@ -90,7 +90,6 @@ class ElementRangeError;
//! Positive number indicating we don't know the gibbs free energy
//! of the element in its most stable state at 298.15 K and 1 bar.
//#define GIBSSFE298_UNKNOWN 123456789.
#define ENTROPY298_UNKNOWN -123456789.
//! Object containing the elements that make up species in a phase.
@ -410,7 +409,7 @@ public:
*/
static std::vector<Elements*> Global_Elements_List;
friend class Constituents;
friend class Phase;
};
} // namespace

View file

@ -2436,12 +2436,6 @@ private:
*/
vector_int m_electrolyteSpeciesType;
/**
* Species molar volumes \f$ m^3 kmol^-1 \f$
* -> m_speciesSize in Constituents.h
*/
//vector_fp m_speciesMolarVolume;
/**
* a_k = Size of the ionic species in the DH formulation
* units = meters

View file

@ -11,13 +11,13 @@
#ifndef CT_PHASE_H
#define CT_PHASE_H
#include "Constituents.h"
#include "cantera/base/vec_functions.h"
#include "cantera/base/ctml.h"
#include "Elements.h"
namespace Cantera
{
class SpeciesThermo;
//! Base class for phases of matter
/*!
@ -55,6 +55,14 @@ namespace Cantera
* may be advantageous as well, and they need to overload these functions
* too.
*
* Class %Constituents is designed to provide information
* about the elements and species in a phase - names, index
* numbers (location in arrays), atomic or molecular weights,
* etc. No computations are performed by the methods of this
* class. The set of elements must include all those that compose
* the species, but may include additional elements. The species
* all must belong to the same phase.
*
* @ingroup phases
*
* Class Phase derives from both classes
@ -111,7 +119,7 @@ namespace Cantera
*
* @ingroup phases
*/
class Phase : public Constituents
class Phase
{
public:
/// Default constructor.
@ -185,6 +193,75 @@ public:
*/
void setName(std::string nm);
/// @name Element Information
// @{
/// Name of the element with index m.
/// This is a passthrough routine to the Element object.
/// \param m Element index.
/// \exception If m < 0 or m >= nElements(), the
/// exception, ElementRangeError, is thrown.
std::string elementName(size_t m) const;
/// Index of element named 'name'.
/// The index is an integer
/// assigned to each element in the order it was added,
/// beginning with 0 for the first element.
/// @param name name of the element
///
/// If 'name' is not
/// the name of an element in the set, then the value -1 is
/// returned.
size_t elementIndex(std::string name) const;
/// Return a read-only reference to the vector of element names.
const std::vector<std::string>& elementNames() const;
/// Atomic weight of element m.
/*!
* @param m Element index
*/
doublereal atomicWeight(size_t m) const;
/// Entropy of the element in its standard state at 298 K and 1 bar
/*!
* @param m Element index
*/
doublereal entropyElement298(size_t m) const;
/// Atomic number of element m.
/*!
* @param m Element index
*/
int atomicNumber(size_t m) const;
int elementType(size_t m) const;
/// Return a read-only reference to the vector of atomic weights.
const vector_fp& atomicWeights() const;
/// Number of elements.
size_t nElements() const;
// @}
//! Number of atoms of element \c m in species \c k.
/*!
* @param k species index
* @param m element index
*/
doublereal nAtoms(size_t k, size_t m) const;
//! Get a vector containing the atomic composition of species k
/*!
* @param k species index
* @param atomArray vector containing the atomic number in the species.
* Length: m_mm
*/
void getAtoms(size_t k, double* atomArray) const;
//! Returns the index of a species named 'name' within the Phase object
/*!
* The first species in the phase will have an index 0, and the last one in the
@ -208,6 +285,12 @@ public:
*/
size_t speciesIndex(std::string name) const;
//! Name of the species with index k
/*!
* @param k index of the species
*/
std::string speciesName(size_t k) const;
//! Returns the expanded species name of a species, including the phase name
/*!
* Returns the expanded phase name species name string.
@ -218,6 +301,14 @@ public:
*/
std::string speciesSPName(int k) const;
/// Return a const reference to the vector of species names
const std::vector<std::string>& speciesNames() const;
/// Returns the number of species in the phase
size_t nSpecies() const {
return m_kk;
}
//! Save the current internal state of the phase
/*!
* Write to vector 'state' the current internal state.
@ -370,6 +461,25 @@ public:
*/
void setState_RY(doublereal rho, doublereal* y);
//! Molecular weight of species \c k.
/*!
* @param k index of species \c k
* @return Returns the molecular weight of species \c k.
*/
doublereal molecularWeight(size_t k) const;
//! Return the Molar mass of species \c k
/*!
* Alternate name for molecular weight.
*
* @param k index for species
* @return Return the molar mass of species k kg/kmol.
* @deprecated use molecularWeight instead
*/
doublereal molarMass(size_t k) const {
return molecularWeight(k);
}
/**
* Copy the vector of molecular weights into vector weights.
*
@ -396,9 +506,20 @@ public:
/**
* Return a const reference to the internal vector of molecular weights.
* units = kg / kmol
*/
const vector_fp& molecularWeights() const;
//! This routine returns the size of species k
/*!
* @param k index of the species
* @return
* Returns the size of the species. Units are meters.
*/
doublereal size(size_t k) const {
return m_speciesSize[k];
}
/**
* Get the mole fractions by name.
*
@ -551,6 +672,14 @@ public:
//@}
/*!
* Electrical charge of one species k molecule, divided by
* the magnitude of the electron charge ( \f$ e = 1.602
* \times 10^{-19}\f$ Coulombs). Dimensionless.
*
* @param k species index
*/
doublereal charge(size_t k) const;
/**
* Charge density [C/m^3].
@ -680,14 +809,131 @@ public:
doublereal sum_xlogQ(doublereal* const Q) const;
//@}
/// @name Adding Elements and Species
/// These methods are used to add new elements or species.
/// These are not usually called by user programs.
///
/// Since species are checked to insure that they are only
/// composed of declared elements, it is necessary to first
/// add all elements before adding any species.
//@{
//! Add an element.
/*!
* @param symbol Atomic symbol std::string.
* @param weight Atomic mass in amu.
*/
void addElement(const std::string& symbol, doublereal weight);
//! Add an element from an XML specification.
/*!
* @param e Reference to the XML_Node where the element is described.
*/
void addElement(const XML_Node& e);
//! Add an element, checking for uniqueness
/*!
* The uniqueness is checked by comparing the string symbol. If
* not unique, nothing is done.
*
* @param symbol String symbol of the element
* @param weight Atomic weight of the element (kg kmol-1).
* @param atomicNumber Atomic number of the element (unitless)
* @param entropy298 Entropy of the element at 298 K and 1 bar
* in its most stable form. The default is
* the value ENTROPY298_UNKNOWN, which is
* interpreted as an unknown, and if used
* will cause Cantera to throw an error.
* @param elem_type Specifies the type of the element constraint equation. This defaults
* to CT_ELEM_TYPE_ABSPOS, i.e., an element.
*/
void addUniqueElement(const std::string& symbol, doublereal weight,
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. If
* not unique, nothing is done.
*
* @param e Reference to the XML_Node where the element is described.
*/
void addUniqueElement(const XML_Node& e);
//! Add all elements referenced in an XML_Node tree
/*!
* @param phase Reference to the top XML_Node of a phase
*/
void addElementsFromXML(const XML_Node& phase);
/// Prohibit addition of more elements, and prepare to add species.
void freezeElements();
/// True if freezeElements has been called.
bool elementsFrozen();
//! Add an element after the elements have been frozen, checking for uniqueness
/*!
* The uniqueness is checked by comparing the string symbol. If
* not unique, nothing is done.
*
* @param symbol String symbol of the element
* @param weight Atomic weight of the element (kg kmol-1).
* @param atomicNumber Atomic number of the element (unitless)
* @param entropy298 Entropy of the element at 298 K and 1 bar
* in its most stable form. The default is
* the value ENTROPY298_UNKNOWN, which is
* interpreted as an unknown, and if used
* will cause Cantera to throw an error.
* @param elem_type Specifies the type of the element constraint equation. This defaults
* to CT_ELEM_TYPE_ABSPOS, i.e., an element.
*/
size_t addUniqueElementAfterFreeze(const std::string& symbol, doublereal weight, int atomicNumber,
doublereal entropy298 = ENTROPY298_UNKNOWN, int elem_type = CT_ELEM_TYPE_ABSPOS);
//@}
/**
* @name Adding Species
* These methods are used to add new species.
* They are not usually called by user programs.
*/
//@{
void addSpecies(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 the string name. It only
* adds the species if it is unique.
*
* @param name String name of the species
* @param comp Double vector containing the elemental composition of the
* species.
* @param charge Charge of the species. Defaults to zero.
* @param size Size of the species (meters). Defaults to 1 meter.
*/
void addUniqueSpecies(const std::string& name, const doublereal* comp,
doublereal charge = 0.0,
doublereal size = 1.0);
//@}
/**
* Finished adding species, prepare to use them for calculation
* of mixture properties.
*/
virtual void freezeSpecies();
/// True if freezeSpecies has been called.
bool speciesFrozen() {
return m_speciesFrozen;
}
virtual bool ready() const;
/// Remove all elements and species
void clear();
//! Return the State Mole Fraction Number
DEPRECATED(int stateMFNumber() const) {
return m_stateNum;
@ -740,6 +986,29 @@ protected:
*/
size_t m_ndim;
//! Atomic composition of the species.
/*!
* the number of atoms of i in species k is equal to
* m_speciesComp[k * m_mm + i]
* The length of this vector is equal to m_kk * m_mm
*/
vector_fp m_speciesComp;
/**
* m_speciesSize(): Vector of species sizes.
* length m_kk
* This is used in some equations of state
* which employ the constant partial molar
* volume approximation. It's so fundamental
* we've put it at the Constituents class level
*/
vector_fp m_speciesSize;
/**
* m_speciesCharge: Vector of species charges
* length = m_kk
*/
vector_fp m_speciesCharge;
private:
//! This stores the initial state of the system
@ -824,6 +1093,23 @@ private:
* @deprecated
*/
int m_stateNum;
//! Boolean indicating whether the number of species has been frozen.
/*!
* During the construction of the phase, this is false. After
* construction of the the phase, this is true.
*/
bool m_speciesFrozen;
/*!
* Pointer to the element object corresponding to this
* phase. Normally, this will be the default Element object
* common to all phases.
*/
Elements* m_Elements;
//! Vector of the species names
std::vector<std::string> m_speciesNames;
};
//! typedef for the base Phase class

View file

@ -12,7 +12,7 @@
#define CT_THERMOPHASE_H
#include "Phase.h"
#include "SpeciesThermo.h"
namespace Cantera
{

View file

@ -13,6 +13,9 @@
* U.S. Government retains certain rights in this software.
*/
//! @deprecated remove include when UnknownVPSSMgr is removed
#include "cantera/base/stringUtils.h"
#ifndef VPSSMGR_TYPES_H
#define VPSSMGR_TYPES_H

View file

@ -58,9 +58,10 @@ std::string ArraySizeError::getMessage() const {
return ss.str();
}
std::string ElementRangeError::getMessage() const {
std::string IndexError::getMessage() const {
std::stringstream ss;
ss << "Element index " << m_ << " outside valid range of 0 to " << (mmax_-1) << ".";
ss << "IndexError: " << arrayName_ << "[" << m_ << "]" <<
" outside valid range of 0 to " << (mmax_-1) << ".";
return ss.str();
}

View file

@ -7,11 +7,12 @@
#include "cantera/thermo/MolalityVPSSTP.h"
#endif
#include "cantera/base/global.h"
#include "cantera/base/stringUtils.h"
#include <math.h>
#include <iostream>
using namespace std;
using namespace std;
namespace Cantera
{

View file

@ -14,6 +14,7 @@
#include "cantera/kinetics/AqueousKinetics.h"
#include "ReactionData.h"
#include "cantera/kinetics/RateCoeffMgr.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;

View file

@ -1,590 +0,0 @@
/**
* @file Constituents.cpp
* Header file Class \link Cantera::Constituents Constitutents\endlink which
* manages a set of elements and species (see \ref phases).
*/
// Copyright 2001 California Institute of Technology
#include "cantera/thermo/Constituents.h"
#include "cantera/thermo/Elements.h"
using namespace std;
namespace Cantera
{
/*
* Constructor sets all base variable types to zero. Also, it
* sets the pointer to the Elements object for this object to the
* default value of BaseElements. If the BaseElements Elements
* object doesn't exist, it creates it.
*
* Input
* --------
* ptr_Elements: If the Constituents object requires a different
* Elements object than the default one, input
* address here. This argument defaults to null,
* in which case the default Elements Object is
* chosen.
*/
/*
* DGG: I have reversed the role of ptr_Elements. In this version,
* the default is that a new Elements object is created, so this
* Constituents object is independent of any other object. But if
* ptr_Elements is supplied, it will be used. This way, a class
* implementing a multi-phase mixture is responsible for
* maintaining the global elements list for the mixture, and no
* static global element list is required.
*/
Constituents::Constituents(Elements* ptr_Elements) :
m_kk(0),
m_speciesFrozen(false) ,
m_Elements(ptr_Elements)
{
if (!m_Elements) {
m_Elements = new Elements();
}
// Register subscription to Elements object whether or not we
// created it here.
m_Elements->subscribe();
}
/**
* Destructor for class Constituents.
*
* Some cleanup of of the Global_Elements_List array is
* effected by unsubscribing to m_Elements.
*/
Constituents::~Constituents()
{
int ileft = m_Elements->unsubscribe();
/*
* Here we may delete Elements Objects or not. Right now, we
* will delete them. We also delete the global pointer entry
* to keep everything consistent.
*/
if (ileft <= 0) {
vector<Elements*>::iterator it;
for (it = Elements::Global_Elements_List.begin();
it != Elements::Global_Elements_List.end(); ++it) {
if (*it == m_Elements) {
Elements::Global_Elements_List.erase(it);
break;
}
}
delete m_Elements;
}
}
size_t Constituents::nElements() const
{
return m_Elements->nElements();
}
/*
* Return the Atomic weight of element m.
* units = Kg / Kmol
*/
doublereal Constituents::atomicWeight(size_t m) const
{
return m_Elements->atomicWeight(m);
}
doublereal Constituents::entropyElement298(size_t m) const
{
return m_Elements->entropyElement298(m);
}
/*
* returns a reference to the vector of atomic weights pertinent
* to this constituents object
* units = kg / Kmol
*/
const vector_fp& Constituents::atomicWeights() const
{
return m_Elements->atomicWeights();
}
/*
* Return the atomic number of element m.
*/
int Constituents::atomicNumber(size_t m) const
{
return m_Elements->atomicNumber(m);
}
int Constituents::elementType(size_t m) const
{
return m_Elements->elementType(m);
}
/*
* Add an element to the set.
* @param symbol symbol string
* @param weight atomic weight in kg/mol.
*
* If weight is not given, then a lookup is performed in the
* element object
*
*/
void Constituents::
addElement(const std::string& symbol, doublereal weight)
{
m_Elements->addElement(symbol, weight);
}
void Constituents::
addElement(const XML_Node& e)
{
m_Elements->addElement(e);
}
/*
* Add a unique element to the set. A check on the symbol is made
* If the symbol is already an element, then a new element is
* not created.
*
* @param symbol symbol string
* @param weight atomic weight in kg/mol.
*
* If weight is not given, then a lookup is performed in the
* element object
*
* -> Passthrough to the Element lvl.
*/
void Constituents::
addUniqueElement(const std::string& symbol, doublereal weight,
int atomicNumber, doublereal entropy298, int elem_type)
{
m_Elements->addUniqueElement(symbol, weight, atomicNumber, entropy298, elem_type);
}
void Constituents::
addUniqueElement(const XML_Node& e)
{
m_Elements->addUniqueElement(e);
}
void Constituents::addElementsFromXML(const XML_Node& phase)
{
m_Elements->addElementsFromXML(phase);
}
/*
* -> Passthrough to the Element lvl.
*/
void Constituents::freezeElements()
{
m_Elements->freezeElements();
}
/*
* -> Passthrough to the Element lvl.
*/
bool Constituents::elementsFrozen()
{
return m_Elements->elementsFrozen();
}
/*
* Index of element named \a name. The index is an integer
* assigned to each element in the order it was added,
* beginning with 0 for the first element. If \a name is not
* the name of an element in the set, then the value -1 is
* returned.
*
*
* -> Passthrough to the Element class.
*/
size_t Constituents::elementIndex(std::string name) const
{
return (m_Elements->elementIndex(name));
}
/*
* Name of the element with index m.
*
* This is a passthrough routine to the Element object.
* @param m @{ Element index. @}
* \exception If m < 0 or m >= nElements(), the
* exception, ElementRangeError, is thrown.
*/
string Constituents::elementName(size_t m) const
{
return (m_Elements->elementName(m));
}
/*******************************************************************
*
* elementNames():
*
* Returns a read-only reference to the vector of element names.
* @code
* Constituents c;
* ...
* const vector<string>& enames = c.elementNames();
* int n = enames.size();
* for (int i = 0; i < n; i++) cout << enames[i] << endl;
* @endcode
*
*
* -> Passthrough to the Element lvl.
*/
const vector<string>& Constituents::elementNames() const
{
return m_Elements->elementNames();
}
/*
* molecularWeight()
*
* Returns the molecular weight of a species given the species index
*
* units = kg / kmol.
*/
doublereal Constituents::molecularWeight(size_t k) const
{
if (k >= nSpecies()) {
throw SpeciesRangeError("Constituents::molecularWeight",
k, nSpecies());
}
return m_weight[k];
}
/*
* molecularWeights()
*
* Returns a const reference to the vector of molecular weights
* for all of the species defined in the object.
*
* units = kg / kmol.
*/
const vector_fp& Constituents::molecularWeights() const
{
return m_weight;
}
/*
* charge():
*
* Electrical charge of one species k molecule, divided by
* \f$ e = 1.602 \times 10^{-19}\f$ Coulombs.
*/
doublereal Constituents::charge(size_t k) const
{
return m_speciesCharge[k];
}
/*
* addSpecies()
*
* Add a species to a Constituents object. Note, no check is made
* as to whether the species has a unique name.
*
* Input
* ---------
* name = string containing the name
* comp[]
* charge =
* weight = weight of the species. Default = 0.0.
* Note, the weight is a bit redundent and potentially
* harmful. If weight is less than or equal to zero,
* the weight is calculated from the element composition
* and it need not be supplied on the command line.
*/
void Constituents::
addSpecies(const std::string& name, const doublereal* comp,
doublereal charge, doublereal size)
{
m_Elements->freezeElements();
m_speciesNames.push_back(name);
m_speciesCharge.push_back(charge);
m_speciesSize.push_back(size);
size_t ne = m_Elements->nElements();
// Create a changeable copy of the element composition. We now change the charge potentially
vector_fp compNew(ne);
for (size_t m = 0; m < ne; m++) {
compNew[m] = comp[m];
}
double wt = 0.0;
const vector_fp& aw = m_Elements->atomicWeights();
if (charge != 0.0) {
size_t eindex = m_Elements->elementIndex("E");
if (eindex != npos) {
doublereal ecomp = compNew[eindex];
if (fabs(charge + ecomp) > 0.001) {
if (ecomp != 0.0) {
throw CanteraError("Constituents::addSpecies",
"Input charge and element E compositions differ for species " + name);
} else {
// Just fix up the element E composition based on the input species charge
compNew[eindex] = -charge;
}
}
} else {
addUniqueElementAfterFreeze("E", 0.000545, 0, 0.0, CT_ELEM_TYPE_ELECTRONCHARGE);
ne = m_Elements->nElements();
eindex = m_Elements->elementIndex("E");
compNew.resize(ne);
compNew[ne - 1] = - charge;
//comp[eindex] = -charge;
// throw CanteraError("Constituents::addSpecies",
// "Element List doesn't include E, yet this species has charge:" + name);
}
}
for (size_t m = 0; m < ne; m++) {
m_speciesComp.push_back(compNew[m]);
wt += compNew[m] * aw[m];
}
m_weight.push_back(wt);
m_kk++;
}
/*
*
* addUniqueSpecies():
*
* Add a species to a Constituents object. This routine will
* first check to see if the species is already part of the
* phase. It does this via a string comparison with the
* existing species in the phase.
*/
void Constituents::
addUniqueSpecies(const std::string& name, const doublereal* comp,
doublereal charge, doublereal size)
{
vector<string>::const_iterator it = m_speciesNames.begin();
for (size_t k = 0; k < m_kk; k++) {
if (*it == name) {
/*
* We have found a match. At this point we could do some
* compatibility checks. However, let's just return for the
* moment without specifying any error.
*/
size_t m_mm = m_Elements->nElements();
for (size_t i = 0; i < m_mm; i++) {
if (comp[i] != m_speciesComp[m_kk * m_mm + i]) {
throw CanteraError("addUniqueSpecies",
"Duplicate species have different "
"compositions: " + *it);
}
}
if (charge != m_speciesCharge[m_kk]) {
throw CanteraError("addUniqueSpecies",
"Duplicate species have different "
"charges: " + *it);
}
if (size != m_speciesSize[m_kk]) {
throw CanteraError("addUniqueSpecies",
"Duplicate species have different "
"sizes: " + *it);
}
return;
}
++it;
}
addSpecies(name, comp, charge, size);
}
/*
*
* freezeSpecies()
* Set the boolean indicating that we are no longer allowing
* species to be added to the Constituents class object.
*/
void Constituents::freezeSpecies()
{
m_speciesFrozen = true;
}
/*
*
* speciesIndex()
*
* Index of species named \c name. The first species added
* will have index 0, and the last one index nSpecies() - 1.
*
* Note, the [] operator shouldn't be used for map's because it
* creates new entries. Here, we use find() to look up entries.
*
* If name isn't in the list, then a -1 is returned.
*/
size_t Constituents::speciesIndex(std::string name) const
{
vector<string>::const_iterator it = m_speciesNames.begin();
for (size_t k = 0; k < m_kk; k++) {
if (*it == name) {
/*
* We have found a match.
*/
return k;
}
++it;
}
return npos;
}
/*
*
* speciesName()
*
* Name of the species with index k
*/
string Constituents::speciesName(size_t k) const
{
if (k >= nSpecies())
throw SpeciesRangeError("Constituents::speciesName",
k, nSpecies());
return m_speciesNames[k];
}
/*
*
* speciesNames()
*
* Return a const reference to the vector of species names
*/
const vector<string>& Constituents::speciesNames() const
{
return m_speciesNames;
}
/*
*
* ready():
* True if both elements and species have been frozen
*/
bool Constituents::ready() const
{
return (m_Elements->elementsFrozen() && m_speciesFrozen);
}
/*
* Returns the number of atoms of element \c m in species \c k.
*/
doublereal Constituents::nAtoms(size_t k, size_t m) const
{
const size_t m_mm = m_Elements->nElements();
if (m >= m_mm) {
throw ElementRangeError("Constituents::nAtoms",m,nElements());
}
if (k >= nSpecies()) {
throw SpeciesRangeError("Constituents::nAtoms",k,nSpecies());
}
return m_speciesComp[m_mm * k + m];
}
//====================================================================================================================
/*
*
* getAtoms()
*
* Get a vector containing the atomic composition
* of species k
*/
void Constituents::getAtoms(size_t k, double* atomArray) const
{
const size_t m_mm = m_Elements->nElements();
for (size_t m = 0; m < m_mm; m++) {
atomArray[m] = (double) m_speciesComp[m_mm * k + m];
}
}
//====================================================================================================================
size_t Constituents::addUniqueElementAfterFreeze(const std::string& symbol, doublereal weight, int atomicNumber,
doublereal entropy298, int elem_type)
{
size_t ii = elementIndex(symbol);
if (ii != npos) {
return ii;
}
// Check to see that the element isn't really in the list
m_Elements->m_elementsFrozen = false;
addUniqueElement(symbol, weight, atomicNumber, entropy298, elem_type);
m_Elements->m_elementsFrozen = true;
size_t m_mm = m_Elements->nElements();
ii = elementIndex(symbol);
if (ii != m_mm-1) {
throw CanteraError("Constituents::addElementAfterFreeze()", "confused");
}
if (m_kk > 0) {
vector_fp old(m_speciesComp);
m_speciesComp.resize(m_kk*m_mm, 0.0);
for (size_t k = 0; k < m_kk; k++) {
size_t m_old = m_mm - 1;
for (size_t m = 0; m < m_old; m++) {
m_speciesComp[k * m_mm + m] = old[k * (m_old) + m];
}
m_speciesComp[k * (m_mm) + (m_mm-1)] = 0.0;
}
}
return ii;
}
//====================================================================================================================
/*
* This copy constructor just calls the assignment operator
* for this class.
* The assignment operator does a deep copy.
*/
Constituents::Constituents(const Constituents& right) :
m_kk(0),
m_speciesFrozen(false),
m_Elements(0)
{
*this = right;
}
/*
* Assignment operator for the Constituents class.
* Right now we pretty much do a straight uncomplicated
* copy of all of the protected data.
*/
Constituents& Constituents::operator=(const Constituents& right)
{
/*
* Check for self assignment.
*/
if (this == &right) {
return *this;
}
/*
* We do a straight assignment operator on all of the
* data. The vectors are copied.
*/
m_kk = right.m_kk;
m_weight = right.m_weight;
m_speciesFrozen = right.m_speciesFrozen;
if (m_Elements) {
int nleft = m_Elements->unsubscribe();
if (nleft <= 0) {
vector<Elements*>::iterator it;
for (it = Elements::Global_Elements_List.begin();
it != Elements::Global_Elements_List.end(); ++it) {
if (*it == m_Elements) {
Elements::Global_Elements_List.erase(it);
break;
}
}
delete m_Elements;
}
}
m_Elements = right.m_Elements;
if (m_Elements) {
m_Elements->subscribe();
}
m_speciesNames = right.m_speciesNames;
m_speciesComp = right.m_speciesComp;
m_speciesCharge = right.m_speciesCharge;
m_speciesSize = right.m_speciesSize;
/*
* Return the reference to the current object
*/
return *this;
}
}

View file

@ -17,6 +17,9 @@
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/PDSS_Water.h"
#include "cantera/base/stringUtils.h"
#include <cstring>
#include <cstdlib>

View file

@ -323,7 +323,8 @@ size_t Elements::elementIndex(std::string name) const
string Elements::elementName(size_t m) const
{
if (m >= nElements()) {
throw ElementRangeError("Elements::elementName", m, nElements());
throw IndexError("Elements::elementName", "m_elementNames",
m, nElements());
}
return m_elementNames[m];
}

View file

@ -17,7 +17,10 @@
* U.S. Government retains certain rights in this software.
*/
#include "cantera/thermo/GibbsExcessVPSSTP.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;
namespace Cantera

View file

@ -22,6 +22,7 @@
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/PDSS_Water.h"
#include "cantera/base/stringUtils.h"
#include <cmath>
#include <cstdlib>
@ -2445,7 +2446,7 @@ s_updatePitzer_lnMolalityActCoeff() const
*/
const double* molality = DATA_PTR(m_molalitiesCropped);
/*
* These are the charges of the species accessed from Constituents.h
* These are the charges of the species accessed from class Phase
*/
const double* charge = DATA_PTR(m_speciesCharge);

View file

@ -16,6 +16,8 @@
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/PDSS_Water.h"
#include "cantera/base/stringUtils.h"
#include <cstring>
#include <cstdlib>

View file

@ -11,7 +11,10 @@
*/
#include "cantera/thermo/IdealSolidSolnPhase.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;
namespace Cantera

View file

@ -17,6 +17,7 @@
#include "cantera/thermo/PDSS.h"
#include "cantera/thermo/mix_defs.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
using namespace std;

View file

@ -18,9 +18,9 @@
*/
#include "cantera/thermo/IonsFromNeutralVPSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/PDSS_IonsFromNeutral.h"
#include "cantera/thermo/mix_defs.h"
#include "cantera/base/stringUtils.h"
#include <cmath>
#include <iomanip>

View file

@ -15,6 +15,7 @@
#include "cantera/thermo/LatticePhase.h"
#include "cantera/thermo/SpeciesThermo.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
#include <cmath>

View file

@ -13,6 +13,8 @@
*/
#include "cantera/thermo/MargulesVPSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;

View file

@ -11,14 +11,11 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
/*
* $Date: 2011-04-14 12:24:13 -0600 (Thu, 14 Apr 2011) $
* $Revision: 713 $
*/
#include "cantera/thermo/MixedSolventElectrolyte.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;

View file

@ -10,23 +10,16 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
/*
* $Author: hkmoffa $
* $Date: 2010-01-17 12:08:00 -0700 (Sun, 17 Jan 2010) $
* $Revision: 388 $
*/
#include "cantera/thermo/MixtureFugacityTP.h"
#include "cantera/thermo/VPSSMgr.h"
#include "cantera/thermo/PDSS.h"
#include "cantera/base/stringUtils.h"
using namespace std;
namespace Cantera
{
//====================================================================================================================
/*
* Default constructor

View file

@ -17,7 +17,10 @@
* U.S. Government retains certain rights in this software.
*/
#include "cantera/thermo/MolalityVPSSTP.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;
namespace Cantera

View file

@ -16,14 +16,10 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
/*
* $Date: 2009-11-09 16:36:49 -0700 (Mon, 09 Nov 2009) $
* $Revision: 255 $
*/
#include "cantera/thermo/MolarityIonicVPSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
#include <cmath>
using namespace std;

View file

@ -15,6 +15,7 @@
#include "cantera/thermo/PDSS_HKFT.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/PDSS_Water.h"
#include "cantera/base/stringUtils.h"
#include <cstdlib>

View file

@ -8,14 +8,15 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
#include "cantera/base/ct_defs.h"
#include "cantera/base/xml.h"
#include "cantera/base/ctml.h"
#include "cantera/thermo/PDSS_IonsFromNeutral.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/IonsFromNeutralVPSSTP.h"
#include "cantera/thermo/VPStandardStateTP.h"
#include "cantera/base/stringUtils.h"
#include "cantera/base/ct_defs.h"
#include "cantera/base/xml.h"
#include "cantera/base/ctml.h"
using namespace std;

View file

@ -17,6 +17,7 @@
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/VPStandardStateTP.h"
#include "cantera/base/stringUtils.h"
#include <cmath>

View file

@ -7,10 +7,10 @@
// Copyright 2001 California Institute of Technology
#include "cantera/base/ct_defs.h"
#include "cantera/thermo/Phase.h"
#include "cantera/base/vec_functions.h"
#include "cantera/base/ctexceptions.h"
#include "cantera/base/stringUtils.h"
using namespace std;
@ -18,7 +18,6 @@ namespace Cantera
{
Phase::Phase() :
Constituents(),
m_kk(0),
m_ndim(3),
m_xml(new XML_Node("phase")),
@ -27,8 +26,11 @@ Phase::Phase() :
m_temp(0.0),
m_dens(0.001),
m_mmw(0.0),
m_stateNum(-1)
m_stateNum(-1),
m_speciesFrozen(false) ,
m_Elements(new Elements())
{
m_Elements->subscribe();
}
/*
@ -38,7 +40,6 @@ Phase::Phase() :
* then calls the assignment operator.
*/
Phase::Phase(const Phase& right) :
Constituents(),
m_kk(0),
m_ndim(3),
m_xml(new XML_Node("phase")),
@ -47,7 +48,9 @@ Phase::Phase(const Phase& right) :
m_temp(0.0),
m_dens(0.001),
m_mmw(0.0),
m_stateNum(-1)
m_stateNum(-1),
m_speciesFrozen(false) ,
m_Elements(0)
{
/*
* Call the assignment operator.
@ -55,30 +58,14 @@ Phase::Phase(const Phase& right) :
*this = operator=(right);
}
/*
* Assignment operator
*
* This operation is sort of complicated. We have to
* call the assignment operator for the Constituents and
* State operators that Phase inherits from. Then,
* we have to copy our own data, making sure to do a
* deep copy on the XML_Node data owned by this object.
*/
Phase& Phase::operator=(const Phase& right)
{
/*
* Check for self assignment.
*/
// Check for self assignment.
if (this == &right) {
return *this;
}
/*
* Now call the inherited-classes assignment operators.
*/
(void) Constituents::operator=(right);
/*
* Handle its own data
*/
// Handle our own data
m_kk = right.m_kk;
m_ndim = right.m_ndim;
m_data = right.m_data;
@ -90,6 +77,29 @@ Phase& Phase::operator=(const Phase& right)
m_molwts = right.m_molwts;
m_rmolwts = right.m_rmolwts;
m_stateNum = -1;
m_speciesFrozen = right.m_speciesFrozen;
if (m_Elements) {
int nleft = m_Elements->unsubscribe();
if (nleft <= 0) {
vector<Elements*>::iterator it;
for (it = Elements::Global_Elements_List.begin();
it != Elements::Global_Elements_List.end(); ++it) {
if (*it == m_Elements) {
Elements::Global_Elements_List.erase(it);
break;
}
}
delete m_Elements;
}
}
m_Elements = right.m_Elements;
if (m_Elements) {
m_Elements->subscribe();
}
m_speciesNames = right.m_speciesNames;
m_speciesComp = right.m_speciesComp;
m_speciesCharge = right.m_speciesCharge;
m_speciesSize = right.m_speciesSize;
/*
* This is a little complicated. -> Because we delete m_xml
@ -118,6 +128,24 @@ Phase::~Phase()
delete m_xml;
m_xml = 0;
}
int ileft = m_Elements->unsubscribe();
/*
* Here we may delete Elements Objects or not. Right now, we
* will delete them. We also delete the global pointer entry
* to keep everything consistent.
*/
if (ileft <= 0) {
vector<Elements*>::iterator it;
for (it = Elements::Global_Elements_List.begin();
it != Elements::Global_Elements_List.end(); ++it) {
if (*it == m_Elements) {
Elements::Global_Elements_List.erase(it);
break;
}
}
delete m_Elements;
}
}
inline void Phase::stateMFChangeCalc(bool forcerChange)
@ -155,6 +183,71 @@ void Phase::setName(std::string nm)
m_name = nm;
}
size_t Phase::nElements() const
{
return m_Elements->nElements();
}
string Phase::elementName(size_t m) const
{
return m_Elements->elementName(m);
}
size_t Phase::elementIndex(std::string name) const
{
return m_Elements->elementIndex(name);
}
const vector<string>& Phase::elementNames() const
{
return m_Elements->elementNames();
}
doublereal Phase::atomicWeight(size_t m) const
{
return m_Elements->atomicWeight(m);
}
doublereal Phase::entropyElement298(size_t m) const
{
return m_Elements->entropyElement298(m);
}
const vector_fp& Phase::atomicWeights() const
{
return m_Elements->atomicWeights();
}
int Phase::atomicNumber(size_t m) const
{
return m_Elements->atomicNumber(m);
}
int Phase::elementType(size_t m) const
{
return m_Elements->elementType(m);
}
doublereal Phase::nAtoms(size_t k, size_t m) const
{
const size_t m_mm = m_Elements->nElements();
if (m >= m_mm) {
throw IndexError("Phase::nAtoms", "", m, nElements());
}
if (k >= nSpecies()) {
throw IndexError("Phase::nAtoms", "", k, nSpecies());
}
return m_speciesComp[m_mm * k + m];
}
void Phase::getAtoms(size_t k, double* atomArray) const
{
const size_t m_mm = m_Elements->nElements();
for (size_t m = 0; m < m_mm; m++) {
atomArray[m] = (double) m_speciesComp[m_mm * k + m];
}
}
// Returns the index of a species named 'name' within the Phase object
/*
* The first species in the phase will have an index 0, and the last one in the
@ -181,14 +274,33 @@ size_t Phase::speciesIndex(std::string nameStr) const
std::string pn;
std::string sn = parseSpeciesName(nameStr, pn);
if (pn == "" || pn == m_name || pn == m_id) {
return Constituents::speciesIndex(sn);
vector<string>::const_iterator it = m_speciesNames.begin();
for (size_t k = 0; k < m_kk; k++) {
if (*it == sn) {
return k;
}
++it;
}
return npos;
}
return npos;
}
string Phase::speciesName(size_t k) const
{
if (k >= nSpecies())
throw IndexError("Phase::speciesName", "m_speciesNames", k, nSpecies());
return m_speciesNames[k];
}
const vector<string>& Phase::speciesNames() const
{
return m_speciesNames;
}
std::string Phase::speciesSPName(int k) const
{
std::string sn = Constituents::speciesName(k);
std::string sn = speciesName(k);
return(m_name + ":" + sn);
}
@ -405,12 +517,20 @@ void Phase::setState_RY(doublereal rho, doublereal* y)
setDensity(rho);
}
doublereal Phase::molecularWeight(size_t k) const
{
if (k >= nSpecies()) {
throw IndexError("Phase::molecularWeight", "m_weight", k, nSpecies());
}
return m_molwts[k];
}
/*
* Copy the vector of molecular weights into vector weights.
*/
void Phase::getMolecularWeights(vector_fp& weights) const
{
const vector_fp& mw = Constituents::molecularWeights();
const vector_fp& mw = molecularWeights();
if (weights.size() < mw.size()) {
weights.resize(mw.size());
}
@ -423,29 +543,21 @@ void Phase::getMolecularWeights(vector_fp& weights) const
*/
void Phase::getMolecularWeights(int iwt, doublereal* weights) const
{
const vector_fp& mw = Constituents::molecularWeights();
const vector_fp& mw = molecularWeights();
copy(mw.begin(), mw.end(), weights);
}
/*
* Copy the vector of molecular weights into array weights.
*/
void Phase::getMolecularWeights(doublereal* weights) const
{
const vector_fp& mw = Constituents::molecularWeights();
const vector_fp& mw = molecularWeights();
copy(mw.begin(), mw.end(), weights);
}
/**
* Return a const reference to the internal vector of
* molecular weights.
*/
const vector_fp& Phase::molecularWeights() const
{
return Constituents::molecularWeights();
return m_molwts;
}
/**
* Get the mole fractions by name.
*/
@ -561,6 +673,11 @@ doublereal Phase::molarVolume() const
return 1.0/molarDensity();
}
doublereal Phase::charge(size_t k) const
{
return m_speciesCharge[k];
}
doublereal Phase::chargeDensity() const
{
size_t kk = nSpecies();
@ -592,28 +709,168 @@ doublereal Phase::sum_xlogQ(doublereal* Q) const
return m_mmw * Cantera::sum_xlogQ(m_ym.begin(), m_ym.end(), Q);
}
/**
* Finished adding species, prepare to use them for calculation
* of mixture properties.
*/
void Phase::addElement(const std::string& symbol, doublereal weight)
{
m_Elements->addElement(symbol, weight);
}
void Phase::addElement(const XML_Node& e)
{
m_Elements->addElement(e);
}
void Phase::addUniqueElement(const std::string& symbol, doublereal weight,
int atomicNumber, doublereal entropy298, int elem_type)
{
m_Elements->addUniqueElement(symbol, weight, atomicNumber, entropy298, elem_type);
}
void Phase::addUniqueElement(const XML_Node& e)
{
m_Elements->addUniqueElement(e);
}
void Phase::addElementsFromXML(const XML_Node& phase)
{
m_Elements->addElementsFromXML(phase);
}
void Phase::freezeElements()
{
m_Elements->freezeElements();
}
bool Phase::elementsFrozen()
{
return m_Elements->elementsFrozen();
}
size_t Phase::addUniqueElementAfterFreeze(const std::string& symbol, doublereal weight, int atomicNumber,
doublereal entropy298, int elem_type)
{
size_t ii = elementIndex(symbol);
if (ii != npos) {
return ii;
}
// Check to see that the element isn't really in the list
m_Elements->m_elementsFrozen = false;
addUniqueElement(symbol, weight, atomicNumber, entropy298, elem_type);
m_Elements->m_elementsFrozen = true;
size_t m_mm = m_Elements->nElements();
ii = elementIndex(symbol);
if (ii != m_mm-1) {
throw CanteraError("Phase::addElementAfterFreeze()", "confused");
}
if (m_kk > 0) {
vector_fp old(m_speciesComp);
m_speciesComp.resize(m_kk*m_mm, 0.0);
for (size_t k = 0; k < m_kk; k++) {
size_t m_old = m_mm - 1;
for (size_t m = 0; m < m_old; m++) {
m_speciesComp[k * m_mm + m] = old[k * (m_old) + m];
}
m_speciesComp[k * (m_mm) + (m_mm-1)] = 0.0;
}
}
return ii;
}
void Phase::addSpecies(const std::string& name, const doublereal* comp,
doublereal charge, doublereal size)
{
m_Elements->freezeElements();
m_speciesNames.push_back(name);
m_speciesCharge.push_back(charge);
m_speciesSize.push_back(size);
size_t ne = m_Elements->nElements();
// Create a changeable copy of the element composition. We now change the charge potentially
vector_fp compNew(ne);
for (size_t m = 0; m < ne; m++) {
compNew[m] = comp[m];
}
double wt = 0.0;
const vector_fp& aw = m_Elements->atomicWeights();
if (charge != 0.0) {
size_t eindex = m_Elements->elementIndex("E");
if (eindex != npos) {
doublereal ecomp = compNew[eindex];
if (fabs(charge + ecomp) > 0.001) {
if (ecomp != 0.0) {
throw CanteraError("Phase::addSpecies",
"Input charge and element E compositions differ for species " + name);
} else {
// Just fix up the element E composition based on the input species charge
compNew[eindex] = -charge;
}
}
} else {
addUniqueElementAfterFreeze("E", 0.000545, 0, 0.0, CT_ELEM_TYPE_ELECTRONCHARGE);
ne = m_Elements->nElements();
eindex = m_Elements->elementIndex("E");
compNew.resize(ne);
compNew[ne - 1] = - charge;
}
}
for (size_t m = 0; m < ne; m++) {
m_speciesComp.push_back(compNew[m]);
wt += compNew[m] * aw[m];
}
m_molwts.push_back(wt);
m_kk++;
}
void Phase::addUniqueSpecies(const std::string& name, const doublereal* comp,
doublereal charge, doublereal size)
{
vector<string>::const_iterator it = m_speciesNames.begin();
for (size_t k = 0; k < m_kk; k++) {
if (*it == name) {
/*
* We have found a match. At this point we could do some
* compatibility checks. However, let's just return for the
* moment without specifying any error.
*/
size_t m_mm = m_Elements->nElements();
for (size_t i = 0; i < m_mm; i++) {
if (comp[i] != m_speciesComp[m_kk * m_mm + i]) {
throw CanteraError("addUniqueSpecies",
"Duplicate species have different "
"compositions: " + *it);
}
}
if (charge != m_speciesCharge[m_kk]) {
throw CanteraError("addUniqueSpecies",
"Duplicate species have different "
"charges: " + *it);
}
if (size != m_speciesSize[m_kk]) {
throw CanteraError("addUniqueSpecies",
"Duplicate species have different "
"sizes: " + *it);
}
return;
}
++it;
}
addSpecies(name, comp, charge, size);
}
void Phase::freezeSpecies()
{
Constituents::freezeSpecies();
init(Constituents::molecularWeights());
m_speciesFrozen = true;
init(molecularWeights());
size_t kk = nSpecies();
size_t nv = kk + 2;
m_data.resize(nv,0.0);
m_data[0] = 300.0;
m_data[1] = 0.001;
m_data[2] = 1.0;
m_kk = nSpecies();
}
void Phase::init(const vector_fp& mw)
{
m_kk = mw.size();
m_molwts.resize(m_kk);
m_rmolwts.resize(m_kk);
m_y.resize(m_kk, 0.0);
m_ym.resize(m_kk, 0.0);
@ -650,7 +907,7 @@ void Phase::init(const vector_fp& mw)
bool Phase::ready() const
{
return (m_kk > 0 && Constituents::ready());
return (m_kk > 0 && m_Elements->elementsFrozen() && m_speciesFrozen);
}
} // namespace Cantera

View file

@ -7,14 +7,11 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
/*
* $Date: 2010-11-12 14:37:41 -0700 (Fri, 12 Nov 2010) $
* $Revision: 641 $
*/
#include "cantera/thermo/PhaseCombo_Interaction.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;

View file

@ -17,6 +17,7 @@
* U.S. Government retains certain rights in this software.
*/
#include "cantera/thermo/PseudoBinaryVPSSTP.h"
#include "cantera/base/stringUtils.h"
#include <cmath>

View file

@ -97,7 +97,6 @@ initThermo()
"could not create new substance object.");
}
m_mw = m_sub->MolWt();
m_weight[0] = m_mw;
setMolecularWeight(0,m_mw);
double one = 1.0;
setMoleFractions(&one);

View file

@ -11,14 +11,11 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
/*
* $Date: 2011-04-14 12:24:13 -0600 (Thu, 14 Apr 2011) $
* $Revision: 713 $
*/
#include "RedlichKisterVPSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;

View file

@ -11,6 +11,7 @@
* U.S. Government retains certain rights in this software.
*/
#include "cantera/thermo/SingleSpeciesTP.h"
#include "cantera/base/stringUtils.h"
using namespace std;

View file

@ -10,9 +10,9 @@
#include "cantera/thermo/SurfPhase.h"
#include "cantera/thermo/EdgePhase.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
using namespace ctml;
using namespace std;
///////////////////////////////////////////////////////////

View file

@ -9,6 +9,8 @@
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/base/mdp_allo.h"
#include "cantera/base/stringUtils.h"
#include <iomanip>
using namespace std;

View file

@ -14,6 +14,7 @@
#include "cantera/thermo/VPStandardStateTP.h"
#include "cantera/thermo/VPSSMgr.h"
#include "cantera/thermo/PDSS.h"
#include "cantera/base/stringUtils.h"
using namespace std;

View file

@ -11,6 +11,7 @@
#include "cantera/base/ctml.h"
#include "cantera/thermo/PDSS_Water.h"
#include "cantera/thermo/WaterPropsIAPWS.h"
#include "cantera/base/stringUtils.h"
#include <cmath>

View file

@ -8,12 +8,14 @@
* Contract DE-AC04-94AL85000 with Sandia Corporation, the
* U.S. Government retains certain rights in this software.
*/
#include "cantera/base/xml.h"
#include "cantera/thermo/WaterSSTP.h"
#include "cantera/thermo/WaterPropsIAPWS.h"
//#include "importCTML.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/xml.h"
#include "cantera/base/stringUtils.h"
#include <cmath>
using namespace std;
@ -237,7 +239,6 @@ initThermoXML(XML_Node& phaseNode, std::string id)
}
double mw_O = atomicWeight(nO);
m_mw = 2.0 * mw_H + mw_O;
m_weight[0] = m_mw;
setMolecularWeight(0,m_mw);
double one = 1.0;
setMoleFractions(&one);

View file

@ -13,6 +13,8 @@
#include "cantera/numerics/ctlapack.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;

View file

@ -12,6 +12,7 @@
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/transport/DustyGasTransport.h"
#include "cantera/base/stringUtils.h"
using namespace std;

View file

@ -2,17 +2,13 @@
* @file LiquidTransportParams.cpp
* Source code for liquid mixture transport property evaluations.
*/
/*
* Latest Checkin:
* $Author$
* $Date$
* $Revision$
*/
#include "cantera/transport/LiquidTransportParams.h"
#include <iostream>
#include "cantera/thermo/IonsFromNeutralVPSSTP.h"
#include "cantera/thermo/MargulesVPSSTP.h"
#include "cantera/base/stringUtils.h"
#include <stdlib.h>
using namespace std;
using namespace ctml;

View file

@ -8,8 +8,8 @@
#include "cantera/base/utilities.h"
#include "cantera/transport/LiquidTransportParams.h"
#include "cantera/transport/TransportFactory.h"
#include "cantera/numerics/ctlapack.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;

View file

@ -10,6 +10,7 @@
#include "cantera/base/utilities.h"
#include "cantera/transport/TransportParams.h"
#include "cantera/transport/TransportFactory.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;

View file

@ -20,6 +20,7 @@
#include "cantera/thermo/IdealGasPhase.h"
#include "cantera/transport/TransportFactory.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;

View file

@ -8,8 +8,8 @@
#include "cantera/base/utilities.h"
#include "cantera/transport/LiquidTransportParams.h"
#include "cantera/transport/TransportFactory.h"
#include "cantera/numerics/ctlapack.h"
#include "cantera/base/stringUtils.h"
#include <iostream>
using namespace std;

View file

@ -32,6 +32,7 @@
#include "cantera/base/global.h"
#include "cantera/thermo/IdealGasPhase.h"
#include "cantera/base/ctml.h"
#include "cantera/base/stringUtils.h"
#include <cstdio>
#include <cstring>