Constituents.h

Go to the documentation of this file.
00001 /**
00002  * @file Constituents.h
00003  *  Header file  Class \link Cantera::Constituents Constitutents\endlink which 
00004  *  manages a set of elements and species (see \ref phases).
00005  */
00006 
00007 /*  
00008  *  $Date: 2009-12-09 12:29:23 -0500 (Wed, 09 Dec 2009) $
00009  *  $Revision: 306 $
00010  */
00011 
00012 //  Copyright 2001  California Institute of Technology
00013 
00014 
00015 #ifndef CT_CONSTIT_H
00016 #define CT_CONSTIT_H
00017 
00018 
00019 #include "ct_defs.h"
00020 
00021 #include "SpeciesThermo.h"
00022 #include "ctexceptions.h"
00023 #include "stringUtils.h"
00024 #include "xml.h"
00025 #include "Elements.h"
00026 
00027 namespace Cantera {
00028 
00029   class Elements;
00030 
00031   /************** DEFINITIONS OF ERRORS *****************************/
00032 
00033   //! Specific fatal error indicating that the index of a species is out of range.
00034   /*!
00035    *
00036    *  @ingroup errorhandling
00037    */
00038   class SpeciesRangeError : public CanteraError {
00039   public:
00040     //! Constructor
00041     /*!
00042      *  @param func Function where the error occurred.
00043      *  @param k    current species index value
00044      *  @param kmax Maximum permissible species index value. The
00045      *              minimum permissible species index value is assumed to be 0
00046      *
00047      */
00048     SpeciesRangeError(std::string func, int k, int kmax) :
00049       CanteraError(func, "Species index " + int2str(k) + 
00050                    " outside valid range of 0 to " + int2str(kmax-1)) {}
00051   };
00052 
00053   /******************************************************************/
00054 
00055 
00056   //! Class %Constituents manages a set of elements and  species.
00057   /*!
00058    * Class %Constituents is designed to provide information
00059    * about the elements and species in a phase - names, index
00060    * numbers (location in arrays), atomic or molecular weights,
00061    * etc. No computations are performed by the methods of this
00062    * class. The set of elements must include all those that compose
00063    * the species, but may include additional elements. The species
00064    * all must belong to the same phase.
00065    *
00066    * @ingroup phases
00067    */
00068   class Constituents {
00069 
00070   public:
00071 
00072     //! Constructor.
00073     /*!
00074      *  Constructor sets all base variable types to zero. Also, it
00075      *  sets the pointer to the Elements object for this object.
00076      *
00077      * @param ptr_Elements
00078      *   The default is that a new Elements object is created, so this
00079      *   Constituents object is independent of any other object. But if
00080      *   ptr_Elements is supplied, it will be used. This way, a class
00081      *   implementing a multi-phase mixture is responsible for
00082      *   maintaining the global elements list for the mixture, and no
00083      *   static global element list is required.
00084      */
00085     Constituents(Elements* ptr_Elements = 0);
00086        
00087     /// Destructor. 
00088     ~Constituents();
00089 
00090     ///  This copy constructor just calls the assignment operator
00091     ///  for this class.
00092     /*!
00093      * @param right     reference to the object to be copied.
00094      */
00095     Constituents(const Constituents& right);
00096 
00097     /// Assignment operator
00098     /*!
00099      *  @param right    Reference to the object to be copied.
00100      */
00101     Constituents& operator=(const Constituents& right);
00102 
00103     /// @name Element Information
00104     // @{
00105         
00106     /// Name of the element with index m.
00107     ///   This is a passthrough routine to the Element object.
00108     ///   \param m  Element index. 
00109     ///   \exception If m < 0 or m >= nElements(), the
00110     ///          exception, ElementRangeError, is thrown.
00111     std::string elementName(int m) const;
00112 
00113 
00114     /// Index of element named 'name'.
00115     /// The index is an integer
00116     /// assigned to each element in the order it was added,
00117     /// beginning with 0 for the first element. 
00118     /// @param name  name of the element 
00119     ///
00120     /// If 'name' is not
00121     /// the name of an element in the set, then the value -1 is
00122     /// returned.
00123     int elementIndex(std::string name) const;
00124 
00125 
00126     /// Atomic weight of element m.
00127     /*!
00128      * @param m  Element index
00129      */
00130     doublereal atomicWeight(int m) const;
00131 
00132     /// Entropy of the element in its standard state at 298 K and 1 bar
00133     /*!
00134      * @param m  Element index
00135      */
00136     doublereal entropyElement298(int m) const;
00137 
00138     /// Atomic number of element m.
00139     /*!
00140      *  @param m Element index
00141      */
00142     int atomicNumber(int m) const;
00143 
00144     /// Return a read-only reference to the vector of element names.
00145     const std::vector<std::string>& elementNames() const;
00146 
00147     /// Return a read-only reference to the vector of atomic weights.
00148     const vector_fp& atomicWeights() const;
00149 
00150     /// Number of elements.
00151     int nElements() const;
00152        
00153     // @}
00154 
00155 
00156 
00157     /// @name Adding Elements and Species
00158     /// These methods are used to add new elements or species.
00159     /// These are not usually called by user programs.
00160     /// 
00161     /// Since species are checked to insure that they are only 
00162     /// composed of declared elements, it is necessary to first
00163     /// add all elements before adding any species. 
00164 
00165     //@{
00166 
00167     //! Add an element. 
00168     /*!
00169      *  @param symbol Atomic symbol std::string.
00170      *  @param weight Atomic mass in amu.
00171      */
00172     void addElement(const std::string& symbol, doublereal weight);
00173       
00174     //! Add an element from an XML specification.
00175     /*!
00176      * @param e Reference to the XML_Node where the element is described.
00177      */
00178     void addElement(const XML_Node& e);
00179 
00180     //! Add an element, checking for uniqueness
00181     /*!
00182      * The uniqueness is checked by comparing the string symbol. If
00183      * not unique, nothing is done.
00184      *
00185      * @param symbol  String symbol of the element
00186      * @param weight  Atomic weight of the element (kg kmol-1).
00187      * @param atomicNumber Atomic number of the element (unitless)
00188      * @param entropy298 Entropy of the element at 298 K and 1 bar
00189      *                   in its most stable form. The default is
00190      *                   the value ENTROPY298_UNKNOWN, which is 
00191      *                   interpreted as an unknown, and if used
00192      *                   will cause Cantera to throw an error.
00193      */
00194     void addUniqueElement(const std::string& symbol, doublereal weight,
00195                           int atomicNumber = 0,
00196                           doublereal entropy298 = ENTROPY298_UNKNOWN);
00197 
00198     //! Adde an element, checking for uniqueness
00199     /*!
00200      * The uniqueness is checked by comparing the string symbol. If
00201      * not unique, nothing is done.
00202      *
00203      * @param e Reference to the XML_Node where the element is described.
00204      */
00205     void addUniqueElement(const XML_Node& e);
00206 
00207     //! Add all elements referenced in an XML_Node tree
00208     /*!
00209      * @param phase Reference to the top  XML_Node of a phase
00210      */
00211     void addElementsFromXML(const XML_Node& phase);
00212    
00213     /// Prohibit addition of more elements, and prepare to add species.
00214     void freezeElements();
00215 
00216     /// True if freezeElements has been called.
00217     bool elementsFrozen();
00218 
00219     //@}
00220       
00221     /// Returns the number of species in the phase
00222     int nSpecies() const { return m_kk; }
00223 
00224     //! Molecular weight of species \c k.
00225     /*!
00226      * @param k   index of species \c k
00227      * @return
00228      *      Returns the molecular weight of species \c k.
00229      */
00230     doublereal molecularWeight(int k) const;
00231 
00232     //! Return the Molar mass of species \c k
00233     /*!
00234      * Preferred name for molecular weight.
00235      *
00236      * @param k  index for species
00237      * @return
00238      *      Return the molar mass of species k kg/kmol.
00239      */
00240     doublereal molarMass(int k) const {
00241       return molecularWeight(k);
00242     }
00243 
00244     /**
00245      * Return a const reference to the vector of molecular weights
00246      * of the species
00247      */
00248     const vector_fp& molecularWeights() const;
00249        
00250     /*!
00251      *   Electrical charge of one species k molecule, divided by
00252      *   the magnitude of the electron charge ( \f$ e = 1.602
00253      *   \times 10^{-19}\f$ Coulombs). Dimensionless.
00254      *
00255      * @param k species index
00256      */
00257     doublereal charge(int k) const;
00258 
00259     /**
00260      * @name Adding Species
00261      * These methods are used to add new species.
00262      * They are not usually called by user programs.
00263      */
00264     //@{
00265     void addSpecies(const std::string& name, const doublereal* comp,
00266                     doublereal charge = 0.0, doublereal size = 1.0);
00267 
00268     //! Add a species to the phase, checking for uniqueness of the name
00269     /*!
00270      * This routine checks for uniqueness of the string name. It only
00271      * adds the species if it is unique.
00272      *
00273      * @param name    String name of the species
00274      * @param  comp   Double vector containing the elemental composition of the
00275      *                species.
00276      * @param charge  Charge of the species. Defaults to zero.
00277      * @param size    Size of the species (meters). Defaults to 1 meter.
00278      */
00279     void addUniqueSpecies(const std::string& name, const doublereal* comp,
00280                           doublereal charge = 0.0, 
00281                           doublereal size = 1.0);
00282       
00283     //! Index of species named 'name'
00284     /*!
00285      * The first species added
00286      * will have index 0, and the last one index nSpecies() - 1.
00287      *
00288      * @param name String name of the species
00289      * @return 
00290      *    Returns the index of the species.
00291      */
00292     int speciesIndex(std::string name) const;
00293 
00294     //! Name of the species with index k
00295     /*!
00296      * @param k index of the species
00297      */
00298     std::string speciesName(int k) const;
00299        
00300     /// Return a const referernce to the vector of species names
00301     const std::vector<std::string>& speciesNames() const;
00302       
00303     //!  This routine returns the size of species k
00304     /*!
00305      * @param k index of the species 
00306      * @return 
00307      *      Returns the size of the species. Units are meters.
00308      */
00309     doublereal size(int k) const { return m_speciesSize[k]; }
00310 
00311     /**
00312      * Prohibit addition of more species, and prepare for
00313      * calculations with this set of elements and species.
00314      */
00315     void freezeSpecies();
00316 
00317     /// True if freezeSpecies has been called.
00318     bool speciesFrozen() { return m_speciesFrozen; }
00319 
00320     /// Remove all elements and species
00321     void clear();
00322 
00323     //@}
00324 
00325     /// True if both elements and species have been frozen
00326     bool ready() const;
00327 
00328     //! Number of atoms of element \c m in species \c k.
00329     /*!
00330      * @param k    species index
00331      * @param m    element index
00332      */
00333     doublereal nAtoms(int k, int m) const;
00334 
00335     //! Get a vector containing the atomic composition  of species k
00336     /*!
00337      * @param  k         species index
00338      * @param atomArray  vector containing the atomic number in the species.
00339      *                   Length: m_mm
00340      */
00341     void getAtoms(int k, double *atomArray) const;
00342     
00343   protected:
00344     
00345     //! Number of species in the phase.
00346     int                            m_kk;
00347     //! Vector of molecular weights of the species
00348     /*!
00349      * This vector has length m_kk.
00350      * The units of the vector are kg kmol-1.
00351      */
00352     vector_fp                      m_weight;
00353 
00354     //! Boolean indicating whether the number of species has been frozen.
00355     /*!
00356      * During the construction of the phase, this is false. After
00357      * construction of the the phase, this is true.
00358      */
00359     bool                           m_speciesFrozen;
00360 
00361     /*!
00362      * Pointer to the element object corresponding to this
00363      * phase. Normally, this will be the default Element object
00364      * common to all phases.
00365      */
00366     Elements *                     m_Elements;
00367 
00368     //! Vector of the species names
00369     std::vector<std::string>                 m_speciesNames;
00370 
00371     //! Atomic composition of the species.
00372     /*!
00373      * the number of atoms of i in species k is equal to
00374      * m_speciesComp[k * m_mm + i]
00375      * The length of this vector is equal to m_kk * m_mm
00376      */
00377     vector_fp                      m_speciesComp;
00378 
00379     /**
00380      * m_speciesCharge: Vector of species charges
00381      *           length = m_kk
00382      */
00383     vector_fp                      m_speciesCharge;
00384 
00385     /**
00386      * m_speciesSize(): Vector of species sizes.
00387      *           length m_kk
00388      *           This is used in some equations of state
00389      *           which employ the constant partial molar
00390      *           volume approximation. It's so fundamental
00391      *           we've put it at the Constituents class level
00392      */
00393     vector_fp                      m_speciesSize;
00394 
00395   private:
00396 
00397   };  
00398     
00399     
00400 }  // namespace
00401 
00402 #endif
Generated by  doxygen 1.6.3