Phase.h

Go to the documentation of this file.
00001 /**
00002  *  @file Phase.h
00003  *
00004  *   Header file for class, Phase, which contains functions for
00005  *   setting the state of a phase, and for referencing species by
00006  *   name, and also contains text for the module phases (see \ref
00007  *   phases and class \link Cantera::Phase Phase\endlink).
00008  */
00009 
00010 /*
00011  * $Author: hkmoffa $
00012  * $Revision: 306 $
00013  * $Date: 2009-12-09 12:29:23 -0500 (Wed, 09 Dec 2009) $
00014  */
00015 // Copyright 2001  California Institute of Technology
00016 
00017 #ifndef CT_PHASE_H
00018 #define CT_PHASE_H
00019 
00020 #include "State.h"
00021 #include "Constituents.h"
00022 #include "vec_functions.h"
00023 
00024 #include "ctml.h"
00025 using namespace ctml;
00026 
00027 namespace Cantera {
00028     
00029   
00030   /** 
00031    * @defgroup phases Models of Phases of Matter
00032    *
00033    *  These classes are used to represent the composition and state of a
00034    *  single phase of matter. 
00035    *   Together  these classes form the basis for describing the species and
00036    *  element compositions of a phase as well as the stoichiometry
00037    *  of each species, and for describing the current state of the
00038    *  phase. They do not in themselves contain Thermodynamic equation of 
00039    *  state information. However, they do comprise all of the necessary
00040    *  background functionality to support thermodynamic calculations, and the
00041    *  class ThermoPhase inherits from the class Phase (see \ref thermoprops).
00042    * 
00043    *  Class Elements manages the elements that are part of a
00044    *  chemistry specification for a phase.  This class may support calculations
00045    *  employing Multiple phases. In this case, a single Elements object may
00046    *  be shared by more than one Constituents class. Reactions between
00047    *  the phases may then be described using stoichiometry base on the
00048    *  same Elements class object.
00049    *
00050    *  The member functions of class %Elements return information about
00051    *  the elements described in a particular instantiation of the
00052    *  class.
00053    *
00054    *  Class %Constituents is designed to provide information
00055    *  about the elements and species in a phase - names, index
00056    *  numbers (location in arrays), atomic or molecular weights,
00057    *  etc. No computations are performed by the methods of this
00058    *  class. The set of elements must include all those that compose
00059    *  the species, but may include additional elements.
00060    *  
00061    *  %Constituents contains a pointer to the Elements object, and
00062    *  it contains wrapper functions for all of the functionality
00063    *  of the %Elements object, i.e., atomic weights, number and identity
00064    *  of the elements. %Elements may be added to a phase by using
00065    *  the function Constituents::addUniqueElement(). The %Elements 
00066    *  object may be shared amongst different Phases.
00067    *
00068    *  %Constituents also contains utilities retrieving the index of
00069    *  a species in the phase given its name, Constituents::speciesIndex().
00070    *
00071    *  Class State manages the independent variables of temperature,
00072    *  mass density, and species mass/mole fraction that define the
00073    *  thermodynamic state.
00074    * 
00075    *  Class %State stores just enough information about a
00076    *  multicomponent solution to specify its intensive thermodynamic
00077    *  state.  It stores values for the temperature, mass density, and
00078    *  an array of species mass fractions. It also stores an array of
00079    *  species molecular weights, which are used to convert between
00080    *  mole and mass representations of the composition. These are the
00081    *  \e only properties of the species that class %State knows about.
00082    *
00083    *  Class %State is not usually used directly in application
00084    *  programs. Its primary use is as a base class for class
00085    *  Phase. Class %State has no virtual methods, and none of its
00086    *  methods are meant to be overloaded. However, this is one
00087    *  exception.  If the phase is incompressible, then the density
00088    *  must be replaced by the pressure as the independent variable. In
00089    *  this case, functions such as State::setMassFractions() within
00090    *  the class %State must actually now calculate the density (at
00091    *  constant <I>T</I> and <I>P</I>) instead of leaving it alone as
00092    *  befits an independent variable. Therefore, these types of
00093    *  functions are virtual functions and need to be overloaded for
00094    *  incompressible phases. Note, for nearly incompressible phases
00095    *  (or phases which utilize standard states based on a <I>T</I> and
00096    *  <I>P</I>) this change in independent variables may be
00097    *  advantageous as well, and these functions in %State need to
00098    *  overload as well so that the storred density within State
00099    *  doesn't become out of date.
00100    *
00101    *  Class Phase derives from both clases
00102    *  Constituents and State. In addition to the methods of those two
00103    *  classes, it implements methods that allow referencing a species
00104    *  by name. And, it contains a lot of utility functions that will
00105    *  set the %State of the phase in its entirety, by first setting
00106    *  the composition, then the temperature and then the density.
00107    *  An example of this is the function,
00108    *    Phase::setState_TRY(doublereal t, doublereal dens, const doublereal* y).
00109    *
00110    *  Class Phase contains method for saving and restoring the
00111    *  full internal states of each phase. These are called Phase::saveState()
00112    *  and Phase::restoreState(). These functions operate on a state
00113    *  vector, which is in general of length (2 + nSpecies()). The first
00114    *  two entries of the state vector is temperature and density.
00115    *
00116    */
00117 
00118 
00119   //! Base class for phases of mater
00120   /*!
00121    * Base class for phases of matter. Class Phase derives from both
00122    * Constituents and State. In addition to the methods of those two
00123    * classes, it implements methods that allow referencing a species
00124    * by name.
00125    *
00126    *  Class Phase derives from both clases
00127    *  Constituents and State. In addition to the methods of those two
00128    *  classes, it implements methods that allow referencing a species
00129    *  by name. And, it contains a lot of utility functions that will
00130    *  set the %State of the phase in its entirety, by first setting
00131    *  the composition, then the temperature and then the density.
00132    *  An example of this is the function,
00133    *    Phase::setState_TRY(doublereal t, doublereal dens, const doublereal* y).
00134    *
00135    *  Class Phase contains method for saving and restoring the
00136    *  full internal states of each phase. These are called Phase::saveState()
00137    *  and Phase::restoreState(). These functions operate on a state
00138    *  vector, which is in general of length (2 + nSpecies()). The first
00139    *  two entries of the state vector is temperature and density.
00140    *
00141    *
00142    *  @todo
00143    *   Make the concept of saving state vectors more general, so that
00144    *   it can handle other cases where there are additional internal state
00145    *   variables, such as the voltage, a potential energy, or a strain field.
00146    *
00147    * @ingroup phases
00148    */
00149   class Phase : public Constituents, public State {    
00150 
00151   public:
00152 
00153     /// Default constructor.
00154     Phase();
00155 
00156     /// Destructor.
00157     virtual ~Phase();
00158 
00159     /**
00160      * Copy Constructor
00161      *
00162      * @param  right       Reference to the class to be used in the copy
00163      */
00164     Phase(const Phase &right);
00165       
00166     /**
00167      * Assignment operator
00168      *
00169      * @param  right      Reference to the class to be used in the copy
00170      */
00171     Phase &operator=(const Phase &right);
00172         
00173     //! Returns a reference to the XML_Node storred for the phase
00174     /*!
00175      *  The XML_Node for the phase contains all of the input data used
00176      *  to set up the model for the phase, during its initialization.
00177      */
00178     XML_Node& xml();
00179 
00180     //! Return the string id for the phase
00181     /*!
00182      * Returns the id of the phase. The ID of the phase
00183      * is set to the string name of the phase within the XML file
00184      * Generally, it refers to the individual model name that
00185      * denotes the species, the thermo, and the reaction rate info.
00186      */
00187     std::string id() const;
00188 
00189     //! Set the string id for the phase
00190     /*!
00191      * Sets the id of the phase. The ID of the phase
00192      * is originally set to the string name of the phase within the XML file.
00193      * Generally, it refers to the individual model name that
00194      * denotes the species, the thermo, and the reaction rate info.
00195      *
00196      * @param id String id of the phase
00197      */
00198     void setID(std::string id); 
00199 
00200     //! Return the name of the phase
00201     /*!
00202      * Returns the name of the phase. The name of the phase
00203      * is set to the string name of the phase within the XML file
00204      * Generally, it refers to the individual model name that
00205      * denotes the species, the thermo, and the reaction rate info.
00206      * It may also refer more specifically to a location within
00207      * the domain.
00208      */
00209     std::string name() const;
00210 
00211     //! Sets the string name for the phase
00212     /*!
00213      * Sets the name of the phase. The name of the phase
00214      * is originally set to the string name of the phase within the XML file.
00215      * Generally, it refers to the individual model name that
00216      * denotes the species, the thermo, and the reaction rate info.
00217      * It may also refer more specifically to a location within
00218      * the domain.
00219      *
00220      * @param nm String name of the phase
00221      */
00222     void setName(std::string nm);
00223 
00224     //! Returns the index of the phase
00225     /*!
00226      * The index is used in the Python and matlab interfaces to 
00227      * index into a list of ThermoPhase objects
00228      */
00229     int index() const;
00230 
00231     //! Sets the index of the phase
00232     /*!
00233      * The index is used in the Python and matlab interfaces to 
00234      * index into a list of ThermoPhase objects
00235      *
00236      * @param m Integer index of the phase
00237      */
00238     void setIndex(int m);
00239 
00240     //! Save the current internal state of the phase
00241     /*!
00242      * Write to vector 'state' the current internal state.
00243      *
00244      * @param state output vector. Will be resized to nSpecies() + 2 on return.
00245      */
00246     void saveState(vector_fp& state) const;
00247        
00248     //! Write to array 'state' the current internal state.
00249     /*!
00250      * @param lenstate length of the state array. Must be >= nSpecies() + 2
00251      * @param state    output vector. Must be of length  nSpecies() + 2 or
00252      *                 greater.
00253      */
00254     void saveState(int lenstate, doublereal* state) const;
00255       
00256     //!Restore a state saved on a previous call to saveState.
00257     /*!
00258      * @param state State vector containing the previously saved state.
00259      */
00260     void restoreState(const vector_fp& state);
00261 
00262     //! Restore the state of the phase from a previously saved state vector.
00263     /*!
00264      *  @param lenstate   Length of the state vector
00265      *  @param state      Vector of state conditions.
00266      */
00267     void restoreState(int lenstate, const doublereal* state);
00268 
00269     /**
00270      * Set the species mole fractions by name. 
00271      * @param xMap map from species names to mole fraction values.
00272      * Species not listed by name in \c xMap are set to zero.
00273      */
00274     void setMoleFractionsByName(compositionMap& xMap);
00275 
00276     //! Set the mole fractions of a group of species by name
00277     /*!
00278      * The string x is in the form of a composition map
00279      * Species which are not listed by name in the composition
00280      * map are set to zero.
00281      *
00282      * @param x string x in the form of a composition map
00283      */
00284     void setMoleFractionsByName(const std::string& x);
00285 
00286     /**
00287      * Set the species mass fractions by name. 
00288      * @param yMap map from species names to mass fraction values.
00289      * Species not listed by name in \c yMap are set to zero.
00290      */
00291     void setMassFractionsByName(compositionMap& yMap);
00292 
00293     
00294     //! Set the species mass fractions by name. 
00295     /*!
00296      * Species not listed by name in \c x are set to zero.
00297      *
00298      * @param x  String containing a composition map
00299      */
00300     void setMassFractionsByName(const std::string& x);
00301 
00302     //! Set the internally storred temperature (K), density, and mole fractions.  
00303     /*!
00304      * Note, the mole fractions are always set first, before the density
00305      *
00306      * @param t     Temperature in kelvin
00307      * @param dens  Density (kg/m^3)
00308      * @param x     vector of species mole fractions.
00309      *              Length is equal to m_kk
00310      */
00311     void setState_TRX(doublereal t, doublereal dens, const doublereal* x);
00312 
00313 
00314     //! Set the internally storred temperature (K), density, and mole fractions.  
00315     /*!
00316      * Note, the mole fractions are always set first, before the density
00317      *
00318      * @param t     Temperature in kelvin
00319      * @param dens  Density (kg/m^3)
00320      * @param x     Composition Map containing the mole fractions.
00321      *              Species not included in the map are assumed to have
00322      *              a zero mole fraction.
00323      */
00324     void setState_TRX(doublereal t, doublereal dens, compositionMap& x);
00325 
00326     //! Set the internally storred temperature (K), density, and mass fractions.  
00327     /*!
00328      * Note, the mass fractions are always set first, before the density
00329      *
00330      * @param t     Temperature in kelvin
00331      * @param dens  Density (kg/m^3)
00332      * @param y     vector of species mass fractions.
00333      *              Length is equal to m_kk
00334      */
00335     void setState_TRY(doublereal t, doublereal dens, const doublereal* y);
00336 
00337     //! Set the internally storred temperature (K), density, and mass fractions.  
00338     /*!
00339      * Note, the mass fractions are always set first, before the density
00340      *
00341      * @param t     Temperature in kelvin
00342      * @param dens  Density (kg/m^3)
00343      * @param y     Composition Map containing the mass fractions.
00344      *              Species not included in the map are assumed to have
00345      *              a zero mass fraction.
00346      */
00347     void setState_TRY(doublereal t, doublereal dens, compositionMap& y);
00348 
00349     //! Set the internally storred temperature (K), molar density (kmol/m^3), and mole fractions.  
00350     /*!
00351      * Note, the mole fractions are always set first, before the molar density
00352      *
00353      * @param t     Temperature in kelvin
00354      * @param n     molar density (kmol/m^3)
00355      * @param x     vector of species mole fractions.
00356      *              Length is equal to m_kk
00357      */
00358     void setState_TNX(doublereal t, doublereal n, const doublereal* x);
00359     
00360     //! Set the internally storred temperature (K) and density (kg/m^3)
00361     /*!
00362      * @param t     Temperature in kelvin
00363      * @param rho   Density (kg/m^3)
00364      */
00365     void setState_TR(doublereal t, doublereal rho);
00366       
00367     //! Set the internally storred temperature (K) and mole fractions.  
00368     /*!
00369      * @param t   Temperature in kelvin
00370      * @param x   vector of species mole fractions.
00371      *            Length is equal to m_kk
00372      */
00373     void setState_TX(doublereal t, doublereal* x);
00374 
00375     //! Set the internally storred temperature (K) and mass fractions.  
00376     /*!
00377      * @param t   Temperature in kelvin
00378      * @param y   vector of species mass fractions.
00379      *            Length is equal to m_kk
00380      */
00381     void setState_TY(doublereal t, doublereal* y);
00382 
00383     //! Set the density (kg/m^3) and mole fractions. 
00384     /*!
00385      * @param rho  Density (kg/m^3)
00386      * @param x    vector of species mole fractions.
00387      *             Length is equal to m_kk
00388      */
00389     void setState_RX(doublereal rho, doublereal* x);
00390 
00391     //! Set the density (kg/m^3) and mass fractions.  
00392     /*!
00393      * @param rho  Density (kg/m^3)
00394      * @param y    vector of species mass fractions.
00395      *             Length is equal to m_kk
00396      */
00397     void setState_RY(doublereal rho, doublereal* y);
00398 
00399     /**
00400      * Copy the vector of molecular weights into vector weights.
00401      *
00402      * @param weights Output vector of molecular weights (kg/kmol)
00403      */
00404     void getMolecularWeights(vector_fp& weights) const;
00405 
00406     /**
00407      * Copy the vector of molecular weights into array weights.
00408      *
00409      * @param iwt      Unused. 
00410      * @param weights  Output array of molecular weights (kg/kmol)
00411      *
00412      * @deprecated
00413      */
00414     void getMolecularWeights(int iwt, doublereal* weights) const;
00415 
00416     /**
00417      * Copy the vector of molecular weights into array weights.
00418      *
00419      * @param weights  Output array of molecular weights (kg/kmol)
00420      */
00421     void getMolecularWeights(doublereal* weights) const;
00422 
00423     /**
00424      * Return a const reference to the internal vector of
00425      * molecular weights.
00426      */
00427     const array_fp& molecularWeights() const;
00428 
00429     /**
00430      * Get the mole fractions by name. 
00431      *
00432      * @param x  Output composition map containing the
00433      *           species mole fractions.
00434      */
00435     void getMoleFractionsByName(compositionMap& x) const;
00436 
00437     //! Return the mole fraction of a single species
00438     /*!
00439      * @param  k  String name of the species
00440      *
00441      * @return Mole fraction of the species
00442      */
00443     doublereal moleFraction(int k) const;
00444         
00445     //! Return the mole fraction of a single species
00446     /*!
00447      * @param  name  String name of the species
00448      *
00449      * @return Mole fraction of the species
00450      */
00451     doublereal moleFraction(std::string name) const;
00452 
00453     //! Return the mass fraction of a single species
00454     /*!
00455      * @param  k  String name of the species
00456      *
00457      * @return Mass Fraction of the species
00458      */
00459     doublereal massFraction(int k) const;
00460 
00461     //! Return the mass fraction of a single species
00462     /*!
00463      * @param  name  String name of the species
00464      *
00465      * @return Mass Fraction of the species
00466      */
00467     doublereal massFraction(std::string name) const;
00468 
00469     /**
00470      * Charge density [C/m^3].
00471      */
00472     doublereal chargeDensity() const;
00473 
00474     /// Returns the number of spatial dimensions (1, 2, or 3)
00475     int nDim() const {return m_ndim;}
00476 
00477     //! Set the number of spatial dimensions (1, 2, or 3)
00478     /*!
00479      *  The number of spatial dimensions is used for vector involving
00480      *  directions.
00481      *
00482      * @param ndim   Input number of dimensions.
00483      */
00484     void setNDim(int ndim) {m_ndim = ndim;}
00485 
00486     /** 
00487      *  Finished adding species, prepare to use them for calculation
00488      *  of mixture properties.
00489      */
00490     virtual void freezeSpecies();
00491  
00492     virtual bool ready() const;
00493 
00494 
00495   protected:
00496 
00497     /**
00498      * m_kk = Number of species in the phase.  @internal m_kk is a
00499      * member of both the State and Constituents classes.
00500      * Therefore, to avoid multiple inheritance problems, we need
00501      * to restate it in here, so that the declarations in the two
00502      * base classes become hidden.
00503      */
00504     int m_kk;
00505 
00506     /**
00507      * m_ndim is the dimensionality of the phase.  Volumetric
00508      * phases have dimensionality 3 and surface phases have
00509      * dimensionality 2.
00510      */
00511     int m_ndim;
00512     /**
00513      * m_index is the index of the phase
00514      * 
00515      */
00516     int m_index;
00517 
00518   private:
00519 
00520     //! This stores the initial state of the system
00521     /*!
00522      * @deprecated
00523      *      This doesn't seem to be used much anymore.
00524      */
00525     vector_fp m_data;
00526 
00527     //! Pointer to the XML node containing the XML info for this phase
00528     XML_Node* m_xml;
00529 
00530     //! ID of the phase.
00531     /*!
00532      * This is the value of the ID attribute of the XML phase node.
00533      */
00534     std::string m_id;
00535 
00536     //! Name of the phase.
00537     /*!
00538      * Initially, this is the value of the ID attribute of the XML phase node.
00539      */
00540     std::string m_name;
00541   };
00542 
00543   //! typedef for the base Phase class
00544   typedef Phase phase_t;
00545 }
00546 
00547 #endif
Generated by  doxygen 1.6.3