Cantera  2.4.0
Elements.cpp
Go to the documentation of this file.
1 /**
2  * @file Elements.cpp
3  * This file contains a database of atomic weights.
4  */
5 
6 // This file is part of Cantera. See License.txt in the top-level directory or
7 // at http://www.cantera.org/license.txt for license and copyright information.
8 
10 #include "cantera/base/ctml.h"
12 
13 using namespace std;
14 
15 namespace Cantera
16 {
17 
18 /*! Database for atomic weights
19  * Values are taken from the 1989 Standard Atomic Weights, CRC
20  *
21  * units = kg / kg-mol (or equivalently gm / gm-mol)
22  *
23  * This structure was picked because it's simple, compact, and extensible.
24  */
26  string symbol; //!< Element symbol, first letter capitalized
27  string fullName; //!< Element full name, first letter lowercase
28  double atomicWeight; //!< Element atomic weight in kg / kg-mol
29 };
30 
31 /*! Database for named isotopic weights
32  * Values are taken from the 1989 Standard Atomic Weights, CRC
33  *
34  * units = kg / kg-mol (or equivalently gm / gm-mol)
35  *
36  * This structure was picked because it's simple, compact, and extensible.
37  */
39  string symbol; //!< Isotope symbol, first letter capitalized
40  string fullName; //!< Isotope full name, first letter lowercase
41  double atomicWeight; //!< Isotope atomic weight in kg / kg-mol
42  int atomicNumber; //!< Isotope atomic number
43 };
44 
45 /*!
46  * @var static struct atomicWeightData atomicWeightTable[]
47  * \brief atomicWeightTable is a vector containing the atomic weights database.
48  *
49  * atomicWeightTable[] is a static function with scope limited to this file.
50  * It can only be referenced via the functions in this file.
51  *
52  * The size of the table is given by the initial instantiation.
53  */
55  {"H", "hydrogen", 1.00794},
56  {"He", "helium", 4.002602},
57  {"Li", "lithium", 6.941 },
58  {"Be", "beryllium", 9.012182},
59  {"B", "boron", 10.811 },
60  {"C", "carbon", 12.011 },
61  {"N", "nitrogen", 14.00674},
62  {"O", "oxygen", 15.9994 },
63  {"F", "fluorine", 18.9984032},
64  {"Ne", "neon", 20.1797 },
65  {"Na", "sodium", 22.98977},
66  {"Mg", "magnesium", 24.3050 },
67  {"Al", "aluminum", 26.98154},
68  {"Si", "silicon", 28.0855 },
69  {"P", "phosphorus", 30.97376},
70  {"S", "sulfur", 32.066 },
71  {"Cl", "chlorine", 35.4527 },
72  {"Ar", "argon", 39.948 },
73  {"K", "potassium", 39.0983 },
74  {"Ca", "calcium", 40.078 },
75  {"Sc", "scandium", 44.95591},
76  {"Ti", "titanium", 47.88 },
77  {"V", "vanadium", 50.9415 },
78  {"Cr", "chromium", 51.9961 },
79  {"Mn", "manganese", 54.9381 },
80  {"Fe", "iron", 55.847 },
81  {"Co", "cobalt", 58.9332 },
82  {"Ni", "nickel", 58.69 },
83  {"Cu", "copper", 63.546 },
84  {"Zn", "zinc", 65.39 },
85  {"Ga", "gallium", 69.723 },
86  {"Ge", "germanium", 72.61 },
87  {"As", "arsenic", 74.92159},
88  {"Se", "selenium", 78.96 },
89  {"Br", "bromine", 79.904 },
90  {"Kr", "krypton", 83.80 },
91  {"Rb", "rubidium", 85.4678 },
92  {"Sr", "strontium", 87.62 },
93  {"Y", "yttrium", 88.90585},
94  {"Zr", "zirconium", 91.224 },
95  {"Nb", "nobelium", 92.90638},
96  {"Mo", "molybdenum", 95.94 },
97  {"Tc", "technetium", 97.9072 },
98  {"Ru", "ruthenium", 101.07 },
99  {"Rh", "rhodium", 102.9055 },
100  {"Pd", "palladium", 106.42 },
101  {"Ag", "silver", 107.8682 },
102  {"Cd", "cadmium", 112.411 },
103  {"In", "indium", 114.82 },
104  {"Sn", "tin", 118.710 },
105  {"Sb", "antimony", 121.75 },
106  {"Te", "tellurium", 127.6 },
107  {"I", "iodine", 126.90447},
108  {"Xe", "xenon", 131.29 },
109  {"Cs", "cesium", 132.90543},
110  {"Ba", "barium", 137.327 },
111  {"La", "lanthanum", 138.9055 },
112  {"Ce", "cerium", 140.115 },
113  {"Pr", "praseodymium", 140.90765},
114  {"Nd", "neodymium", 144.24 },
115  {"Pm", "promethium", 144.9127 },
116  {"Sm", "samarium", 150.36 },
117  {"Eu", "europium", 151.965 },
118  {"Gd", "gadolinium", 157.25 },
119  {"Tb", "terbium", 158.92534},
120  {"Dy", "dysprosium", 162.50 },
121  {"Ho", "holmium", 164.93032},
122  {"Er", "erbium", 167.26 },
123  {"Tm", "thulium", 168.93421},
124  {"Yb", "ytterbium", 173.04 },
125  {"Lu", "lutetium", 174.967 },
126  {"Hf", "hafnium", 178.49 },
127  {"Ta", "tantalum", 180.9479 },
128  {"W", "tungsten", 183.85 },
129  {"Re", "rhenium", 186.207 },
130  {"Os", "osmium", 190.2 },
131  {"Ir", "iridium", 192.22 },
132  {"Pt", "platinum", 195.08 },
133  {"Au", "gold", 196.96654},
134  {"Hg", "mercury", 200.59 },
135  {"Tl", "thallium", 204.3833 },
136  {"Pb", "lead", 207.2 },
137  {"Bi", "bismuth", 208.98037},
138  {"Po", "polonium", 208.9824 },
139  {"At", "astatine", 209.9871 },
140  {"Rn", "radon", 222.0176 },
141  {"Fr", "francium", 223.0197 },
142  {"Ra", "radium", 226.0254 },
143  {"Ac", "actinium", 227.0279 },
144  {"Th", "thorium", 232.0381 },
145  {"Pa", "protactinium", 231.03588},
146  {"U", "uranium", 238.0508 },
147  {"Np", "neptunium", 237.0482 },
148  {"Pu", "plutonium", 244.0482 },
149 };
150 
151 /*!
152  * @var static struct isotopeWeightData isotopeWeightTable[]
153  * \brief isotopeWeightTable is a vector containing the atomic weights database.
154  *
155  * isotopeWeightTable[] is a static function with scope limited to this file.
156  * It can only be referenced via the functions in this file.
157  *
158  * The size of the table is given by the initial instantiation.
159  */
161  {"D", "deuterium", 2.0, 1},
162  {"Tr", "tritium", 3.0, 1},
163  {"E", "electron", 0.000545, 0},
164 };
165 
166 double getElementWeight(const std::string& ename)
167 {
168  int numElements = numElementsDefined();
169  int numIsotopes = numIsotopesDefined();
170  string symbol = trimCopy(ename);
171  string name = toLowerCopy(symbol);
172  for (int i = 0; i < numElements; i++) {
173  if (symbol == atomicWeightTable[i].symbol) {
175  } else if (name == atomicWeightTable[i].fullName) {
177  }
178  }
179  for (int i = 0; i < numIsotopes; i++) {
180  if (symbol == isotopeWeightTable[i].symbol) {
182  } else if (name == isotopeWeightTable[i].fullName) {
184  }
185  }
186  throw CanteraError("getElementWeight", "element not found: " + ename);
187 }
188 
189 double getElementWeight(int atomicNumber)
190 {
191  int num = numElementsDefined();
192  if (atomicNumber > num || atomicNumber < 1) {
193  throw IndexError("getElementWeight", "atomicWeightTable", atomicNumber, num);
194  }
195  return atomicWeightTable[atomicNumber - 1].atomicWeight;
196 }
197 
198 string getElementSymbol(const std::string& ename)
199 {
200  int numElements = numElementsDefined();
201  int numIsotopes = numIsotopesDefined();
202  string name = toLowerCopy(trimCopy(ename));
203  for (int i = 0; i < numElements; i++) {
204  if (name == atomicWeightTable[i].fullName) {
205  return atomicWeightTable[i].symbol;
206  }
207  }
208  for (int i = 0; i < numIsotopes; i++) {
209  if (name == isotopeWeightTable[i].fullName) {
210  return isotopeWeightTable[i].symbol;
211  }
212  }
213  throw CanteraError("getElementSymbol", "element not found: " + ename);
214 }
215 
216 string getElementSymbol(int atomicNumber)
217 {
218  int num = numElementsDefined();
219  if (atomicNumber > num || atomicNumber < 1) {
220  throw IndexError("getElementSymbol", "atomicWeightTable", atomicNumber,
221  num);
222  }
223  return atomicWeightTable[atomicNumber - 1].symbol;
224 }
225 
226 string getElementName(const std::string& ename)
227 {
228  int numElements = numElementsDefined();
229  int numIsotopes = numIsotopesDefined();
230  string symbol = trimCopy(ename);
231  for (int i = 0; i < numElements; i++) {
232  if (symbol == atomicWeightTable[i].symbol) {
233  return atomicWeightTable[i].fullName;
234  }
235  }
236  for (int i = 0; i < numIsotopes; i++) {
237  if (symbol == isotopeWeightTable[i].symbol) {
238  return isotopeWeightTable[i].fullName;
239  }
240  }
241  throw CanteraError("getElementName", "element not found: " + ename);
242 }
243 
244 string getElementName(int atomicNumber)
245 {
246  int num = numElementsDefined();
247  if (atomicNumber > num || atomicNumber < 1) {
248  throw IndexError("getElementName", "atomicWeightTable", atomicNumber,
249  num);
250  }
251  return atomicWeightTable[atomicNumber - 1].fullName;
252 }
253 
254 int getAtomicNumber(const std::string& ename)
255 {
256  int numElements = numElementsDefined();
257  int numIsotopes = numIsotopesDefined();
258  string symbol = trimCopy(ename);
259  string name = toLowerCopy(symbol);
260  for (int i = 0; i < numElements; i++) {
261  if (symbol == atomicWeightTable[i].symbol) {
262  return i+1;
263  } else if (name == atomicWeightTable[i].fullName) {
264  return i+1;
265  }
266  }
267  for (int i = 0; i < numIsotopes; i++) {
268  if (symbol == isotopeWeightTable[i].symbol) {
270  } else if (name == isotopeWeightTable[i].fullName) {
272  }
273  }
274  throw CanteraError("getAtomicNumber", "element not found: " + ename);
275 }
276 
278 {
279  return sizeof(atomicWeightTable) / sizeof(struct atomicWeightData);
280 }
281 
283 {
284  return sizeof(isotopeWeightTable) / sizeof(struct isotopeWeightData);
285 }
286 
287 }
int getAtomicNumber(const std::string &ename)
Get the atomic number for an element.
Definition: Elements.cpp:254
std::string trimCopy(const std::string &input)
Trim.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
string fullName
Isotope full name, first letter lowercase.
Definition: Elements.cpp:40
double getElementWeight(int atomicNumber)
Get the atomic weight of an element.
Definition: Elements.cpp:189
int numElementsDefined()
Get the number of named elements defined in Cantera.
Definition: Elements.cpp:277
Contains the getElementWeight function and the definitions of element constraint types.
STL namespace.
string fullName
Element full name, first letter lowercase.
Definition: Elements.cpp:27
string getElementSymbol(int atomicNumber)
Get the symbol for an element.
Definition: Elements.cpp:216
double atomicWeight
Isotope atomic weight in kg / kg-mol.
Definition: Elements.cpp:41
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
int atomicNumber
Isotope atomic number.
Definition: Elements.cpp:42
int numIsotopesDefined()
Get the number of named isotopes defined in Cantera.
Definition: Elements.cpp:282
static struct isotopeWeightData isotopeWeightTable[]
isotopeWeightTable is a vector containing the atomic weights database.
Definition: Elements.cpp:160
string getElementName(int atomicNumber)
Get the name of an element.
Definition: Elements.cpp:244
Contains declarations for string manipulation functions within Cantera.
string symbol
Element symbol, first letter capitalized.
Definition: Elements.cpp:26
double atomicWeight
Element atomic weight in kg / kg-mol.
Definition: Elements.cpp:28
An array index is out of range.
Definition: ctexceptions.h:158
string symbol
Isotope symbol, first letter capitalized.
Definition: Elements.cpp:39
std::string toLowerCopy(const std::string &input)
Convert to lower case.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
static struct atomicWeightData atomicWeightTable[]
atomicWeightTable is a vector containing the atomic weights database.
Definition: Elements.cpp:54