Add functions to get more information about elements.

Add functions to get the atomic number, name, symbol, and weight
of elements looked up by the atomic number, name, or symbol.
This commit is contained in:
Bryan W. Weber 2015-12-22 16:45:18 -05:00
parent f3bc7a5d5b
commit c324386fb2
2 changed files with 161 additions and 0 deletions

View file

@ -101,6 +101,78 @@ double LookupWtElements(const std::string& ename);
*/
double getElementWeight(const std::string& ename);
//! Get the atomic weight of an element.
/*!
* Get the atomic weight of an element defined in Cantera by its atomic
* number. The named isotopes cannot be accessed from this function,
* since the atomic number of the isotopes is the same as the regular
* element from which they are derived.
*
* @param atomicNumber Integer, atomic number of the element
* @return The atomic weight of the element
* @exception CanteraError If a match is not found, throws a CanteraError
*/
double getElementWeight(int atomicNumber);
//! Get the symbol for an element
/*!
* Get the symbol for an element defined in Cantera by its name. This
* includes the named isotopes defined in Cantera.
*
* @param ename String, name of the element
* @return The symbol of the element in a string
* @exception CanteraError If a match is not found, throws a CanteraError
*/
std::string getElementSymbol(const std::string& ename);
//! Get the symbol for an element
/*!
* Get the symbol for an element defined in Cantera by its atomic
* number. The named isotopes cannot be accessed from this function,
* since the atomic number of the isotopes is the same as the regular
* element from which they are derived.
*
* @param atomicNumber Integer, atomic number of the element
* @return The symbol of the element in a string
* @exception CanteraError If a match is not found, throws a CanteraError
*/
std::string getElementSymbol(int atomicNumber);
//! Get the name of an element
/*!
* Get the name of an element defined in Cantera by its symbol. This
* includes the named isotopes defined in Cantera.
*
* @param ename String, symbol for the element
* @return The name of the element, in a string
* @exception CanteraError If a match is not found, throws a CanteraError
*/
std::string getElementName(const std::string& ename);
//! Get the name of an element
/*!
* Get the name of an element defined in Cantera by its atomic
* number. The named isotopes cannot be accessed from this function,
* since the atomic number of the isotopes is the same as the regular
* element from which they are derived.
*
* @param atomicNumber Integer, atomic number of the element
* @return The name of the element, in a string
* @exception CanteraError If a match is not found, throws a CanteraError
*/
std::string getElementName(int atomicNumber);
//! Get the atomic number for an element
/*!
* Get the atomic number of an element defined in Cantera by its symbol
* or name. This includes the named isotopes included in Cantera.
*
* @param ename String, name or symbol of the element
* @return The integer atomic number of the element
* @exception CanteraError If a match is not found, throws a CanteraError
*/
int getAtomicNumber(const std::string& ename);
//! Get the number of named elements defined in Cantera.
//! This array excludes named isotopes
int numElementsDefined();

View file

@ -193,6 +193,95 @@ double getElementWeight(const std::string& ename)
return -1.0;
}
double getElementWeight(int atomicNumber)
{
int num = numElementsDefined();
if (atomicNumber > num || atomicNumber < 1) {
throw IndexError("getElementWeight", "atomicWeightTable", atomicNumber, num);
}
return atomicWeightTable[atomicNumber - 1].atomicWeight;
}
string getElementSymbol(const std::string& ename)
{
int numElements = numElementsDefined();
int numIsotopes = numIsotopesDefined();
for (int i = 0; i < numElements; i++) {
if (ename == atomicWeightTable[i].fullName) {
return atomicWeightTable[i].symbol;
}
}
for (int i = 0; i < numIsotopes; i++) {
if (ename == isotopeWeightTable[i].fullName) {
return isotopeWeightTable[i].symbol;
}
}
throw CanteraError("getElementSymbol", "element not found: " + ename);
}
string getElementSymbol(int atomicNumber)
{
int num = numElementsDefined();
if (atomicNumber > num || atomicNumber < 1) {
throw IndexError("getElementSymbol", "atomicWeightTable", atomicNumber,
num);
}
return atomicWeightTable[atomicNumber - 1].symbol;
}
string getElementName(const std::string& ename)
{
int numElements = numElementsDefined();
int numIsotopes = numIsotopesDefined();
string sym = ename.substr(0,2);
for (int i = 0; i < numElements; i++) {
if (sym == atomicWeightTable[i].symbol) {
return atomicWeightTable[i].fullName;
}
}
for (int i = 0; i < numIsotopes; i++) {
if (sym == isotopeWeightTable[i].symbol) {
return isotopeWeightTable[i].fullName;
}
}
throw CanteraError("getElementName", "element not found: " + ename);
}
string getElementName(int atomicNumber)
{
int num = numElementsDefined();
if (atomicNumber > num || atomicNumber < 1) {
throw IndexError("getElementName", "atomicWeightTable", atomicNumber,
num);
}
return atomicWeightTable[atomicNumber - 1].fullName;
}
int getAtomicNumber(const std::string& ename)
{
int numElements = numElementsDefined();
int numIsotopes = numIsotopesDefined();
string sym = ename.substr(0,2);
for (int i = 0; i < numElements; i++) {
if (sym == atomicWeightTable[i].symbol) {
return i+1;
}
else if (ename == atomicWeightTable[i].fullName) {
return i+1;
}
}
for (int i = 0; i < numIsotopes; i++) {
if (sym == isotopeWeightTable[i].symbol) {
return isotopeWeightTable[i].atomicNumber;
}
else if (ename == isotopeWeightTable[i].fullName) {
return isotopeWeightTable[i].atomicNumber;
}
}
throw CanteraError("getAtomicNumber", "element not found: " + ename);
return -1.0;
}
int numElementsDefined()
{
return sizeof(atomicWeightTable) / sizeof(struct atomicWeightData);