Cantera  2.3.0
ThermoFactory.h
Go to the documentation of this file.
1 /**
2  * @file ThermoFactory.h
3  * Headers for the factory class that can create known ThermoPhase objects
4  * (see \ref thermoprops and class \link Cantera::ThermoFactory ThermoFactory\endlink).
5  */
6 
7 // This file is part of Cantera. See License.txt in the top-level directory or
8 // at http://www.cantera.org/license.txt for license and copyright information.
9 
10 #ifndef THERMO_FACTORY_H
11 #define THERMO_FACTORY_H
12 
13 #include "ThermoPhase.h"
14 #include "cantera/base/xml.h"
16 
17 namespace Cantera
18 {
19 
20 /*!
21  * @addtogroup thermoprops
22  *
23  * Standard ThermoPhase objects may be instantiated by calling the main %Cantera
24  * factory class for ThermoPhase objects; This class is called ThermoFactory.
25  */
26 //@{
27 
28 //! Specific error to be thrown if the type of Thermo manager is unrecognized.
29 /*!
30  * This particular error class may be caught, if the application may have other
31  * models that the main Cantera application doesn't know about.
32  */
34 {
35 public:
36  //! Constructor
37  /*!
38  * @param proc Function name where the error occurred.
39  * @param thermoModel Sting name of ThermoPhase which didn't match
40  */
41  UnknownThermoPhaseModel(const std::string& proc,
42  const std::string& thermoModel) :
43  CanteraError(proc, "Specified ThermoPhase model "
44  + thermoModel +
45  " does not match any known type.") {}
46 };
47 
48 
49 //! Factory class for thermodynamic property managers.
50 /*!
51  * This class keeps a list of the known ThermoPhase classes, and is
52  * used to create new instances of these classes.
53  */
54 class ThermoFactory : public Factory<ThermoPhase>
55 {
56 public:
57  //! Static function that creates a static instance of the factory.
58  static ThermoFactory* factory() {
59  std::unique_lock<std::mutex> lock(thermo_mutex);
60  if (!s_factory) {
62  }
63  return s_factory;
64  }
65 
66  //! delete the static instance of this factory
67  virtual void deleteFactory() {
68  std::unique_lock<std::mutex> lock(thermo_mutex);
69  delete s_factory;
70  s_factory = 0;
71  }
72 
73  //! Create a new thermodynamic property manager.
74  /*!
75  * @param model String to look up the model against
76  * @returns a pointer to a new ThermoPhase instance matching the model
77  * string. Returns NULL if something went wrong. Throws an exception
78  * UnknownThermoPhaseModel if the string wasn't matched.
79  */
80  virtual ThermoPhase* newThermoPhase(const std::string& model);
81 
82 private:
83  //! static member of a single instance
85 
86  //! Private constructors prevents usage
87  ThermoFactory();
88 
89  //! Decl for locking mutex for thermo factory singleton
90  static std::mutex thermo_mutex;
91 };
92 
93 //! Create a new thermo manager instance.
94 /*!
95  * @param model String to look up the model against
96  * @param f ThermoFactory instance to use in matching the string
97  * @returns a pointer to a new ThermoPhase instance matching the model string.
98  * Returns NULL if something went wrong. Throws an exception
99  * UnknownThermoPhaseModel if the string wasn't matched.
100  * @deprecated The `ThermoFactory*` argument to this function is deprecated and
101  * will be removed after Cantera 2.3.
102  */
103 inline ThermoPhase* newThermoPhase(const std::string& model,
104  ThermoFactory* f=0)
105 {
106  if (f == 0) {
108  } else {
109  warn_deprecated("newThermoPhase(string, ThermoFactory*)",
110  "The `ThermoFactory*` argument to this function is deprecated and"
111  " will be removed after Cantera 2.3.");
112  }
113  return f->create(model);
114 }
115 
116 //! Translate the eosType id into a string
117 /*!
118  * @param ieos eosType id of the phase. This is unique for the phase
119  * @param length maximum length of the return string. Defaults to 100
120  * @returns a string representation of the eosType id for a phase
121  * @deprecated To be removed after Cantera 2.3.
122  */
123 std::string eosTypeString(int ieos, int length = 100);
124 
125 //! Create a new ThermoPhase object and initializes it according to the XML tree
126 /*!
127  * This routine first looks up the identity of the model for the solution
128  * thermodynamics in the model attribute of the thermo child of the XML phase
129  * node. Then, it does a string lookup using Cantera's internal ThermoPhase
130  * Factory routines on the model to figure out what ThermoPhase derived class
131  * should be assigned. It creates a new instance of that class, and then calls
132  * importPhase() to populate that class with the correct parameters from the
133  * XML tree.
134  *
135  * @param phase XML_Node reference pointing to the phase XML element.
136  * @return A pointer to the completed and initialized ThermoPhase object.
137  *
138  * @ingroup inputfiles
139  */
140 ThermoPhase* newPhase(XML_Node& phase);
141 
142 //! Create and Initialize a ThermoPhase object from an XML input file.
143 /*!
144  * This routine is a wrapper around the newPhase(XML_Node) routine which does
145  * the work. The wrapper locates the input phase XML_Node in a file, and then
146  * instantiates the object, returning the pointer to the ThermoPhase object.
147  *
148  * @param infile name of the input file
149  * @param id name of the phase id in the file.
150  * If this is blank, the first phase in the file is used.
151  * @returns an initialized ThermoPhase object.
152  */
153 ThermoPhase* newPhase(const std::string& infile, std::string id="");
154 
155 //! Import a phase information into an empty ThermoPhase object
156 /*!
157  * Here we read an XML description of the thermodynamic information for a phase.
158  * At the end of this routine, the phase should be ready to be used within
159  * applications. This routine contains some key routines that are used as pass
160  * back routines so that the phase (and the contents of the XML file) may
161  * contain variable parameterizations for the specification of the species
162  * standard states, the equation of state, and the specification of other
163  * nonidealities. Below, a description is presented of the main algorithm for
164  * bringing up a ThermoPhase object, with care to present points where
165  * customizations occur.
166  *
167  * Before invoking this routine, either the ThermoPhase Factory routines are
168  * called or direct constructor routines are called that instantiate an
169  * inherited ThermoPhase object. This object is input to this routine, and
170  * therefore contains inherited routines that drive the customization of the
171  * initialization process.
172  *
173  * At the start of the routine, we import descriptions of the elements that make
174  * up the species in a phase.
175  *
176  * We call setParametersFromXML(eos) to read parameters about the thermo phase
177  * before the species are read in.
178  *
179  * We call addElementsFromXML() to add elements into the description of the
180  * phase.
181  *
182  * We create a new species thermo manager. Function 'newSpeciesThermoMgr' looks
183  * at the species in the database to see what thermodynamic property
184  * parameterizations are used, and selects a class that can handle the
185  * parameterizations found.
186  *
187  * We import information about the species, including their reference state
188  * thermodynamic polynomials. We then freeze the state of the species in the
189  * element.
190  *
191  * Finally, we call initThermoXML(), a member function of the ThermoPhase
192  * object, to "finish" the description. Now that the species are known,
193  * additional information may be read in about the thermodynamics of the phase,
194  * (e.g., virial coefficients, which are binary or ternary interaction
195  * parameters between species).
196  *
197  * @param phase This object must be the phase node of a complete XML tree
198  * description of the phase, including all of the species data. In
199  * other words while "phase" must point to an XML phase object, it
200  * must have sibling nodes "speciesData" that describe the species
201  * in the phase.
202  * @param th Pointer to the ThermoPhase object which will handle the
203  * thermodynamics for this phase. We initialize part of the
204  * ThermoPhase object here, especially for those objects which are
205  * part of the Cantera Kernel.
206  * @ingroup thermoprops
207  */
208 void importPhase(XML_Node& phase, ThermoPhase* th);
209 
210 //! Add the elements given in an XML_Node tree to the specified phase
211 void installElements(Phase& th, const XML_Node& phaseNode);
212 
213 //! Search an XML tree for species data.
214 /*!
215  * This utility routine will search the XML tree for the species named by the
216  * string, kname. It will return the XML_Node pointer to the species data for
217  * that species. Failures of any kind return the null pointer.
218  *
219  * @param kname String containing the name of the species.
220  * @param phaseSpeciesData Pointer to the XML speciesData element
221  * containing the species data for that phase.
222  */
223 const XML_Node* speciesXML_Node(const std::string& kname,
224  const XML_Node* phaseSpeciesData);
225 
226 //@}
227 
228 }
229 
230 #endif
Specific error to be thrown if the type of Thermo manager is unrecognized.
Definition: ThermoFactory.h:33
virtual void deleteFactory()
delete the static instance of this factory
Definition: ThermoFactory.h:67
ThermoPhase * newPhase(XML_Node &xmlphase)
Create a new ThermoPhase object and initializes it according to the XML tree.
std::string eosTypeString(int ieos, int length)
Translate the eosType id into a string.
static ThermoFactory * factory()
Static function that creates a static instance of the factory.
Definition: ThermoFactory.h:58
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
const XML_Node * speciesXML_Node(const std::string &kname, const XML_Node *phaseSpeciesData)
Search an XML tree for species data.
UnknownThermoPhaseModel(const std::string &proc, const std::string &thermoModel)
Constructor.
Definition: ThermoFactory.h:41
Factory class for thermodynamic property managers.
Definition: ThermoFactory.h:54
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
static std::mutex thermo_mutex
Decl for locking mutex for thermo factory singleton.
Definition: ThermoFactory.h:90
virtual ThermoPhase * newThermoPhase(const std::string &model)
Create a new thermodynamic property manager.
Classes providing support for XML data files.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
static ThermoFactory * s_factory
static member of a single instance
Definition: ThermoFactory.h:84
ThermoPhase * newThermoPhase(const std::string &model, ThermoFactory *f=0)
Create a new thermo manager instance.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:69
void installElements(Phase &th, const XML_Node &phaseNode)
Add the elements given in an XML_Node tree to the specified phase.
ThermoFactory()
Private constructors prevents usage.
Namespace for the Cantera kernel.
Definition: application.cpp:29
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
File contains the FactoryBase class declarations.