Cantera  2.0
Elements.h
Go to the documentation of this file.
1 /**
2  * @file Elements.h
3  * Contains the LookupWtElements function and the definitions of element
4  * constraint types.
5  */
6 // Copyright 2001 California Institute of Technology
7 
8 #ifndef CT_ELEMENTS_H
9 #define CT_ELEMENTS_H
10 
11 #include "cantera/base/ct_defs.h"
12 
13 namespace Cantera
14 {
15 
16 /*!
17  * @name Types of Element Constraint Equations
18  *
19  * There may be several different types of element constraints handled
20  * by the equilibrium program and by Cantera in other contexts.
21  * These defines are used to assign each constraint to one category.
22  * @{
23  */
24 
25 //! An element constraint that is current turned off
26 #define CT_ELEM_TYPE_TURNEDOFF -1
27 
28 //! Normal element constraint consisting of positive coefficients for the
29 //! formula matrix.
30 /*!
31  * All species have positive coefficients within the formula matrix.
32  * With this constraint, we may employ various strategies to handle
33  * small values of the element number successfully.
34  */
35 #define CT_ELEM_TYPE_ABSPOS 0
36 
37 //! This refers to conservation of electrons
38 /*!
39  * Electrons may have positive or negative values in the Formula matrix.
40  */
41 #define CT_ELEM_TYPE_ELECTRONCHARGE 1
42 
43 //! This refers to a charge neutrality of a single phase
44 /*!
45  * Charge neutrality may have positive or negative values in the Formula matrix.
46  */
47 #define CT_ELEM_TYPE_CHARGENEUTRALITY 2
48 
49 //! Constraint associated with maintaining a fixed lattice stoichiometry in a solid
50 /*!
51  * The constraint may have positive or negative values. The lattice 0 species will
52  * have negative values while higher lattices will have positive values
53  */
54 #define CT_ELEM_TYPE_LATTICERATIO 3
55 
56 //! Constraint associated with maintaining frozen kinetic equilibria in
57 //! some functional groups within molecules
58 /*!
59  * We seek here to say that some functional groups or ionic states should be
60  * treated as if they are separate elements given the time scale of the problem.
61  * This will be abs positive constraint. We have not implemented any examples yet.
62  * A requirement will be that we must be able to add and subtract these constraints.
63  */
64 #define CT_ELEM_TYPE_KINETICFROZEN 4
65 
66 //! Constraint associated with the maintenance of a surface phase
67 /*!
68  * We don't have any examples of this yet either. However, surfaces only exist
69  * because they are interfaces between bulk layers. If we want to treat surfaces
70  * within thermodynamic systems we must come up with a way to constrain their total
71  * number.
72  */
73 #define CT_ELEM_TYPE_SURFACECONSTRAINT 5
74 
75 //! Other constraint equations
76 /*!
77  * currently there are none
78  */
79 #define CT_ELEM_TYPE_OTHERCONSTRAINT 6
80 //@}
81 
82 //! Number indicating we don't know the entropy of the element in its most
83 //! stable state at 298.15 K and 1 bar.
84 #define ENTROPY298_UNKNOWN -123456789.
85 
86 //! Function to look up an atomic weight
87 //! This function looks up the argument string in the database above and
88 //! returns the associated molecular weight.
89 //! The data are from the periodic table.
90 //!
91 //! Note: The idea behind this function is to provide a unified source for the
92 //! element atomic weights. This helps to ensure that mass is conserved.
93 //! @param ename String, Only the first 3 characters are significant
94 //! @return The atomic weight of the element
95 //! @exception CanteraError If a match is not found, throws a CanteraError
96 double LookupWtElements(const std::string& ename);
97 
98 class XML_Node;
99 
100 //! Object containing the elements that make up species in a phase.
101 /*!
102  * Class %Elements manages the elements that are part of a
103  * chemistry specification. This class may support calculations
104  * employing Multiple phases. In this case, a single Elements object may
105  * be shared by more than one Constituents class. Reactions between
106  * the phases may then be described using stoichiometry base on the
107  * same Elements class object.
108  *
109  * The member functions return information about the elements described
110  * in a particular instantiation of the class.
111  *
112  * @ingroup phases
113  */
114 class Elements
115 {
116 
117 public:
118 
119  //! Default constructor for the elements class
120  Elements();
121 
122  //! Default destructor for the elements class
123  ~Elements();
124 
125 
126  //! copy constructor
127  /*!
128  * This copy constructor just calls the assignment operator for this
129  * class. It sets the number of subscribers to zer0.
130  *
131  * @param right Reference to the object to be copied.
132  */
133  Elements(const Elements& right);
134 
135  //! Assignment operator
136  /*!
137  * This is the assignment operator for the Elements class.
138  * Right now we pretty much do a straight uncomplicated
139  * assignment. However, subscribers are not mucked with, as they
140  * have to do with the address of the object to be subscribed to
141  *
142  * @param right Reference to the object to be copied.
143  */
144  Elements& operator=(const Elements& right);
145 
146 
147  //! Static function to look up an atomic weight
148  /*!
149  * This static function looks up the argument string in the
150  * database above and returns the associated molecular weight.
151  * The data are from the periodic table.
152  *
153  * Note: The idea behind this function is to provide a unified
154  * source for the element atomic weights. This helps to
155  * ensure that mass is conserved.
156  *
157  * @param ename String, Only the first 3 characters are significant
158  *
159  * @return
160  * Return value contains the atomic weight of the element
161  * If a match for the string is not found, a value of -1.0 is
162  * returned.
163  *
164  * @exception CanteraError
165  * If a match is not found, a CanteraError is thrown as well
166  */
167  static double LookupWtElements(const std::string& ename);
168  /// Atomic weight of element m.
169  /*!
170  * @param m element index
171  */
172  doublereal atomicWeight(int m) const {
173  return m_atomicWeights[m];
174  }
175 
176  /// Atomic number of element m.
177  /*!
178  * @param m element index
179  */
180  int atomicNumber(int m) const {
181  return m_atomicNumbers[m];
182  }
183 
184  //! Entropy at 298.15 K and 1 bar of stable state
185  //! of the element
186  /*!
187  * units J kmol-1 K-1
188  *
189  * @param m Element index
190  */
191  doublereal entropyElement298(int m) const;
192 
193  //! Return the element constraint type
194  /*!
195  * Possible types include:
196  *
197  * CT_ELEM_TYPE_ABSPOS 0
198  * CT_ELEM_TYPE_ELECTRONCHARGE 1
199  * CT_ELEM_TYPE_CHARGENEUTRALITY 2
200  * CT_ELEM_TYPE_LATTICERATIO 3
201  * CT_ELEM_TYPE_KINETICFROZEN 4
202  * CT_ELEM_TYPE_SURFACECONSTRAINT 5
203  * CT_ELEM_TYPE_OTHERCONSTRAINT 6
204  *
205  * The default is CT_ELEM_TYPE_ABSPOS
206  *
207  * @param m Element index
208  *
209  * @return Returns the element type
210  */
211  int elementType(int m) const;
212 
213  //! Change the element type of the mth constraint
214  /*!
215  * Reassigns an element type
216  *
217  * @param m Element index
218  * @param elem_type New elem type to be assigned
219  *
220  * @return Returns the old element type
221  */
222  int changeElementType(int m, int elem_type);
223 
224  /// vector of element atomic weights
225  const vector_fp& atomicWeights() const {
226  return m_atomicWeights;
227  }
228  /**
229  * Inline function that returns the number of elements in the object.
230  *
231  * @return
232  * \c int: The number of elements in the object.
233  */
234  int nElements() const {
235  return m_mm;
236  }
237 
238  //! Function that returns the index of an element.
239  /*!
240  * Index of element named \c name. The index is an integer
241  * assigned to each element in the order it was added,
242  * beginning with 0 for the first element. If \c name is not
243  * the name of an element in the set, then the value -1 is
244  * returned.
245  *
246  * @param name String containing the index.
247  */
248  int elementIndex(std::string name) const;
249 
250  //! Name of the element with index \c m.
251  /*!
252  * @param m Element index. If m < 0 or m >= nElements() an exception is thrown.
253  */
254  std::string elementName(int m) const;
255 
256  //! Returns a string vector containing the element names
257  /*!
258  * Returns a read-only reference to the vector of element names.
259  * @return <tt> const vector<string>& </tt>: The vector contains
260  * the element names in their indexed order.
261  */
262  const std::vector<std::string>& elementNames() const {
263  return m_elementNames;
264  }
265 
266  //! Add an element to the current set of elements in the current object.
267  /*!
268  * The default weight is a special value, which will cause the
269  * routine to look up the actual weight via a string lookup.
270  *
271  * There are two interfaces to this routine. The XML interface
272  * looks up the required parameters for the regular interface
273  * and then calls the base routine.
274  *
275  * @param symbol string symbol for the element.
276  * @param weight Atomic weight of the element. If no argument
277  * is provided, a lookup is attempted.
278  */
279  void addElement(const std::string& symbol,
280  doublereal weight = -12345.0);
281  //! Add an element to the current set of elements in the current object.
282  /*!
283  * @param e Reference to the XML_Node containing the element information
284  * The node name is the element symbol and the atomWt attribute
285  * is used as the atomic weight.
286  */
287  void addElement(const XML_Node& e);
288 
289  //! Add an element only if the element hasn't been added before.
290  /*!
291  * This is accomplished via a string match on symbol.
292  *
293  * @param symbol string symbol for the element.
294  * @param weight Atomic weight of the element. If no argument
295  * is provided, a lookup is attempted.
296  * @param atomicNumber defaults to 0
297  * @param entropy298 Value of the entropy at 298 and 1 bar of the
298  * element in its most stable form.
299  * The default is to specify an ENTROPY298_UNKNOWN value,
300  * which will cause a throw error if its ever
301  * needed.
302  * @param elem_type New elem type to be assigned.
303  * The default is a regular element, CT_ELEM_TYPE_ABSPOS
304  */
305  void addUniqueElement(const std::string& symbol,
306  doublereal weight = -12345.0, int atomicNumber = 0,
307  doublereal entropy298 = ENTROPY298_UNKNOWN, int elem_type = CT_ELEM_TYPE_ABSPOS);
308 
309  //! Add an element to the current set of elements in the current object.
310  /*!
311  * @param e Reference to the XML_Node containing the element information
312  * The node name is the element symbol and the atomWt attribute
313  * is used as the atomic weight.
314  */
315  void addUniqueElement(const XML_Node& e);
316 
317  //! Add multiple elements from a XML_Node phase description
318  /*!
319  * @param phase XML_Node reference to a phase
320  */
321  void addElementsFromXML(const XML_Node& phase);
322 
323  //! Prohibit addition of more elements, and prepare to add species.
324  void freezeElements();
325 
326  //! True if freezeElements has been called.
327  bool elementsFrozen() const;
328 
329  /// Remove all elements
330  void clear();
331 
332  /// True if both elements and species have been frozen
333  bool ready() const;
334 
335  //! subscribe to this object
336  /*!
337  * Increment by one the number of subscriptions to this object.
338  */
339  void subscribe();
340 
341  //! unsubscribe to this object
342  /*!
343  * decrement by one the number of subscriptions to this object.
344  */
345  int unsubscribe();
346 
347  //! report the number of subscriptions
348  int reportSubscriptions() const;
349 
350 protected:
351 
352  /******************************************************************/
353  /* Description of DATA in the Object */
354  /******************************************************************/
355 
356  //! Number of elements.
357  int m_mm;
358 
359  /* m_elementsFrozen: */
360  /** boolean indicating completion of object
361  *
362  * If this is true, then no elements may be added to the
363  * object.
364  */
366 
367  /**
368  * Vector of element atomic weights:
369  *
370  * units = kg / kmol
371  */
373 
374  /**
375  * Vector of element atomic numbers:
376  *
377  */
379 
380  /** Vector of strings containing the names of the elements
381  *
382  * Note, a string search is the primary way to identify elements.
383  */
384  std::vector<std::string> m_elementNames;
385 
386  //! Entropy at 298.15 K and 1 bar of stable state
387  /*!
388  * units J kmol-1
389  */
391 
392  //! Vector of element types
394  /**
395  * Number of Constituents Objects that use this object
396  *
397  * Number of Constituents Objects that require this Elements object
398  * to complete its definition.
399  * The destructor checks to see that this is equal to zero.
400  * when the element object is released.
401  */
403 
404  /********* GLOBAL STATIC SECTION *************/
405 
406 public:
407  /** Vector of pointers to Elements Objects
408  *
409  */
410  static std::vector<Elements*> Global_Elements_List;
411 
412  friend class Constituents;
413 };
414 
415 
416 } // namespace
417 
418 #endif