Cantera  2.3.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 };
164 
165 double LookupWtElements(const std::string& ename)
166 {
167  warn_deprecated("LookupWtElements",
168  "Use getElementWeight instead. To be removed after Cantera 2.3");
169  return getElementWeight(ename);
170 }
171 
172 double getElementWeight(const std::string& ename)
173 {
174  int numElements = numElementsDefined();
175  int numIsotopes = numIsotopesDefined();
176  string symbol = ba::trim_copy(ename);
177  string name = ba::to_lower_copy(symbol);
178  for (int i = 0; i < numElements; i++) {
179  if (symbol == atomicWeightTable[i].symbol) {
181  } else if (name == atomicWeightTable[i].fullName) {
183  }
184  }
185  for (int i = 0; i < numIsotopes; i++) {
186  if (symbol == isotopeWeightTable[i].symbol) {
188  } else if (name == isotopeWeightTable[i].fullName) {
190  }
191  }
192  throw CanteraError("getElementWeight", "element not found: " + ename);
193 }
194 
195 double getElementWeight(int atomicNumber)
196 {
197  int num = numElementsDefined();
198  if (atomicNumber > num || atomicNumber < 1) {
199  throw IndexError("getElementWeight", "atomicWeightTable", atomicNumber, num);
200  }
201  return atomicWeightTable[atomicNumber - 1].atomicWeight;
202 }
203 
204 string getElementSymbol(const std::string& ename)
205 {
206  int numElements = numElementsDefined();
207  int numIsotopes = numIsotopesDefined();
208  string name = ba::to_lower_copy(ba::trim_copy(ename));
209  for (int i = 0; i < numElements; i++) {
210  if (name == atomicWeightTable[i].fullName) {
211  return atomicWeightTable[i].symbol;
212  }
213  }
214  for (int i = 0; i < numIsotopes; i++) {
215  if (name == isotopeWeightTable[i].fullName) {
216  return isotopeWeightTable[i].symbol;
217  }
218  }
219  throw CanteraError("getElementSymbol", "element not found: " + ename);
220 }
221 
222 string getElementSymbol(int atomicNumber)
223 {
224  int num = numElementsDefined();
225  if (atomicNumber > num || atomicNumber < 1) {
226  throw IndexError("getElementSymbol", "atomicWeightTable", atomicNumber,
227  num);
228  }
229  return atomicWeightTable[atomicNumber - 1].symbol;
230 }
231 
232 string getElementName(const std::string& ename)
233 {
234  int numElements = numElementsDefined();
235  int numIsotopes = numIsotopesDefined();
236  string symbol = ba::trim_copy(ename);
237  for (int i = 0; i < numElements; i++) {
238  if (symbol == atomicWeightTable[i].symbol) {
239  return atomicWeightTable[i].fullName;
240  }
241  }
242  for (int i = 0; i < numIsotopes; i++) {
243  if (symbol == isotopeWeightTable[i].symbol) {
244  return isotopeWeightTable[i].fullName;
245  }
246  }
247  throw CanteraError("getElementName", "element not found: " + ename);
248 }
249 
250 string getElementName(int atomicNumber)
251 {
252  int num = numElementsDefined();
253  if (atomicNumber > num || atomicNumber < 1) {
254  throw IndexError("getElementName", "atomicWeightTable", atomicNumber,
255  num);
256  }
257  return atomicWeightTable[atomicNumber - 1].fullName;
258 }
259 
260 int getAtomicNumber(const std::string& ename)
261 {
262  int numElements = numElementsDefined();
263  int numIsotopes = numIsotopesDefined();
264  string symbol = ba::trim_copy(ename);
265  string name = ba::to_lower_copy(symbol);
266  for (int i = 0; i < numElements; i++) {
267  if (symbol == atomicWeightTable[i].symbol) {
268  return i+1;
269  } else if (name == atomicWeightTable[i].fullName) {
270  return i+1;
271  }
272  }
273  for (int i = 0; i < numIsotopes; i++) {
274  if (symbol == isotopeWeightTable[i].symbol) {
276  } else if (name == isotopeWeightTable[i].fullName) {
278  }
279  }
280  throw CanteraError("getAtomicNumber", "element not found: " + ename);
281 }
282 
284 {
285  return sizeof(atomicWeightTable) / sizeof(struct atomicWeightData);
286 }
287 
289 {
290  return sizeof(isotopeWeightTable) / sizeof(struct isotopeWeightData);
291 }
292 
293 }
int getAtomicNumber(const std::string &ename)
Get the atomic number for an element.
Definition: Elements.cpp:260
double LookupWtElements(const std::string &ename)
Function to look up an atomic weight.
Definition: Elements.cpp:165
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:195
int numElementsDefined()
Get the number of named elements defined in Cantera.
Definition: Elements.cpp:283
Contains the getElementWeight function and the definitions of element constraint types.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:222
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:288
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:250
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:164
string symbol
Isotope symbol, first letter capitalized.
Definition: Elements.cpp:39
Namespace for the Cantera kernel.
Definition: application.cpp:29
static struct atomicWeightData atomicWeightTable[]
atomicWeightTable is a vector containing the atomic weights database.
Definition: Elements.cpp:54