00001 /** 00002 * @file Elements.h 00003 * Header file for class, Elements, which contains the elements that 00004 * make up species (see \ref phases and \link Cantera::Elements Elements\endlink). 00005 * 00006 * This file contains the declarations for the elements class. 00007 */ 00008 /*********************************************************************** 00009 * $RCSfile: Elements.h,v $ 00010 * $Author: hkmoffa $ 00011 * $Date: 2010-01-17 12:55:28 -0500 (Sun, 17 Jan 2010) $ 00012 * $Revision: 386 $ 00013 ***********************************************************************/ 00014 // Copyright 2001 California Institute of Technology 00015 00016 #ifndef CT_ELEMENTS_H 00017 #define CT_ELEMENTS_H 00018 00019 #undef USE_DGG_CODE 00020 00021 #include "ct_defs.h" 00022 00023 00024 namespace Cantera { 00025 00026 class XML_Node; 00027 class ElementRangeError; 00028 00029 //! Positive number indicating we don't know the gibbs free energy 00030 //! of the element in its most stable state at 298.15 K and 1 bar. 00031 //#define GIBSSFE298_UNKNOWN 123456789. 00032 #define ENTROPY298_UNKNOWN -123456789. 00033 00034 //! Object containing the elements that make up species in a phase. 00035 /*! 00036 * Class %Elements manages the elements that are part of a 00037 * chemistry specification. This class may support calculations 00038 * employing Multiple phases. In this case, a single Elements object may 00039 * be shared by more than one Constituents class. Reactions between 00040 * the phases may then be described using stoichiometry base on the 00041 * same Elements class object. 00042 * 00043 * The member functions return information about the elements described 00044 * in a particular instantiation of the class. 00045 * 00046 * @ingroup phases 00047 */ 00048 class Elements { 00049 00050 public: 00051 00052 //! Default constructor for the elements class 00053 Elements(); 00054 00055 //! Default destructor for the elements class 00056 ~Elements(); 00057 00058 00059 //! copy constructor 00060 /*! 00061 * This copy constructor just calls the assignment operator for this 00062 * class. It sets the number of subscribers to zer0. 00063 * 00064 * @param right Reference to the object to be copied. 00065 */ 00066 Elements(const Elements& right); 00067 00068 //! Assigntment operator 00069 /*! 00070 * This is the assignment operator for the Elements class. 00071 * Right now we pretty much do a straight uncomplicated 00072 * assignment. However, subscribers are not mucked with, as they 00073 * have to do with the address of the object to be subscribed to 00074 * 00075 * @param right Reference to the object to be copied. 00076 */ 00077 Elements& operator=(const Elements& right); 00078 00079 00080 //! Static function to look up an atomic weight 00081 /*! 00082 * This static function looks up the argument string in the 00083 * database above and returns the associated molecular weight. 00084 * The data are from the periodic table. 00085 * 00086 * Note: The idea behind this function is to provide a unified 00087 * source for the element atomic weights. This helps to 00088 * ensure that mass is conserved. 00089 * 00090 * @param ename String, Only the first 3 characters are significant 00091 * 00092 * @return 00093 * Return value contains the atomic weight of the element 00094 * If a match for the string is not found, a value of -1.0 is 00095 * returned. 00096 * 00097 * @exception CanteraError 00098 * If a match is not found, a CanteraError is thrown as well 00099 */ 00100 static double LookupWtElements(const std::string &ename); 00101 00102 /// Atomic weight of element m. 00103 /*! 00104 * @param m element index 00105 */ 00106 doublereal atomicWeight(int m) const { return m_atomicWeights[m]; } 00107 00108 /// Atomic number of element m. 00109 /*! 00110 * @param m element index 00111 */ 00112 int atomicNumber(int m) const { return m_atomicNumbers[m]; } 00113 00114 //! Entropy at 298.15 K and 1 bar of stable state 00115 //! of the element 00116 /*! 00117 * units J kmol-1 K-1 00118 * 00119 * @param m Element index 00120 */ 00121 doublereal entropyElement298(int m) const; 00122 00123 /// vector of element atomic weights 00124 const vector_fp& atomicWeights() const { return m_atomicWeights; } 00125 00126 /** 00127 * Inline function that returns the number of elements in the object. 00128 * 00129 * @return 00130 * \c int: The number of elements in the object. 00131 */ 00132 int nElements() const { return m_mm; } 00133 00134 //! Function that returns the index of an element. 00135 /*! 00136 * Index of element named \c name. The index is an integer 00137 * assigned to each element in the order it was added, 00138 * beginning with 0 for the first element. If \c name is not 00139 * the name of an element in the set, then the value -1 is 00140 * returned. 00141 * 00142 * @param name String containing the index. 00143 */ 00144 int elementIndex(std::string name) const; 00145 00146 //! Name of the element with index \c m. 00147 /*! 00148 * @param m Element index. If m < 0 or m >= nElements() an exception is thrown. 00149 */ 00150 std::string elementName(int m) const; 00151 00152 //! Returns a string vector containing the element names 00153 /*! 00154 * Returns a read-only reference to the vector of element names. 00155 * @return <tt> const vector<string>& </tt>: The vector contains 00156 * the element names in their indexed order. 00157 */ 00158 const std::vector<std::string>& elementNames() const { 00159 return m_elementNames; 00160 } 00161 00162 //! Add an element to the current set of elements in the current object. 00163 /*! 00164 * The default weight is a special value, which will cause the 00165 * routine to look up the actual weight via a string lookup. 00166 * 00167 * There are two interfaces to this routine. The XML interface 00168 * looks up the required parameters for the regular interface 00169 * and then calls the base routine. 00170 * 00171 * @param symbol string symbol for the element. 00172 * @param weight Atomic weight of the element. If no argument 00173 * is provided, a lookup is attempted. 00174 */ 00175 void addElement(const std::string& symbol, 00176 doublereal weight = -12345.0); 00177 00178 //! Add an element to the current set of elements in the current object. 00179 /*! 00180 * @param e Reference to the XML_Node containing the element information 00181 * The node name is the element symbol and the atomWt attribute 00182 * is used as the atomic weight. 00183 */ 00184 void addElement(const XML_Node& e); 00185 00186 //! Add an element only if the element hasn't been added before. 00187 /*! 00188 * This is accomplished via a string match on symbol. 00189 * 00190 * @param symbol string symbol for the element. 00191 * @param weight Atomic weight of the element. If no argument 00192 * is provided, a lookup is attempted. 00193 * @param atomicNumber defaults to 0 00194 * @param entropy298 Value of the entropy at 298 and 1 bar of the 00195 * element in its most stable form. 00196 * The default is to specify an ENTROPY298_UNKNOWN value, 00197 * which will cause a throw error if its ever 00198 * needed. 00199 */ 00200 void addUniqueElement(const std::string& symbol, 00201 doublereal weight = -12345.0, int atomicNumber = 0, 00202 doublereal entropy298 = ENTROPY298_UNKNOWN); 00203 00204 //! Add an element to the current set of elements in the current object. 00205 /*! 00206 * @param e Reference to the XML_Node containing the element information 00207 * The node name is the element symbol and the atomWt attribute 00208 * is used as the atomic weight. 00209 */ 00210 void addUniqueElement(const XML_Node& e); 00211 00212 //! Add multiple elements from a XML_Node phase description 00213 /*! 00214 * @param phase XML_Node reference to a phase 00215 */ 00216 void addElementsFromXML(const XML_Node& phase); 00217 00218 //! Prohibit addition of more elements, and prepare to add species. 00219 void freezeElements(); 00220 00221 /// True if freezeElements has been called. 00222 bool elementsFrozen() { return m_elementsFrozen; } 00223 00224 /// Remove all elements 00225 void clear(); 00226 00227 /// True if both elements and species have been frozen 00228 bool ready() const; 00229 00230 00231 //! subscribe to this object 00232 /*! 00233 * Increment by one the number of subscriptions to this object. 00234 */ 00235 void subscribe(); 00236 00237 //! unsubscribe to this object 00238 /*! 00239 * decrement by one the number of subscriptions to this object. 00240 */ 00241 int unsubscribe(); 00242 00243 //! report the number of subscriptions 00244 int reportSubscriptions() const; 00245 00246 protected: 00247 00248 /******************************************************************/ 00249 /* Description of DATA in the Object */ 00250 /******************************************************************/ 00251 00252 //! Number of elements. 00253 int m_mm; 00254 00255 /* m_elementsFrozen: */ 00256 /** boolean indicating completion of object 00257 * 00258 * If this is true, then no elements may be added to the 00259 * object. 00260 */ 00261 bool m_elementsFrozen; 00262 00263 /** 00264 * Vector of element atomic weights: 00265 * 00266 * units = kg / kmol 00267 */ 00268 vector_fp m_atomicWeights; 00269 00270 /** 00271 * Vector of element atomic numbers: 00272 * 00273 */ 00274 vector_int m_atomicNumbers; 00275 00276 /** Vector of strings containing the names of the elements 00277 * 00278 * Note, a string search is the primary way to identify elements. 00279 */ 00280 std::vector<std::string> m_elementNames; 00281 00282 //! Entropy at 298.15 K and 1 bar of stable state 00283 /*! 00284 * units J kmol-1 00285 */ 00286 vector_fp m_entropy298; 00287 00288 /** 00289 * Number of Constituents Objects that use this object 00290 * 00291 * Number of Constituents Objects that require this Elements object 00292 * to complete its definition. 00293 * The destructor checks to see that this is equal to zero. 00294 * when the element object is released. 00295 */ 00296 int numSubscribers; 00297 00298 /********* GLOBAL STATIC SECTION *************/ 00299 00300 public: 00301 /** Vector of pointers to Elements Objects 00302 * 00303 */ 00304 static std::vector<Elements *> Global_Elements_List; 00305 00306 friend class Constituents; 00307 }; 00308 00309 } // namespace 00310 00311 #endif