Cantera  2.0
SpeciesThermoFactory.h
Go to the documentation of this file.
1 /**
2  * @file SpeciesThermoFactory.h
3  * Header for factory to build instances of classes that manage the
4  * standard-state thermodynamic properties of a set of species
5  * (see \ref spthermo and class
6  * \link Cantera::SpeciesThermoFactory SpeciesThermoFactory\endlink);
7  */
8 // Copyright 2001 California Institute of Technology
9 
10 #ifndef SPECIESTHERMO_FACTORY_H
11 #define SPECIESTHERMO_FACTORY_H
12 
13 #include "SpeciesThermo.h"
16 #include "cantera/base/ct_thread.h"
17 
18 namespace Cantera
19 {
20 
21 class XML_Node;
22 class VPStandardStateTP;
23 class VPSSMgr;
24 class ThermoPhase;
25 
26 /**
27  * Throw a named error for an unknown or missing species thermo model.
28  *
29  * @ingroup thermoprops
30  */
32 {
33 public:
34  //! constructor
35  /*!
36  * @param proc Function name error occurred.
37  * @param spName Species Name that caused the error
38  * @param speciesThermoModel Unrecognized species thermo model name
39  */
40  UnknownSpeciesThermoModel(std::string proc, std::string spName,
41  std::string speciesThermoModel) :
42  CanteraError(proc, "species " + spName +
43  ": Specified speciesThermoPhase model "
44  + speciesThermoModel +
45  " does not match any known type.") {}
46  //! destructor
47  virtual ~UnknownSpeciesThermoModel() throw() {}
48 };
49 
50 //! Factory to build instances of classes that manage the
51 //! standard-state thermodynamic properties of a set of species.
52 /*!
53  * This class is responsible for making the decision concerning
54  * which derivative of SpeciesThermo object to use.
55  * The SpeciesThermo object is used to calculate
56  * thermodynamic functions for the reference state.
57  * It queries the database of species to understand what
58  * the requirements are for the submodels for all of the
59  * species in the phase. Then, it picks the SpeciesThermo
60  * object to use, and passes it back to the calling routine.
61  * It doesn't load any of the data into the derived
62  * SpeciesThermo object.
63  *
64  * Making the choice of SpeciesThermo types is the only
65  * thing this class does.
66  *
67  * This class is implemented as a singleton -- one in which
68  * only one instance is needed. The recommended way to access
69  * the factory is to call this static method, which
70  * instantiates the class if it is the first call, but
71  * otherwise simply returns the pointer to the existing
72  * instance.
73  *
74  * @ingroup thermoprops
75  */
77 {
78 
79 public:
80 
81  //! Static method to return an instance of this class
82  /*!
83  * This class is implemented as a singleton -- one in which
84  * only one instance is needed. The recommended way to access
85  * the factory is to call this static method, which
86  * instantiates the class if it is the first call, but
87  * otherwise simply returns the pointer to the existing
88  * instance.
89  */
90  static SpeciesThermoFactory* factory();
91 
92  //! Delete static instance of this class
93  /**
94  * If it is necessary to explicitly delete the factory before
95  * the process terminates (for example, when checking for
96  * memory leaks) then this method can be called to delete it.
97  */
98  void deleteFactory();
99 
100  //! Destructor
101  /**
102  * Doesn't do anything. We do not delete statically
103  * created single instance of this class here, because it would
104  * create an infinite loop if destructor is called for that
105  * single instance.
106  */
107  virtual ~SpeciesThermoFactory();
108 
109  //! Create a new species property manage for the reference state.
110  /*!
111  * @param type the integer type to be created.
112  *
113  *
114  * @return Returns the pointer to the newly malloced
115  * species property manager for the reference
116  * state
117  */
118  SpeciesThermo* newSpeciesThermo(int type) const;
119 
120  //! Create a new species thermo property manager given a string
121  /*!
122  * Create a new species thermo property manager, given a
123  * string.
124  *
125  * @param stype String name for the species thermo type
126  *
127  *
128  * @return Returns the pointer to the newly malloced
129  * species property manager for the reference
130  * state
131  */
132  SpeciesThermo* newSpeciesThermoManager(std::string& stype) const;
133 
134  //! Create a new species property manager for the reference
135  //! state for a group of species
136  /*!
137  * This routine will look through species nodes. It will discover what
138  * each species needs for its species property managers. Then,
139  * it will malloc and return the proper species property manager to use.
140  *
141  * @param spDataNodeList This vector contains a list
142  * of species XML nodes that will be in the phase
143  *
144  * @return Returns the pointer to the newly malloced
145  * species property manager for the reference
146  * state
147  */
148  SpeciesThermo* newSpeciesThermo(std::vector<XML_Node*> & spDataNodeList) const;
149 
150  //! Create a new species property manager for the reference state
151  /*!
152  * This routine will look through species nodes. It will discover what
153  * each species needs for its species property managers. Then,
154  * it will malloc and return the proper species property manager to use.
155  *
156  *
157  * @param spDataNodeList This vector contains a list
158  * of species XML nodes that will be in the phase
159  *
160  * @return Returns the pointer to the newly malloced
161  * species property manager for the reference state
162  * @deprecated Essentially never used
163  */
164  DEPRECATED(SpeciesThermo* newSpeciesThermoOpt(std::vector<XML_Node*> & spDataNodeList) const);
165 
166  //! Install a species thermodynamic property parameterization
167  //! for the reference state for one species into a species thermo manager.
168  /*!
169  * @param k Species number
170  * @param speciesNode Reference to the XML node specifying the species standard
171  * state information
172  * @param th_ptr Pointer to the %ThermoPhase object for the species
173  * @param spthermo Species reference state thermo manager
174  * @param phaseNode_ptr Optional pointer to the XML phase
175  * information for the phase in which the species
176  * resides
177  */
178  void installThermoForSpecies(size_t k, const XML_Node& speciesNode,
179  ThermoPhase* th_ptr, SpeciesThermo& spthermo,
180  const XML_Node* phaseNode_ptr = 0) const;
181 
182  //! Install a species thermodynamic property parameterization
183  //! for the standard state for one species into a species thermo manager, VPSSMgr
184  /*!
185  * This is a wrapper around the createInstallVPSS() function in the
186  * VPStandardStateTP object.
187  *
188  * This serves to install the species into vpss_ptr, create a PDSS file. We also
189  * read the xml database to extract the constants for these steps.
190  *
191  * @param k species number
192  * @param speciesNode Reference to the XML node specifying the species standard
193  * state information
194  * @param vp_ptr variable pressure ThermoPhase object
195  * @param vpss_ptr Pointer to the Manager for calculating variable pressure
196  * substances.
197  * @param spthermo_ptr Species reference state thermo manager
198  * @param phaseNode_ptr Optional Pointer to the XML phase
199  * information for the phase in which the species
200  * resides
201  */
202  void installVPThermoForSpecies(size_t k, const XML_Node& speciesNode,
203  VPStandardStateTP* vp_ptr,
204  VPSSMgr* vpss_ptr,
205  SpeciesThermo* spthermo_ptr,
206  const XML_Node* phaseNode_ptr) const;
207 
208 private:
209 
210  //! Pointer to the sole instance of this class, which is static
212 
213  //! Decl of the static mutex variable that locks the %SpeciesThermo factory singleton
214  static mutex_t species_thermo_mutex;
215 
216  //! Constructor. This is made private, so that only the static
217  //! method factory() can instantiate the class.
219 };
220 
221 
222 ////////////////////// Convenience functions ////////////////////
223 //
224 // These functions allow using a different factory class that
225 // derives from SpeciesThermoFactory.
226 //
227 //////////////////////////////////////////////////////////////////
228 
229 
230 //! Create a new species thermo manager instance, by specifying
231 //!the type and (optionally) a pointer to the factory to use to create it.
232 /*!
233  * This utility program will look through species nodes. It will discover what
234  * each species needs for its species property managers. Then,
235  * it will malloc and return the proper species property manager to use.
236  *
237  * These functions allow using a different factory class that
238  * derives from SpeciesThermoFactory.
239  *
240  * @param type Species thermo type.
241  * @param f Pointer to a SpeciesThermoFactory. optional parameter.
242  * Defaults to NULL.
243  */
244 SpeciesThermo* newSpeciesThermoMgr(int type, SpeciesThermoFactory* f=0);
245 
246 //! Create a new species thermo manager instance, by specifying
247 //!the type and (optionally) a pointer to the factory to use to create it.
248 /*!
249  * This utility program is a basic factory operation for spawning a
250  * new species reference-state thermo manager
251  *
252  * These functions allows for using a different factory class that
253  * derives from SpeciesThermoFactory. However, no applications of this
254  * have been done yet.
255  *
256  * @param stype String specifying the species thermo type
257  * @param f Pointer to a SpeciesThermoFactory. optional parameter.
258  * Defaults to NULL.
259  */
260 SpeciesThermo* newSpeciesThermoMgr(std::string& stype,
261  SpeciesThermoFactory* f=0);
262 
263 //! Function to return SpeciesThermo manager
264 /*!
265  * This utility program will look through species nodes. It will discover what
266  * each species needs for its species property managers. Then,
267  * it will malloc and return the proper species reference state manager to use.
268  *
269  * These functions allow using a different factory class that
270  * derives from SpeciesThermoFactory.
271  *
272  * @param spDataNodeList This vector contains a list
273  * of species XML nodes that will be in the phase
274  *
275  * @param f Pointer to a SpeciesThermoFactory. optional parameter.
276  * Defaults to NULL.
277  * @param opt Boolean defaults to false.
278  */
279 SpeciesThermo* newSpeciesThermoMgr(std::vector<XML_Node*> spDataNodeList,
280  SpeciesThermoFactory* f=0, bool opt=false);
281 
282 }
283 
284 #endif
285 
286