Normalized formatting of Elements.h and Elements.cpp

This commit is contained in:
Ray Speth 2012-04-27 21:20:38 +00:00
parent 59a2c4c251
commit 2193e4ceb0
2 changed files with 423 additions and 396 deletions

View file

@ -95,25 +95,26 @@ namespace Cantera
//! @exception CanteraError If a match is not found, throws a CanteraError
double LookupWtElements(const std::string& ename);
class XML_Node;
class XML_Node;
//! Object containing the elements that make up species in a phase.
/*!
* Class %Elements manages the elements that are part of a
* chemistry specification. This class may support calculations
* employing Multiple phases. In this case, a single Elements object may
* be shared by more than one Constituents class. Reactions between
* the phases may then be described using stoichiometry base on the
* same Elements class object.
*
* The member functions return information about the elements described
* in a particular instantiation of the class.
*
* @ingroup phases
*/
class Elements {
//! Object containing the elements that make up species in a phase.
/*!
* Class %Elements manages the elements that are part of a
* chemistry specification. This class may support calculations
* employing Multiple phases. In this case, a single Elements object may
* be shared by more than one Constituents class. Reactions between
* the phases may then be described using stoichiometry base on the
* same Elements class object.
*
* The member functions return information about the elements described
* in a particular instantiation of the class.
*
* @ingroup phases
*/
class Elements
{
public:
public:
//! Default constructor for the elements class
Elements();
@ -134,7 +135,7 @@ double LookupWtElements(const std::string& ename);
//! Assigntment operator
/*!
* This is the assignment operator for the Elements class.
* Right now we pretty much do a straight uncomplicated
* Right now we pretty much do a straight uncomplicated
* assignment. However, subscribers are not mucked with, as they
* have to do with the address of the object to be subscribed to
*
@ -143,13 +144,13 @@ double LookupWtElements(const std::string& ename);
Elements& operator=(const Elements& right);
//! Static function to look up an atomic weight
//! Static function to look up an atomic weight
/*!
* This static function looks up the argument string in the
* database above and returns the associated molecular weight.
* The data are from the periodic table.
*
* Note: The idea behind this function is to provide a unified
* Note: The idea behind this function is to provide a unified
* source for the element atomic weights. This helps to
* ensure that mass is conserved.
*
@ -160,21 +161,25 @@ double LookupWtElements(const std::string& ename);
* If a match for the string is not found, a value of -1.0 is
* returned.
*
* @exception CanteraError
* If a match is not found, a CanteraError is thrown as well
* @exception CanteraError
* If a match is not found, a CanteraError is thrown as well
*/
static double LookupWtElements(const std::string &ename);
static double LookupWtElements(const std::string& ename);
/// Atomic weight of element m.
/*!
* @param m element index
*/
doublereal atomicWeight(int m) const { return m_atomicWeights[m]; }
doublereal atomicWeight(int m) const {
return m_atomicWeights[m];
}
/// Atomic number of element m.
/*!
* @param m element index
*/
int atomicNumber(int m) const { return m_atomicNumbers[m]; }
int atomicNumber(int m) const {
return m_atomicNumbers[m];
}
//! Entropy at 298.15 K and 1 bar of stable state
//! of the element
@ -197,34 +202,38 @@ double LookupWtElements(const std::string& ename);
* CT_ELEM_TYPE_SURFACECONSTRAINT 5
* CT_ELEM_TYPE_OTHERCONSTRAINT 6
*
* The default is CT_ELEM_TYPE_ABSPOS
* The default is CT_ELEM_TYPE_ABSPOS
*
* @param m Element index
*
*
* @return Returns the element type
*/
int elementType(int m) const;
//! Change the element type of the mth constraint
/*!
/*!
* Reassigns an element type
*
* @param m Element index
* @param elem_type New elem type to be assigned
*
* @param elem_type New elem type to be assigned
*
* @return Returns the old element type
*/
int changeElementType(int m, int elem_type);
/// vector of element atomic weights
const vector_fp& atomicWeights() const { return m_atomicWeights; }
/**
const vector_fp& atomicWeights() const {
return m_atomicWeights;
}
/**
* Inline function that returns the number of elements in the object.
*
* @return
*
* @return
* \c int: The number of elements in the object.
*/
int nElements() const { return m_mm; }
int nElements() const {
return m_mm;
}
//! Function that returns the index of an element.
/*!
@ -238,20 +247,20 @@ double LookupWtElements(const std::string& ename);
*/
int elementIndex(std::string name) const;
//! Name of the element with index \c m.
//! Name of the element with index \c m.
/*!
* @param m Element index. If m < 0 or m >= nElements() an exception is thrown.
*/
std::string elementName(int m) const;
//! Returns a string vector containing the element names
//! Returns a string vector containing the element names
/*!
* Returns a read-only reference to the vector of element names.
* @return <tt> const vector<string>& </tt>: The vector contains
* the element names in their indexed order.
*/
const std::vector<std::string>& elementNames() const {
return m_elementNames;
return m_elementNames;
}
//! Add an element to the current set of elements in the current object.
@ -269,7 +278,7 @@ double LookupWtElements(const std::string& ename);
*/
void addElement(const std::string& symbol,
doublereal weight = -12345.0);
//! Add an element to the current set of elements in the current object.
//! Add an element to the current set of elements in the current object.
/*!
* @param e Reference to the XML_Node containing the element information
* The node name is the element symbol and the atomWt attribute
@ -290,7 +299,7 @@ double LookupWtElements(const std::string& ename);
* The default is to specify an ENTROPY298_UNKNOWN value,
* which will cause a throw error if its ever
* needed.
* @param elem_type New elem type to be assigned.
* @param elem_type New elem type to be assigned.
* The default is a regular element, CT_ELEM_TYPE_ABSPOS
*/
void addUniqueElement(const std::string& symbol,
@ -338,7 +347,7 @@ double LookupWtElements(const std::string& ename);
//! report the number of subscriptions
int reportSubscriptions() const;
protected:
protected:
/******************************************************************/
/* Description of DATA in the Object */
@ -369,7 +378,7 @@ double LookupWtElements(const std::string& ename);
vector_int m_atomicNumbers;
/** Vector of strings containing the names of the elements
*
*
* Note, a string search is the primary way to identify elements.
*/
std::vector<std::string> m_elementNames;
@ -394,14 +403,14 @@ double LookupWtElements(const std::string& ename);
/********* GLOBAL STATIC SECTION *************/
public:
public:
/** Vector of pointers to Elements Objects
*
*/
static std::vector<Elements *> Global_Elements_List;
static std::vector<Elements*> Global_Elements_List;
friend class Constituents;
};
};
} // namespace

