Cantera  2.0
VPSSMgrFactory.h
Go to the documentation of this file.
1 /**
2  * @file VPSSMgrFactory.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 mgrpdssthermocalc and class \link Cantera::VPSSMgrFactory VPSSMgrFactory\endlink);
6  */
7 /*
8  * Copyright (2006) Sandia Corporation. Under the terms of
9  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
10  * U.S. Government retains certain rights in this software.
11  */
12 
13 #ifndef VPSSSPECIESTHERMO_FACTORY_H
14 #define VPSSSPECIESTHERMO_FACTORY_H
15 
19 #include "cantera/base/ct_thread.h"
20 #include "cantera/thermo/VPSSMgr.h"
21 
22 namespace Cantera
23 {
24 
25 class XML_Node;
26 class VPStandardStateTP;
27 
28 //! Throw a named error for an unknown or missing vpss species thermo model.
29 /*!
30  *
31  * @ingroup mgrpdssthermocalc
32  */
34 {
35 public:
36  //! Constructor
37  /*!
38  * @param proc Function name error occurred.
39  * @param VPSSMgrModel Unrecognized species thermo calculator name
40  */
41  UnknownVPSSMgrModel(std::string proc,
42  std::string VPSSMgrModel) :
43  CanteraError(proc, "Specified VPSSMgr model "
44  + VPSSMgrModel +
45  " does not match any known type.") {}
46  //! destructor
47  virtual ~UnknownVPSSMgrModel() 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 VPSSMgr object to use.
55  * The VPSSMgr object is used to calculate
56  * thermodynamic functions for the standard 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 derived VPSSMgr
60  * object to use and passes it back to the calling routine.
61  * It doesn't load any data into the derived
62  * VPSSMgr object.
63  *
64  * Making the choice of VPSSMgr 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 mgrpdssthermocalc
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 VPSSMgrFactory* factory() {
91  ScopedLock lock(vpss_species_thermo_mutex);
92  if (!s_factory) {
94  }
95  return s_factory;
96  }
97 
98  //! Delete static instance of this class
99  /*!
100  * If it is necessary to explicitly delete the factory before
101  * the process terminates (for example, when checking for
102  * memory leaks) then this method can be called to delete it.
103  */
104  void deleteFactory();
105 
106  //! Destructor
107  /*!
108  * Doesn't do anything. We do not delete statically
109  * created single instance of this class here, because it would
110  * create an infinite loop if destructor is called for that
111  * single instance.
112  */
113  virtual ~VPSSMgrFactory();
114 
115  //! String conversion to an enumType
116  /*!
117  * This routine is a string conversion. The string is obtained from the
118  * standardState model attribute and converted to a VPSSMgr_enumType
119  * type.
120  *
121  * @param ssModel String representing the VPSSMGr object
122  */
123  virtual VPSSMgr_enumType
124  VPSSMgr_StringConversion(std::string ssModel) const;
125 
126  //! Create a new species variable pressure standard state calculator
127  /*!
128  * @param type The enumerated type of the standard state calculator
129  * @param vp_ptr Variable pressure standard state ThermoPhase object
130  * that will be the owner.
131  */
132  virtual VPSSMgr* newVPSSMgr(VPSSMgr_enumType type, VPStandardStateTP* vp_ptr);
133 
134  //! Create a new species property manager for a group of species
135  /*!
136  * This routine will look through species nodes. It will discover what
137  * each species needs for its species property managers. Then,
138  * it will malloc and return the proper species property manager to use.
139  *
140  * @param vp_ptr Variable pressure standard state ThermoPhase object
141  * that will be the owner.
142  * @param phaseNode_ptr Pointer to the ThermoPhase phase XML Node
143  * @param spDataNodeList Vector of XML_Nodes, each of which is a species XML Node.
144  * There are m_kk of these.
145  *
146  * @return Returns a pointer to a newly malloced species property
147  * manager object.
148  */
149  virtual VPSSMgr* newVPSSMgr(VPStandardStateTP* vp_ptr,
150  XML_Node* phaseNode_ptr,
151  std::vector<XML_Node*> & spDataNodeList);
152 
153 private:
154 
155  //! pointer to the sole instance of this class
157 
158  //! Decl of the static mutex variable that locks the
159  //! %VPSSMgr factory singleton
161 
162  //! Constructor. This is made private, so that only the static
163  //! method factory() can instantiate the class.
165 };
166 
167 
168 ////////////////////// Convenience functions ////////////////////
169 //
170 // These functions allow using a different factory class that
171 // derives from SpeciesThermoFactory.
172 //
173 //////////////////////////////////////////////////////////////////
174 
175 
176 //! Create a new species thermo manager instance, by specifying
177 //! the type and (optionally) a pointer to the factory to use to create it.
178 /*!
179  * This utility program will look through species nodes. It will discover what
180  * each species needs for its species property managers. Then,
181  * it will malloc and return the proper species property manager to use.
182  *
183  * These functions allow using a different factory class that
184  * derives from SpeciesThermoFactory.
185  *
186  * @param type Species thermo type.
187  * @param vp_ptr Variable pressure standard state ThermoPhase object
188  * that will be the owner.
189  * @param f Pointer to a SpeciesThermoFactory. optional parameter.
190  * Defaults to NULL.
191  */
192 VPSSMgr* newVPSSMgr(VPSSMgr_enumType type,
193  VPStandardStateTP* vp_ptr, VPSSMgrFactory* f=0);
194 
195 //! Function to return VPSSMgr manager
196 /*!
197  * This utility program will look through species nodes. It will discover what
198  * each species needs for its species property managers. Then,
199  * it will alloc and return the proper species property manager to use.
200  *
201  * These functions allow using a different factory class that
202  * derives from SpeciesThermoFactory.
203  *
204  * @param vp_ptr Variable pressure standard state ThermoPhase object
205  * that will be the owner.
206  * @param phaseNode_ptr Pointer to the ThermoPhase phase XML Node
207  *
208  * @param spDataNodeList This vector contains a list
209  * of species XML nodes that will be in the phase
210  *
211  * @param f Pointer to a SpeciesThermoFactory. optional parameter.
212  * Defaults to NULL.
213  */
214 VPSSMgr* newVPSSMgr(VPStandardStateTP* vp_ptr,
215  XML_Node* phaseNode_ptr,
216  std::vector<XML_Node*> & spDataNodeList,
217  VPSSMgrFactory* f=0);
218 
219 }
220 
221 #endif
222 
223