Cantera  2.5.1
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 https://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 used from CIAAW. Atomic weights of the elements 2017
20  * when a single value is given. Available online at
21  * http://www.ciaaw.org/atomic-weights.htm
22  *
23  * When a range of values is given in the CIAAW table, the "conventional
24  * atomic weight" from the IUPAC Periodic Table is used. Available
25  * online at https://iupac.org/wp-content/uploads/2018/12/IUPAC_Periodic_Table-01Dec18.pdf
26  *
27  * If no value is given in either source, it is because no stable isotopes of
28  * that element are known and the atomic weight of that element is listed here
29  * as -1.0
30  *
31  * units = kg / kg-mol (or equivalently gm / gm-mol)
32  *
33  * This structure was picked because it's simple, compact, and extensible.
34  */
36  string symbol; //!< Element symbol, first letter capitalized
37  string fullName; //!< Element full name, first letter lowercase
38  double atomicWeight; //!< Element atomic weight in kg / kg-mol, if known. -1 if no stable isotope
39 };
40 
41 /*! Database for named isotopic weights
42  * Values are used from
43  * Kim S, Chen J, Cheng T, Gindulyte A, He J, He S, Li Q, Shoemaker BA,
44  * Thiessen PA, Yu B, Zaslavsky L, Zhang J, Bolton EE. PubChem 2019
45  * update: improved access to chemical data. Nucleic Acids Res. 2019
46  * Jan 8; 47(D1):D1102-1109. doi:10.1093/nar/gky1033.
47  * [PubMed PMID:30371825]
48  *
49  * units = kg / kg-mol (or equivalently gm / gm-mol)
50  *
51  * This structure was picked because it's simple, compact, and extensible.
52  */
54  string symbol; //!< Isotope symbol, first letter capitalized
55  string fullName; //!< Isotope full name, first letter lowercase
56  double atomicWeight; //!< Isotope atomic weight in kg / kg-mol
57  int atomicNumber; //!< Isotope atomic number
58 };
59 
60 /*!
61  * @var static struct atomicWeightData atomicWeightTable[]
62  * \brief atomicWeightTable is a vector containing the atomic weights database.
63  *
64  * atomicWeightTable[] is a static variable with scope limited to this file.
65  * It can only be referenced via the functions in this file.
66  *
67  * The size of the table is given by the initial instantiation.
68  */
69 static struct atomicWeightData atomicWeightTable[] = {
70  {"H", "hydrogen", 1.008},
71  {"He", "helium", 4.002602},
72  {"Li", "lithium", 6.94},
73  {"Be", "beryllium", 9.0121831},
74  {"B", "boron", 10.81},
75  {"C", "carbon", 12.011},
76  {"N", "nitrogen", 14.007},
77  {"O", "oxygen", 15.999},
78  {"F", "fluorine", 18.998403163},
79  {"Ne", "neon", 20.1797},
80  {"Na", "sodium", 22.98976928},
81  {"Mg", "magnesium", 24.305},
82  {"Al", "aluminum", 26.9815384},
83  {"Si", "silicon", 28.085},
84  {"P", "phosphorus", 30.973761998},
85  {"S", "sulfur", 32.06},
86  {"Cl", "chlorine", 35.45},
87  {"Ar", "argon", 39.95},
88  {"K", "potassium", 39.0983},
89  {"Ca", "calcium", 40.078},
90  {"Sc", "scandium", 44.955908},
91  {"Ti", "titanium", 47.867},
92  {"V", "vanadium", 50.9415},
93  {"Cr", "chromium", 51.9961},
94  {"Mn", "manganese", 54.938043},
95  {"Fe", "iron", 55.845},
96  {"Co", "cobalt", 58.933194},
97  {"Ni", "nickel", 58.6934},
98  {"Cu", "copper", 63.546},
99  {"Zn", "zinc", 65.38},
100  {"Ga", "gallium", 69.723},
101  {"Ge", "germanium", 72.630},
102  {"As", "arsenic", 74.921595},
103  {"Se", "selenium", 78.971},
104  {"Br", "bromine", 79.904},
105  {"Kr", "krypton", 83.798},
106  {"Rb", "rubidium", 85.4678},
107  {"Sr", "strontium", 87.62},
108  {"Y", "yttrium", 88.90584},
109  {"Zr", "zirconium", 91.224},
110  {"Nb", "nobelium", 92.90637},
111  {"Mo", "molybdenum", 95.95},
112  {"Tc", "technetium", -1.0},
113  {"Ru", "ruthenium", 101.07},
114  {"Rh", "rhodium", 102.90549},
115  {"Pd", "palladium", 106.42},
116  {"Ag", "silver", 107.8682},
117  {"Cd", "cadmium", 112.414},
118  {"In", "indium", 114.818},
119  {"Sn", "tin", 118.710},
120  {"Sb", "antimony", 121.760},
121  {"Te", "tellurium", 127.60 },
122  {"I", "iodine", 126.90447},
123  {"Xe", "xenon", 131.293},
124  {"Cs", "cesium", 132.90545196},
125  {"Ba", "barium", 137.327},
126  {"La", "lanthanum", 138.90547},
127  {"Ce", "cerium", 140.116},
128  {"Pr", "praseodymium", 140.90766},
129  {"Nd", "neodymium", 144.242},
130  {"Pm", "promethium", -1.0},
131  {"Sm", "samarium", 150.36},
132  {"Eu", "europium", 151.964},
133  {"Gd", "gadolinium", 157.25},
134  {"Tb", "terbium", 158.925354},
135  {"Dy", "dysprosium", 162.500},
136  {"Ho", "holmium", 164.930328},
137  {"Er", "erbium", 167.259},
138  {"Tm", "thulium", 168.934218},
139  {"Yb", "ytterbium", 173.045},
140  {"Lu", "lutetium", 174.9668},
141  {"Hf", "hafnium", 178.49},
142  {"Ta", "tantalum", 180.94788},
143  {"W", "tungsten", 183.84},
144  {"Re", "rhenium", 186.207},
145  {"Os", "osmium", 190.23 },
146  {"Ir", "iridium", 192.217},
147  {"Pt", "platinum", 195.084},
148  {"Au", "gold", 196.966570},
149  {"Hg", "mercury", 200.592},
150  {"Tl", "thallium", 204.38},
151  {"Pb", "lead", 207.2 },
152  {"Bi", "bismuth", 208.98040},
153  {"Po", "polonium", -1.0},
154  {"At", "astatine", -1.0},
155  {"Rn", "radon", -1.0},
156  {"Fr", "francium", -1.0},
157  {"Ra", "radium", -1.0},
158  {"Ac", "actinium", -1.0},
159  {"Th", "thorium", 232.0377},
160  {"Pa", "protactinium", 231.03588},
161  {"U", "uranium", 238.02891},
162  {"Np", "neptunium", -1.0},
163  {"Pu", "plutonium", -1.0},
164  {"Am", "americium", -1.0},
165  {"Cm", "curium", -1.0},
166  {"Bk", "berkelium", -1.0},
167  {"Cf", "californium", -1.0},
168  {"Es", "einsteinium", -1.0},
169  {"Fm", "fermium", -1.0},
170  {"Md", "mendelevium", -1.0},
171  {"No", "nobelium", -1.0},
172  {"Lr", "lawrencium", -1.0},
173  {"Rf", "rutherfordium", -1.0},
174  {"Db", "dubnium", -1.0},
175  {"Sg", "seaborgium", -1.0},
176  {"Bh", "bohrium", -1.0},
177  {"Hs", "hassium", -1.0},
178  {"Mt", "meitnerium", -1.0},
179  {"Ds", "darmstadtium", -1.0},
180  {"Rg", "roentgenium", -1.0},
181  {"Cn", "copernicium", -1.0},
182  {"Nh", "nihonium", -1.0},
183  {"Gl", "flerovium", -1.0},
184  {"Mc", "moscovium", -1.0},
185  {"Lv", "livermorium", -1.0},
186  {"Ts", "tennessine", -1.0},
187  {"Og", "oganesson", -1.0},
188 };
189 
190 /*!
191  * @var static struct isotopeWeightData isotopeWeightTable[]
192  * \brief isotopeWeightTable is a vector containing the atomic weights database.
193  *
194  * isotopeWeightTable[] is a static function with scope limited to this file.
195  * It can only be referenced via the functions in this file.
196  *
197  * The size of the table is given by the initial instantiation.
198  */
199 static struct isotopeWeightData isotopeWeightTable[] = {
200  // M. Wang et al. The AME2016 atomic mass evaluation. Chinese Physics C.
201  // doi:10.1088/1674-1137/41/3/030003.
202  {"D", "deuterium", 2.0141017781, 1},
203  {"Tr", "tritium", 3.0160492820, 1},
204  {"E", "electron", ElectronMass * Avogadro, 0},
205 };
206 
207 double getElementWeight(const std::string& ename)
208 {
209  int numElements = numElementsDefined();
210  int numIsotopes = numIsotopesDefined();
211  double elementWeight = 0.0;
212  string symbol = trimCopy(ename);
213  string name = toLowerCopy(symbol);
214  for (int i = 0; i < numElements; i++) {
215  if (symbol == atomicWeightTable[i].symbol) {
216  elementWeight = atomicWeightTable[i].atomicWeight;
217  break;
218  } else if (name == atomicWeightTable[i].fullName) {
219  elementWeight = atomicWeightTable[i].atomicWeight;
220  break;
221  }
222  }
223  if (elementWeight > 0.0) {
224  return elementWeight;
225  } else if (elementWeight < 0.0) {
226  throw CanteraError("getElementWeight",
227  "element '{}' has no stable isotopes", ename);
228  }
229  for (int i = 0; i < numIsotopes; i++) {
230  if (symbol == isotopeWeightTable[i].symbol) {
232  } else if (name == isotopeWeightTable[i].fullName) {
234  }
235  }
236  throw CanteraError("getElementWeight", "element not found: " + ename);
237 }
238 
239 double getElementWeight(int atomicNumber)
240 {
241  int num = numElementsDefined();
242  if (atomicNumber > num || atomicNumber < 1) {
243  throw IndexError("getElementWeight", "atomicWeightTable", atomicNumber, num);
244  }
245  double elementWeight = atomicWeightTable[atomicNumber - 1].atomicWeight;
246  if (elementWeight < 0.0) {
247  throw CanteraError("getElementWeight",
248  "element '{}' has no stable isotopes", getElementName(atomicNumber));
249  }
250  return elementWeight;
251 }
252 
253 string getElementSymbol(const std::string& ename)
254 {
255  int numElements = numElementsDefined();
256  int numIsotopes = numIsotopesDefined();
257  string name = toLowerCopy(trimCopy(ename));
258  for (int i = 0; i < numElements; i++) {
259  if (name == atomicWeightTable[i].fullName) {
260  return atomicWeightTable[i].symbol;
261  }
262  }
263  for (int i = 0; i < numIsotopes; i++) {
264  if (name == isotopeWeightTable[i].fullName) {
265  return isotopeWeightTable[i].symbol;
266  }
267  }
268  throw CanteraError("getElementSymbol", "element not found: " + ename);
269 }
270 
271 string getElementSymbol(int atomicNumber)
272 {
273  int num = numElementsDefined();
274  if (atomicNumber > num || atomicNumber < 1) {
275  throw IndexError("getElementSymbol", "atomicWeightTable", atomicNumber,
276  num);
277  }
278  return atomicWeightTable[atomicNumber - 1].symbol;
279 }
280 
281 string getElementName(const std::string& ename)
282 {
283  int numElements = numElementsDefined();
284  int numIsotopes = numIsotopesDefined();
285  string symbol = trimCopy(ename);
286  for (int i = 0; i < numElements; i++) {
287  if (symbol == atomicWeightTable[i].symbol) {
288  return atomicWeightTable[i].fullName;
289  }
290  }
291  for (int i = 0; i < numIsotopes; i++) {
292  if (symbol == isotopeWeightTable[i].symbol) {
293  return isotopeWeightTable[i].fullName;
294  }
295  }
296  throw CanteraError("getElementName", "element not found: " + ename);
297 }
298 
299 string getElementName(int atomicNumber)
300 {
301  int num = numElementsDefined();
302  if (atomicNumber > num || atomicNumber < 1) {
303  throw IndexError("getElementName", "atomicWeightTable", atomicNumber,
304  num);
305  }
306  return atomicWeightTable[atomicNumber - 1].fullName;
307 }
308 
309 int getAtomicNumber(const std::string& ename)
310 {
311  int numElements = numElementsDefined();
312  int numIsotopes = numIsotopesDefined();
313  string symbol = trimCopy(ename);
314  string name = toLowerCopy(symbol);
315  for (int i = 0; i < numElements; i++) {
316  if (symbol == atomicWeightTable[i].symbol) {
317  return i+1;
318  } else if (name == atomicWeightTable[i].fullName) {
319  return i+1;
320  }
321  }
322  for (int i = 0; i < numIsotopes; i++) {
323  if (symbol == isotopeWeightTable[i].symbol) {
325  } else if (name == isotopeWeightTable[i].fullName) {
327  }
328  }
329  throw CanteraError("getAtomicNumber", "element not found: " + ename);
330 }
331 
333 {
334  return sizeof(atomicWeightTable) / sizeof(struct atomicWeightData);
335 }
336 
338 {
339  return sizeof(isotopeWeightTable) / sizeof(struct isotopeWeightData);
340 }
341 
342 }
Contains the getElementWeight function and the definitions of element constraint types.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
An array index is out of range.
Definition: ctexceptions.h:158
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
const double Avogadro
Avogadro's Number [number/kmol].
Definition: ct_defs.h:63
const double ElectronMass
Electron Mass [kg].
Definition: ct_defs.h:95
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
static struct atomicWeightData atomicWeightTable[]
atomicWeightTable is a vector containing the atomic weights database.
Definition: Elements.cpp:69
int numIsotopesDefined()
Get the number of named isotopes defined in Cantera.
Definition: Elements.cpp:337
int getAtomicNumber(const std::string &ename)
Get the atomic number for an element.
Definition: Elements.cpp:309
std::string trimCopy(const std::string &input)
Trim.
std::string toLowerCopy(const std::string &input)
Convert to lower case.
string getElementName(int atomicNumber)
Get the name of an element.
Definition: Elements.cpp:299
double getElementWeight(int atomicNumber)
Get the atomic weight of an element.
Definition: Elements.cpp:239
int numElementsDefined()
Get the number of named elements defined in Cantera.
Definition: Elements.cpp:332
string getElementSymbol(int atomicNumber)
Get the symbol for an element.
Definition: Elements.cpp:271
static struct isotopeWeightData isotopeWeightTable[]
isotopeWeightTable is a vector containing the atomic weights database.
Definition: Elements.cpp:199
Contains declarations for string manipulation functions within Cantera.
string fullName
Element full name, first letter lowercase.
Definition: Elements.cpp:37
string symbol
Element symbol, first letter capitalized.
Definition: Elements.cpp:36
double atomicWeight
Element atomic weight in kg / kg-mol, if known. -1 if no stable isotope.
Definition: Elements.cpp:38
int atomicNumber
Isotope atomic number.
Definition: Elements.cpp:57
string fullName
Isotope full name, first letter lowercase.
Definition: Elements.cpp:55
string symbol
Isotope symbol, first letter capitalized.
Definition: Elements.cpp:54
double atomicWeight
Isotope atomic weight in kg / kg-mol.
Definition: Elements.cpp:56