View file

@ -3,17 +3,8 @@
* This file contains a database of atomic weights.
*/
/****************************************************************************
* $RCSfile: Elements.cpp,v $
* $Author$
* $Date$
* $Revision$
*
*
****************************************************************************/
// Copyright 2003 California Institute of Technology
#ifdef WIN32
#pragma warning(disable:4786)
#endif
@ -32,7 +23,8 @@ using namespace std;
#endif
#include <cstdlib>
namespace Cantera {
namespace Cantera
{
/*! Database for atomic molecular weights
@ -50,13 +42,13 @@ struct awData {
double atomicWeight; //!< atomic weight in kg / kg-mol
};
/*!
* @var static struct awData aWTable[]
* \brief aWTable is a vector containing the atomic weights database.
*
* The size of the table is given by the initial instantiation.
*/
static struct awData aWTable[] = {
/*!
* @var static struct awData aWTable[]
* \brief aWTable is a vector containing the atomic weights database.
*
* The size of the table is given by the initial instantiation.
*/
static struct awData aWTable[] = {
{"H", 1.00794},
{"D", 2.0 },
{"Tr", 3.0 },
@ -153,109 +145,116 @@ struct awData {
{"U", 238.0508 },
{"Np", 237.0482 },
{"Pu", 244.0482 }
};
};
// Static function to look up an atomic weight
/*
* This static function looks up the argument string in the
* database above and returns the associated molecular weight.
* The data are from the periodic table.
*
* Note: The idea behind this function is to provide a unified
* source for the element atomic weights. This helps to
* ensure that mass is conserved.
*
* @param s String, Only the first 3 characters are significant
*
* @return
* Return value contains the atomic weight of the element
* If a match for the string is not found, a value of -1.0 is
* returned.
*
* @exception CanteraError
* If a match is not found, a CanteraError is thrown as well
*/
doublereal Elements::LookupWtElements(const std::string& ename) {
// Static function to look up an atomic weight
/*
* This static function looks up the argument string in the
* database above and returns the associated molecular weight.
* The data are from the periodic table.
*
* Note: The idea behind this function is to provide a unified
* source for the element atomic weights. This helps to
* ensure that mass is conserved.
*
* @param s String, Only the first 3 characters are significant
*
* @return
* Return value contains the atomic weight of the element
* If a match for the string is not found, a value of -1.0 is
* returned.
*
* @exception CanteraError
* If a match is not found, a CanteraError is thrown as well
*/
doublereal Elements::LookupWtElements(const std::string& ename)
{
int num = sizeof(aWTable) / sizeof(struct awData);
string s3 = ename.substr(0,3);
for (int i = 0; i < num; i++) {
if (s3 == aWTable[i].name) {
return (aWTable[i].atomicWeight);
}
if (s3 == aWTable[i].name) {
return (aWTable[i].atomicWeight);
}
}
throw CanteraError("LookupWtElements", "element not found");
return -1.0;
}
}
doublereal LookupWtElements(const std::string& ename) {
doublereal LookupWtElements(const std::string& ename)
{
int num = sizeof(aWTable) / sizeof(struct awData);
string s3 = ename.substr(0,3);
for (int i = 0; i < num; i++) {
if (s3 == aWTable[i].name) {
return (aWTable[i].atomicWeight);
}
if (s3 == aWTable[i].name) {
return (aWTable[i].atomicWeight);
}
}
throw CanteraError("LookupWtElements", "element not found");
return -1.0;
}
}
//! Exception class to indicate a fixed set of elements.
/*!
* This class is used to warn the user when the number of elements
* are changed after at least one species is defined.
*/
class ElementsFrozen : public CanteraError {
public:
//! Exception class to indicate a fixed set of elements.
/*!
* This class is used to warn the user when the number of elements
* are changed after at least one species is defined.
*/
class ElementsFrozen : public CanteraError
{
public:
//! Constructor for class
/*!
* @param func Function where the error occurred.
*/
ElementsFrozen(string func)
: CanteraError(func,
"elements cannot be added after species.") {}
};
/*
* Elements Class Constructor
* We initialize all internal variables to zero here.
*/
Elements::Elements() :
ElementsFrozen(string func)
: CanteraError(func,
"elements cannot be added after species.") {}
};
/*
* Elements Class Constructor
* We initialize all internal variables to zero here.
*/
Elements::Elements() :
m_mm(0),
m_elementsFrozen(false),
m_elem_type(0),
numSubscribers(0)
{
}
{
}
/*
* Elements Class Destructor
* If the number of subscribers is not zero, through an error.
* A logic problem has occurred.
*
* @exception CanteraError
*/
Elements::~Elements() {
/*
* Elements Class Destructor
* If the number of subscribers is not zero, through an error.
* A logic problem has occurred.
*
* @exception CanteraError
*/
Elements::~Elements()
{
if (numSubscribers != 0) {
throw CanteraError("~Elements", "numSubscribers not zero");
throw CanteraError("~Elements", "numSubscribers not zero");
}
}
}
Elements::Elements(const Elements &right) :
Elements::Elements(const Elements& right) :
m_mm(0),
m_elementsFrozen(false),
numSubscribers(0)
{
{
*this = operator=(right);
}
}
Elements& Elements::operator=(const Elements& right)
{
if (&right == this) {
return *this;
}
Elements& Elements::operator=(const Elements &right) {
if (&right == this) return *this;
m_mm = right.m_mm;
m_elementsFrozen = right.m_elementsFrozen;
m_atomicWeights = right.m_atomicWeights;
@ -266,143 +265,151 @@ struct awData {
numSubscribers = 0;
return *this;
}
}
/*
* freezeElements():
*
* Set the freeze flag. This is a prerequesite to other
* activivities, i.e., this is done before species are defined.
*/
void Elements::freezeElements() {
/*
* freezeElements():
*
* Set the freeze flag. This is a prerequesite to other
* activivities, i.e., this is done before species are defined.
*/
void Elements::freezeElements()
{
m_elementsFrozen = true;
}
}
#ifdef INCL_DEPRECATED_METHODS
/*
*
* Returns an ElementData struct that contains the parameters
* for element index m.
*/
ElementData Elements::element(int m) const {
/*
*
* Returns an ElementData struct that contains the parameters
* for element index m.
*/
ElementData Elements::element(int m) const
{
ElementData e;
e.name = m_elementNames[m];
e.atomicWeight = m_atomicWeights[m];
return e;
}
#endif
/*
* elementIndex():
*
* Index of element named \c name. The index is an integer
* assigned to each element in the order it was added,
* beginning with 0 for the first element. If \c name is not
* the name of an element in the set, then the value -1 is
* returned.
*
*/
}
#endif
/*
* elementIndex():
*
* Index of element named \c name. The index is an integer
* assigned to each element in the order it was added,
* beginning with 0 for the first element. If \c name is not
* the name of an element in the set, then the value -1 is
* returned.
*
*/
#ifdef USE_DGG_CODE
int Elements::elementIndex(std::string name) const{
int Elements::elementIndex(std::string name) const
{
map<string, int>::const_iterator it;
it = m_definedElements.find(name);
if (it != m_definedElements.end()) {
return it->second;
return it->second;
}
return -1;
}
}
#else
int Elements::elementIndex(std::string name) const {
int Elements::elementIndex(std::string name) const
{
for (int i = 0; i < m_mm; i++) {
if (m_elementNames[i] == name) return i;
if (m_elementNames[i] == name) {
return i;
}
}
return -1;
}
}
#endif
/*
*
* Name of the element with index \c m. @param m Element
* index. If m < 0 or m >= nElements() an exception is thrown.
*/
string Elements::elementName(int m) const {
/*
*
* Name of the element with index \c m. @param m Element
* index. If m < 0 or m >= nElements() an exception is thrown.
*/
string Elements::elementName(int m) const
{
if (m < 0 || m >= nElements()) {
throw CanteraError("Elements::elementName()", "out of bounds: " + int2str(m) + " " + int2str(nElements()));
throw CanteraError("Elements::elementName()", "out of bounds: " + int2str(m) + " " + int2str(nElements()));
}
return m_elementNames[m];
}
}
doublereal Elements::entropyElement298(int m) const {
doublereal Elements::entropyElement298(int m) const
{
AssertThrowMsg(m_entropy298[m] != ENTROPY298_UNKNOWN,
"Elements::entropy298",
"Entropy at 298 K of element is unknown");
"Elements::entropy298",
"Entropy at 298 K of element is unknown");
AssertTrace(m >= 0 && m < m_mm);
return (m_entropy298[m]);
}
//====================================================================================================================
//! Return the element constraint type
/*!
* Possible types include:
*
* CT_ELEM_TYPE_TURNEDOFF -1
* CT_ELEM_TYPE_ABSPOS 0
* CT_ELEM_TYPE_ELECTRONCHARGE 1
* CT_ELEM_TYPE_CHARGENEUTRALITY 2
* CT_ELEM_TYPE_LATTICERATIO 3
* CT_ELEM_TYPE_KINETICFROZEN 4
* CT_ELEM_TYPE_SURFACECONSTRAINT 5
* CT_ELEM_TYPE_OTHERCONSTRAINT 6
*
* The default is CT_ELEM_TYPE_ABSPOS
*/
int Elements::elementType(int m) const
{
}
//====================================================================================================================
//! Return the element constraint type
/*!
* Possible types include:
*
* CT_ELEM_TYPE_TURNEDOFF -1
* CT_ELEM_TYPE_ABSPOS 0
* CT_ELEM_TYPE_ELECTRONCHARGE 1
* CT_ELEM_TYPE_CHARGENEUTRALITY 2
* CT_ELEM_TYPE_LATTICERATIO 3
* CT_ELEM_TYPE_KINETICFROZEN 4
* CT_ELEM_TYPE_SURFACECONSTRAINT 5
* CT_ELEM_TYPE_OTHERCONSTRAINT 6
*
* The default is CT_ELEM_TYPE_ABSPOS
*/
int Elements::elementType(int m) const
{
return m_elem_type[m];
}
//====================================================================================================================
// Change the element type of the mth constraint
/*
* Reassigns an element type
*
* @param m Element index
* @param elem_type New elem type to be assigned
*
* @return Returns the old element type
*/
int Elements::changeElementType(int m, int elem_type)
{
}
//====================================================================================================================
// Change the element type of the mth constraint
/*
* Reassigns an element type
*
* @param m Element index
* @param elem_type New elem type to be assigned
*
* @return Returns the old element type
*/
int Elements::changeElementType(int m, int elem_type)
{
int old = m_elem_type[m];
m_elem_type[m] = elem_type;
return old;
}
//====================================================================================================================
/*
*
* Add an element to the current set of elements in the current object.
* @param symbol symbol string
* @param weight atomic weight in kg/kmol.
*
* The default weight is a special value, which will cause the
* routine to look up the actual weight via a string lookup.
*
* There are two interfaces to this routine. The XML interface
* looks up the required parameters for the regular interface
* and then calls the base routine.
*/
void Elements::
addElement(const std::string& symbol, doublereal weight)
{
}
//====================================================================================================================
/*
*
* Add an element to the current set of elements in the current object.
* @param symbol symbol string
* @param weight atomic weight in kg/kmol.
*
* The default weight is a special value, which will cause the
* routine to look up the actual weight via a string lookup.
*
* There are two interfaces to this routine. The XML interface
* looks up the required parameters for the regular interface
* and then calls the base routine.
*/
void Elements::
addElement(const std::string& symbol, doublereal weight)
{
if (weight == -12345.0) {
weight = LookupWtElements(symbol);
if (weight < 0.0) {
throw ElementsFrozen("addElement");
}
weight = LookupWtElements(symbol);
if (weight < 0.0) {
throw ElementsFrozen("addElement");
}
}
if (m_elementsFrozen) {
throw ElementsFrozen("addElement");
return;
throw ElementsFrozen("addElement");
return;
}
m_atomicWeights.push_back(weight);
m_elementNames.push_back(symbol);
@ -410,83 +417,84 @@ struct awData {
m_definedElements[symbol] = nElements() + 1;
#endif
if (symbol == "E") {
m_elem_type.push_back(CT_ELEM_TYPE_ELECTRONCHARGE);
m_elem_type.push_back(CT_ELEM_TYPE_ELECTRONCHARGE);
} else {
m_elem_type.push_back(CT_ELEM_TYPE_ABSPOS);
m_elem_type.push_back(CT_ELEM_TYPE_ABSPOS);
}
m_mm++;
}
//===========================================================================================================
void Elements::
addElement(const XML_Node& e) {
}
//===========================================================================================================
void Elements::
addElement(const XML_Node& e)
{
doublereal weight = atof(e["atomicWt"].c_str());
string symbol = e["name"];
addElement(symbol, weight);
}
//===========================================================================================================
/*
* addUniqueElement():
*
* Add a unique element to the set. This routine will not allow
* duplicate elements to be input.
*
* @param symbol symbol string
* @param weight atomic weight in kg/kmol.
*
*
* The default weight is a special value, which will cause the
* routine to look up the actual weight via a string lookup.
*/
}
//===========================================================================================================
/*
* addUniqueElement():
*
* Add a unique element to the set. This routine will not allow
* duplicate elements to be input.
*
* @param symbol symbol string
* @param weight atomic weight in kg/kmol.
*
*
* The default weight is a special value, which will cause the
* routine to look up the actual weight via a string lookup.
*/
#ifdef USE_DGG_CODE
void Elements::
addUniqueElement(const std::string& symbol, doublereal weight, int atomicNumber,
doublereal entropy298, int elem_type)
{
if (m_elementsFrozen)
throw ElementsFrozen("addElement");
void Elements::
addUniqueElement(const std::string& symbol, doublereal weight, int atomicNumber,
doublereal entropy298, int elem_type)
{
if (m_elementsFrozen) {
throw ElementsFrozen("addElement");
}
if (weight == -12345.0) {
weight = LookupWtElements(symbol);
weight = LookupWtElements(symbol);
}
/*
* First decide if this element has been previously added.
* If it unique, add it to the list.
*/
int i = m_definedElements[symbol] - 1;
if (i < 0) {
m_atomicWeights.push_back(weight);
m_elementNames.push_back(symbol);
m_atomicNumbers.push_back(atomicNumber);
m_entropy298.push_back(entropy298);
if (symbol == "E") {
m_elem_type.push_back(CT_ELEM_TYPE_ELECTRONCHARGE);
} else {
m_elem_type.push_back(elem_type);
}
m_mm++;
}
else {
if (m_atomicWeights[i] != weight) {
throw CanteraError("AddUniqueElement",
"Duplicate Elements (" + symbol + ") have different weights");
}
m_atomicWeights.push_back(weight);
m_elementNames.push_back(symbol);
m_atomicNumbers.push_back(atomicNumber);
m_entropy298.push_back(entropy298);
if (symbol == "E") {
m_elem_type.push_back(CT_ELEM_TYPE_ELECTRONCHARGE);
} else {
m_elem_type.push_back(elem_type);
}
m_mm++;
} else {
if (m_atomicWeights[i] != weight) {
throw CanteraError("AddUniqueElement",
"Duplicate Elements (" + symbol + ") have different weights");
}
}
}
}
#else
void Elements::
addUniqueElement(const std::string& symbol,
doublereal weight, int atomicNumber, doublereal entropy298,
int elem_type)
{
void Elements::
addUniqueElement(const std::string& symbol,
doublereal weight, int atomicNumber, doublereal entropy298,
int elem_type)
{
if (weight == -12345.0) {
weight = LookupWtElements(symbol);
if (weight < 0.0) {
throw ElementsFrozen("addElement");
}
weight = LookupWtElements(symbol);
if (weight < 0.0) {
throw ElementsFrozen("addElement");
}
}
/*
* First decide if this element has been previously added
@ -496,109 +504,116 @@ struct awData {
int ifound = 0;
int i = 0;
for (vector<string>::const_iterator it = m_elementNames.begin();
it < m_elementNames.end(); ++it, ++i) {
if (*it == symbol) {
ifound = 1;
break;
}
it < m_elementNames.end(); ++it, ++i) {
if (*it == symbol) {
ifound = 1;
break;
}
}
if (!ifound) {
if (m_elementsFrozen) {
throw ElementsFrozen("addElement");
return;
}
m_atomicWeights.push_back(weight);
m_elementNames.push_back(symbol);
m_atomicNumbers.push_back(atomicNumber);
m_entropy298.push_back(entropy298);
if (symbol == "E") {
m_elem_type.push_back(CT_ELEM_TYPE_ELECTRONCHARGE);
} else {
m_elem_type.push_back(elem_type);
}
m_mm++;
if (m_elementsFrozen) {
throw ElementsFrozen("addElement");
return;
}
m_atomicWeights.push_back(weight);
m_elementNames.push_back(symbol);
m_atomicNumbers.push_back(atomicNumber);
m_entropy298.push_back(entropy298);
if (symbol == "E") {
m_elem_type.push_back(CT_ELEM_TYPE_ELECTRONCHARGE);
} else {
m_elem_type.push_back(elem_type);
}
m_mm++;
} else {
if (m_atomicWeights[i] != weight) {
throw CanteraError("AddUniqueElement",
"Duplicate Elements (" + symbol + ") have different weights");
}
if (m_atomicWeights[i] != weight) {
throw CanteraError("AddUniqueElement",
"Duplicate Elements (" + symbol + ") have different weights");
}
}
}
}
#endif
/*
* @todo call addUniqueElement(symbol, weight) instead of
* addElement.
*/
void Elements::
addUniqueElement(const XML_Node& e) {
/*
* @todo call addUniqueElement(symbol, weight) instead of
* addElement.
*/
void Elements::
addUniqueElement(const XML_Node& e)
{
doublereal weight = 0.0;
if (e.hasAttrib("atomicWt"))
weight = atof(stripws(e["atomicWt"]).c_str());
if (e.hasAttrib("atomicWt")) {
weight = atof(stripws(e["atomicWt"]).c_str());
}
int anum = 0;
if (e.hasAttrib("atomicNumber"))
anum = atoi(stripws(e["atomicNumber"]).c_str());
if (e.hasAttrib("atomicNumber")) {
anum = atoi(stripws(e["atomicNumber"]).c_str());
}
string symbol = e["name"];
doublereal entropy298 = ENTROPY298_UNKNOWN;
if (e.hasChild("entropy298")) {
XML_Node& e298Node = e.child("entropy298");
if (e298Node.hasAttrib("value")) {
entropy298 = atofCheck(stripws(e298Node["value"]).c_str());
}
XML_Node& e298Node = e.child("entropy298");
if (e298Node.hasAttrib("value")) {
entropy298 = atofCheck(stripws(e298Node["value"]).c_str());
}
}
if (weight != 0.0) {
addUniqueElement(symbol, weight, anum, entropy298);
addUniqueElement(symbol, weight, anum, entropy298);
} else {
addUniqueElement(symbol);
addUniqueElement(symbol);
}
}
// True if freezeElements has been called.
bool Elements::elementsFrozen() const
{
return m_elementsFrozen;
}
}
/*
* clear()
*
* Remove all elements from the structure.
*/
void Elements::clear() {
// True if freezeElements has been called.
bool Elements::elementsFrozen() const
{
return m_elementsFrozen;
}
/*
* clear()
*
* Remove all elements from the structure.
*/
void Elements::clear()
{
m_mm = 0;
m_atomicWeights.resize(0);
m_elementNames.resize(0);
m_entropy298.resize(0);
m_elem_type.resize(0);
m_elementsFrozen = false;
}
/*
* ready():
*
* True if the elements have been frozen
*/
bool Elements::ready() const {
}
/*
* ready():
*
* True if the elements have been frozen
*/
bool Elements::ready() const
{
return (m_elementsFrozen);
}
}
void Elements::addElementsFromXML(const XML_Node& phase) {
void Elements::addElementsFromXML(const XML_Node& phase)
{
// get the declared element names
if (! phase.hasChild("elementArray")) {
throw CanteraError("Elements::addElementsFromXML",
"phase xml node doesn't have \"elementArray\" XML Node");
throw CanteraError("Elements::addElementsFromXML",
"phase xml node doesn't have \"elementArray\" XML Node");
}
XML_Node& elements = phase.child("elementArray");
vector<string> enames;
getStringArray(elements, enames);
// // element database defaults to elements.xml
string element_database = "elements.xml";
if (elements.hasAttrib("datasrc"))
element_database = elements["datasrc"];
if (elements.hasAttrib("datasrc")) {
element_database = elements["datasrc"];
}
XML_Node* doc = get_XML_File(element_database);
XML_Node* dbe = &doc->child("ctml/elementData");
@ -606,9 +621,9 @@ struct awData {
XML_Node& root = phase.root();
XML_Node* local_db = 0;
if (root.hasChild("ctml")) {
if (root.child("ctml").hasChild("elementData")) {
local_db = &root.child("ctml/elementData");
}
if (root.child("ctml").hasChild("elementData")) {
local_db = &root.child("ctml/elementData");
}
}
int nel = static_cast<int>(enames.size());
@ -616,48 +631,51 @@ struct awData {
string enm;
XML_Node* e = 0;
for (i = 0; i < nel; i++) {
e = 0;
if (local_db) {
//writelog("looking in local database.");
e = local_db->findByAttr("name",enames[i]);
//if (!e) writelog(enames[i]+" not found.");
}
if (!e)
e = dbe->findByAttr("name",enames[i]);
if (e) {
addUniqueElement(*e);
}
else {
throw CanteraError("addElementsFromXML","no data for element "
+enames[i]);
}
e = 0;
if (local_db) {
//writelog("looking in local database.");
e = local_db->findByAttr("name",enames[i]);
//if (!e) writelog(enames[i]+" not found.");
}
if (!e) {
e = dbe->findByAttr("name",enames[i]);
}
if (e) {
addUniqueElement(*e);
} else {
throw CanteraError("addElementsFromXML","no data for element "
+enames[i]);
}
}
}
}
/*
* subscribe(), unsubscribe(), and reportSubscriptions():
*
* Handles setting and reporting the number of subscriptions to this
* object.
*/
void Elements::subscribe() {
/*
* subscribe(), unsubscribe(), and reportSubscriptions():
*
* Handles setting and reporting the number of subscriptions to this
* object.
*/
void Elements::subscribe()
{
++numSubscribers;
}
int Elements::unsubscribe() {
}
int Elements::unsubscribe()
{
--numSubscribers;
return numSubscribers;
}
int Elements::reportSubscriptions() const {
return numSubscribers;
}
/********************* GLOBAL STATIC SECTION **************************/
/*
* We keep track of a vector of pointers to element objects.
* Initially there are no Elements objects. Whenever one is created,
* the pointer to that object is added onto this list.
*/
vector<Elements *> Elements::Global_Elements_List;
/***********************************************************************/
}
int Elements::reportSubscriptions() const
{
return numSubscribers;
}
/********************* GLOBAL STATIC SECTION **************************/
/*
* We keep track of a vector of pointers to element objects.
* Initially there are no Elements objects. Whenever one is created,
* the pointer to that object is added onto this list.
*/
vector<Elements*> Elements::Global_Elements_List;
/***********************************************************************/
}