Cantera  2.1.2
TransportFactory.h
Go to the documentation of this file.
1 /**
2  * @file TransportFactory.h
3  * Header file defining class TransportFactory
4  * (see \link Cantera::TransportFactory TransportFactory\endlink)
5  */
6 // Copyright 2001 California Institute of Technology
7 
8 #ifndef CT_TRANSPORTFACTORY_H
9 #define CT_TRANSPORTFACTORY_H
10 
11 // Cantera includes
12 #include "cantera/base/ct_defs.h"
13 #include "cantera/base/ct_thread.h"
14 #include "TransportBase.h"
16 #include "LiquidTransportParams.h"
17 #include "SolidTransportData.h"
18 
19 namespace Cantera
20 {
21 
22 // forward references
23 class MMCollisionInt;
24 class GasTransportParams;
25 class LiquidTransportParams;
26 class XML_Node;
27 
28 //! Factory class for creating new instances of classes derived from Transport.
29 /*!
30  * Creates 'transport managers', which are classes derived from class
31  * Transport that provide transport properties. TransportFactory handles all
32  * initialization required, including evaluation of collision integrals and
33  * generating polynomial fits. Transport managers can also be created in
34  * other ways.
35  *
36  * @ingroup tranprops
37  */
39 {
40 public:
41  //! Return a pointer to a TransportFactory instance.
42  /*!
43  * TransportFactory is implemented as a 'singleton', which means that at
44  * most one instance may be created. The constructor is private. When a
45  * TransportFactory instance is required, call static method factory() to
46  * return a pointer to the TransportFactory instance.
47  *
48  * @code
49  * TransportFactory* f;
50  * f = TransportFactory::factory();
51  * @endcode
52  */
54  ScopedLock transportLock(transport_mutex);
55  if (!s_factory) {
57  }
58  return s_factory;
59  }
60 
61  //! Deletes the statically allocated factory instance.
62  virtual void deleteFactory();
63 
64  //! Get the name of the transport model corresponding to the specified constant.
65  /*!
66  * @param model Integer representing the model name
67  */
68  static std::string modelName(int model);
69 
70  //! Make one of several transport models, and return a base class pointer to it.
71  /*!
72  * This method operates at the level of a single transport property as a
73  * function of temperature and possibly composition. It's a factory for
74  * LTPspecies classes.
75  *
76  * @param trNode XML node
77  * @param name reference to the name
78  * @param tp_ind TransportPropertyType class
79  * @param thermo Pointer to the %ThermoPhase class
80  */
81  virtual LTPspecies* newLTP(const XML_Node& trNode, const std::string& name,
82  TransportPropertyType tp_ind, thermo_t* thermo);
83 
84  //! Factory function for the construction of new LiquidTranInteraction
85  //! objects, which are transport models.
86  /*!
87  * This method operates at the level of a single mixture transport property. Individual species
88  * transport properties are addressed by the LTPspecies returned by newLTP.
89  *
90  * @param trNode XML_Node containing the information for the interaction
91  * @param tp_ind TransportPropertyType object
92  * @param trParam reference to the LiquidTransportParams object
93  */
94  virtual LiquidTranInteraction* newLTI(const XML_Node& trNode,
95  TransportPropertyType tp_ind,
96  LiquidTransportParams& trParam);
97 
98  //! Build a new transport manager using a transport manager
99  //! that may not be the same as in the phase description
100  //! and return a base class pointer to it
101  /*!
102  * @param model String name for the transport manager
103  * @param thermo ThermoPhase object
104  * @param log_level log level
105  * @param ndim Number of dimensions for fluxes
106  */
107  virtual Transport* newTransport(const std::string& model, thermo_t* thermo, int log_level=0, int ndim=1);
108 
109  //! Build a new transport manager using the default transport manager
110  //! in the phase description and return a base class pointer to it
111  /*!
112  * @param thermo ThermoPhase object
113  * @param log_level log level
114  */
115  virtual Transport*
116  newTransport(thermo_t* thermo, int log_level=0);
117 
118  //! Initialize an existing transport manager
119  /*!
120  * This routine sets up an existing gas-phase transport manager. It
121  * calculates the collision integrals and calls the initGas() function to
122  * populate the species-dependent data structure.
123  *
124  * @param tr Pointer to the Transport manager
125  * @param thermo Pointer to the ThermoPhase object
126  * @param mode Chemkin compatible mode or not. This alters the specification of the
127  * collision integrals. defaults to no.
128  * @param log_level Defaults to zero, no logging
129  *
130  * In DEBUG_MODE, this routine will create the file transport_log.xml
131  * and write informative information to it.
132  */
133  virtual void initTransport(Transport* tr, thermo_t* thermo, int mode=0, int log_level=0);
134 
135  //! Initialize an existing transport manager for liquid phase
136  /*!
137  * This routine sets up an existing liquid-phase transport manager. It is
138  * similar to initTransport except that it uses the LiquidTransportParams
139  * class and calls setupLiquidTransport().
140  *
141  * @param tr Pointer to the Transport manager
142  * @param thermo Pointer to the ThermoPhase object
143  * @param log_level Defaults to zero, no logging
144  *
145  * In DEBUG_MODE, this routine will create the file transport_log.xml
146  * and write informative information to it.
147  */
148  virtual void initLiquidTransport(Transport* tr, thermo_t* thermo, int log_level=0);
149 
150 private:
151  //! Initialize an existing transport manager for solid phase
152  /*!
153  * This routine sets up an existing solid-phase transport manager.
154  * It is similar to initTransport except that it uses the SolidTransportData
155  * class and calls setupSolidTransport().
156  *
157  * @param tr Pointer to the Transport manager
158  * @param thermo Pointer to the ThermoPhase object
159  * @param log_level Defaults to zero, no logging
160  *
161  * In DEBUG_MODE, this routine will create the file transport_log.xml
162  * and write informative information to it.
163  */
164  virtual void initSolidTransport(Transport* tr, thermo_t* thermo, int log_level=0);
165 
166 private:
167  //! Static instance of the factor -> This is the only instance of this
168  //! object allowed
170 
171  //! Static instance of the mutex used to ensure the proper reading of the transport database
172  static mutex_t transport_mutex;
173 
174  //! The constructor is private; use static method factory() to
175  //! get a pointer to a factory instance
176  /*!
177  * The default constructor for this class sets up
178  * m_models[], a mapping between the string name
179  * for a transport model and the integer name.
180  */
182 
183  //! Read the transport database
184  /*!
185  * Read transport property data from a file for a list of species.
186  * Given the name of a file containing transport property
187  * parameters and a list of species names, this method returns an
188  * instance of TransportParams containing the transport data for
189  * these species read from the file.
190  *
191  * @param xspecies Vector of pointers to species XML_Node databases.
192  * @param log reference to an XML_Node that will contain the log (unused)
193  * @param names vector of species names that must be filled in with valid transport parameters
194  * @param tr Output object containing the transport parameters
195  * for the species listed in names (in the order of their listing
196  * in names).
197  */
198  void getTransportData(const std::vector<const XML_Node*> &xspecies,
199  XML_Node& log, const std::vector<std::string>& names,
200  GasTransportParams& tr);
201 
202  //! Read transport property data from a file for a list of species that comprise
203  //! the phase.
204  /*!
205  * Given a vector of pointers to species XML data bases
206  * and a list of species names, this method constructs the LiquidTransport
207  * Params object containing the transport data for these species.
208  *
209  * It is an error to not find a "transport" XML element within each of the species
210  * XML elements listed in the names vector.
211  *
212  * @param db Reference to a vector of XML_Node pointers containing the species XML
213  * nodes.
214  * @param log Reference to an XML log file. (currently unused)
215  * @param names Vector of names of species. On output, tr will contain transport data
216  * for each of of these names in the order determined by this vector.
217  * @param tr Reference to the LiquidTransportParams object that will contain the results.
218  */
219  void getLiquidSpeciesTransportData(const std::vector<const XML_Node*> &db,
220  XML_Node& log, const std::vector<std::string>& names,
222 
223  //! Read transport property data from a file for interactions between species.
224  /*!
225  * Given the XML_Node database for transport interactions defined within the current phase
226  * and a list of species names within the phase, this method returns an
227  * instance of TransportParams containing the transport data for
228  * these species read from the file.
229  *
230  * This routine reads interaction parameters between species within the phase.
231  *
232  * @param phaseTran_db Reference to the transport XML field for the phase
233  * @param log Reference to an XML log file. (currently unused)
234  * @param names Vector of names of species. On output, tr will contain transport data
235  * for each of of these names in the order determined by this vector.
236  * @param tr Reference to the LiquidTransportParams object that will contain the results.
237  */
238  void getLiquidInteractionsTransportData(const XML_Node& phaseTran_db, XML_Node& log,
239  const std::vector<std::string>& names, LiquidTransportParams& tr);
240 
241  //! Read transport property data from a file for a solid phase
242  /*!
243  * Given a phase XML data base, this method constructs the
244  * SolidTransportData object containing the transport data for the phase.
245  *
246  * @param transportNode Reference to XML_Node containing the phase.
247  * @param log Reference to an XML log file. (currently unused)
248  * @param phaseName name of the corresponding phase
249  * @param tr Reference to the SolidTransportData object that will contain the results.
250  */
251  void getSolidTransportData(const XML_Node& transportNode,
252  XML_Node& log,
253  const std::string phaseName,
254  SolidTransportData& tr);
255 
256  //! Generate polynomial fits to the viscosity, conductivity, and
257  //! the binary diffusion coefficients
258  /*!
259  * If CK_mode, then the fits are of the form
260  * \f[
261  * \log(\eta(i)) = \sum_{n = 0}^3 a_n(i) (\log T)^n
262  * \f]
263  * and
264  * \f[
265  * \log(D(i,j)) = \sum_{n = 0}^3 a_n(i,j) (\log T)^n
266  * \f]
267  * Otherwise the fits are of the form
268  * \f[
269  * \eta(i)/sqrt(k_BT) = \sum_{n = 0}^4 a_n(i) (\log T)^n
270  * \f]
271  * and
272  * \f[
273  * D(i,j)/sqrt(k_BT)) = \sum_{n = 0}^4 a_n(i,j) (\log T)^n
274  * \f]
275  *
276  * @param tr Reference to the GasTransportParams object that will contain the results.
277  * @param logfile Reference to an ostream that will contain log information when in
278  * DEBUG_MODE
279  * @param integrals interpolator for the collision integrals
280  */
281  void fitProperties(GasTransportParams& tr, MMCollisionInt& integrals,
282  std::ostream& logfile);
283 
284  //! Generate polynomial fits to collision integrals
285  /*!
286  * @param logfile Reference to an ostream that will contain log information when in
287  * DEBUG_MODE
288  * @param tr Reference to the GasTransportParams object that will contain the results.
289  * @param integrals interpolator for the collision integrals
290  */
291  void fitCollisionIntegrals(std::ostream& logfile, GasTransportParams& tr,
292  MMCollisionInt& integrals);
293 
294  //! Prepare to build a new kinetic-theory-based transport manager for low-density gases
295  /*!
296  * This class fills up the GastransportParams structure for the current phase
297  *
298  * Uses polynomial fits to Monchick & Mason collision integrals. store then in tr
299  *
300  * @param flog Reference to the ostream for writing log info
301  * @param transport_database Reference to a vector of pointers containing the
302  * transport database for each species
303  * @param thermo Pointer to the %ThermoPhase object
304  * @param mode Mode -> Either it's CK_Mode, chemkin compatibility mode, or it is not
305  * We usually run with chemkin compatibility mode turned off.
306  * @param log_level log level
307  * @param tr GasTransportParams structure to be filled up with information
308  */
309  void setupMM(std::ostream& flog, const std::vector<const XML_Node*> &transport_database,
310  thermo_t* thermo, int mode, int log_level, GasTransportParams& tr);
311 
312  //! Prepare to build a new transport manager for liquids assuming that
313  //! viscosity transport data is provided in Arrhenius form.
314  /*!
315  * @param flog Reference to the ostream for writing log info
316  * @param thermo Pointer to the %ThermoPhase object
317  * @param log_level log level
318  * @param trParam LiquidTransportParams structure to be filled up with information
319  */
320  void setupLiquidTransport(std::ostream& flog, thermo_t* thermo, int log_level, LiquidTransportParams& trParam);
321 
322  //! Prepare to build a new transport manager for solids
323  /*!
324  * @param flog Reference to the ostream for writing log info
325  * @param thermo Pointer to the %ThermoPhase object
326  * @param log_level log level
327  * @param trParam SolidTransportData structure to be filled up with information
328  */
329  void setupSolidTransport(std::ostream& flog, thermo_t* thermo, int log_level, SolidTransportData& trParam);
330 
331  //! Second-order correction to the binary diffusion coefficients
332  /*!
333  * Calculate second-order corrections to binary diffusion
334  * coefficient pair (dkj, djk). At first order, the binary
335  * diffusion coefficients are independent of composition, and
336  * d(k,j) = d(j,k). But at second order, there is a weak
337  * dependence on composition, with the result that d(k,j) !=
338  * d(j,k). This method computes the multiplier by which the
339  * first-order binary diffusion coefficient should be multiplied
340  * to produce the value correct to second order. The expressions
341  * here are taken from Marerro and Mason, J. Phys. Chem. Ref. Data, vol. 1, p. 3 (1972).
342  *
343  * @param t Temperature (K)
344  * @param tr Transport parameters
345  * @param integrals interpolator for the collision integrals
346  * @param k index of first species
347  * @param j index of second species
348  * @param xk Mole fraction of species k
349  * @param xj Mole fraction of species j
350  * @param fkj multiplier for d(k,j)
351  * @param fjk multiplier for d(j,k)
352  *
353  * @note This method is not used currently.
354  */
355  void getBinDiffCorrection(doublereal t, const GasTransportParams& tr,
356  MMCollisionInt& integrals, size_t k,
357  size_t j, doublereal xk, doublereal xj,
358  doublereal& fkj, doublereal& fjk);
359 
360  //! Corrections for polar-nonpolar binary diffusion coefficients
361  /*!
362  * Calculate corrections to the well depth parameter and the
363  * diameter for use in computing the binary diffusion coefficient
364  * of polar-nonpolar pairs. For more information about this
365  * correction, see Dixon-Lewis, Proc. Royal Society (1968).
366  *
367  * @param i Species one - this is a bimolecular correction routine
368  * @param j species two - this is a bimolecular correction routine
369  * @param tr Database of species properties read in from the input xml file.
370  * @param f_eps Multiplicative correction factor to be applied to epsilon(i,j)
371  * @param f_sigma Multiplicative correction factor to be applied to diam(i,j)
372  */
373  void makePolarCorrections(size_t i, size_t j,
374  const GasTransportParams& tr, doublereal& f_eps,
375  doublereal& f_sigma);
376 
377  //! Boolean indicating whether to turn on verbose printing
378  bool m_verbose;
379 
380  //! Mapping between between the string name for a transport model and the
381  //! integer name.
382  std::map<std::string, int> m_models;
383 
384  //! Inverse mapping of transport models, from integer constant to string
385  std::map<int, std::string> m_modelNames;
386 
387  //! Mapping between between the string name
388  //! for a transport property and the integer name.
389  std::map<std::string, TransportPropertyType> m_tranPropMap;
390 
391  //! Mapping between between the string name for a
392  //! species-specific transport property model and the integer name.
393  std::map<std::string, LTPTemperatureDependenceType> m_LTRmodelMap;
394 
395  //! Mapping between between the string name for a
396  //! liquid mixture transport property model and the integer name.
397  std::map<std::string, LiquidTranMixingModel> m_LTImodelMap;
398 };
399 
400 //! Create a new transport manager instance.
401 /*!
402  * @param transportModel String identifying the transport model to be
403  * instantiated, defaults to the empty string
404  * @param thermo ThermoPhase object associated with the phase, defaults to null pointer
405  * @param loglevel int containing the Loglevel, defaults to zero
406  * @param f ptr to the TransportFactory object if it's been malloced.
407  * @param ndim Number of dimensions for transport fluxes
408  *
409  * @ingroup tranprops
410  */
411 Transport* newTransportMgr(const std::string& transportModel = "", thermo_t* thermo = 0, int loglevel = 0,
412  TransportFactory* f = 0, int ndim=1);
413 
414 //! Create a new transport manager instance.
415 /*!
416  * @param thermo ThermoPhase object associated with the phase
417  * @param loglevel int containing the Loglevel, defaults to zero
418  * @param f ptr to the TransportFactory object if it's been
419  * allocated.
420  * @return Returns a transport manager for the phase
421  *
422  * @ingroup tranprops
423  */
424 Transport* newDefaultTransportMgr(thermo_t* thermo, int loglevel = 0, TransportFactory* f = 0);
425 
426 } // End of namespace Cantera
427 
428 #endif
TransportPropertyType
Enumeration of the types of transport properties that can be handled by the variables in the various ...
Definition: LTPspecies.h:32
This structure holds transport model parameters relevant to transport in ideal gases with a kinetic t...
void getTransportData(const std::vector< const XML_Node * > &xspecies, XML_Node &log, const std::vector< std::string > &names, GasTransportParams &tr)
Read the transport database.
virtual Transport * newTransport(const std::string &model, thermo_t *thermo, int log_level=0, int ndim=1)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
Factory class for creating new instances of classes derived from Transport.
void getSolidTransportData(const XML_Node &transportNode, XML_Node &log, const std::string phaseName, SolidTransportData &tr)
Read transport property data from a file for a solid phase.
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
Transport * newTransportMgr(const std::string &transportModel, thermo_t *thermo, int loglevel, TransportFactory *f, int ndim)
Create a new transport manager instance.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
Header file defining class SolidTransportData.
Base class for transport property managers.
void fitProperties(GasTransportParams &tr, MMCollisionInt &integrals, std::ostream &logfile)
Generate polynomial fits to the viscosity, conductivity, and the binary diffusion coefficients...
std::map< int, std::string > m_modelNames
Inverse mapping of transport models, from integer constant to string.
Base class for factories.
Definition: FactoryBase.h:18
void getLiquidSpeciesTransportData(const std::vector< const XML_Node * > &db, XML_Node &log, const std::vector< std::string > &names, LiquidTransportParams &tr)
Read transport property data from a file for a list of species that comprise the phase.
virtual void initTransport(Transport *tr, thermo_t *thermo, int mode=0, int log_level=0)
Initialize an existing transport manager.
static TransportFactory * s_factory
Static instance of the factor -> This is the only instance of this object allowed.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
static std::string modelName(int model)
Get the name of the transport model corresponding to the specified constant.
Class LiquidTransportParams holds transport model parameters relevant to transport in mixtures...
void getLiquidInteractionsTransportData(const XML_Node &phaseTran_db, XML_Node &log, const std::vector< std::string > &names, LiquidTransportParams &tr)
Read transport property data from a file for interactions between species.
void getBinDiffCorrection(doublereal t, const GasTransportParams &tr, MMCollisionInt &integrals, size_t k, size_t j, doublereal xk, doublereal xj, doublereal &fkj, doublereal &fjk)
Second-order correction to the binary diffusion coefficients.
Header file defining class LiquidTransportParams.
TransportFactory()
The constructor is private; use static method factory() to get a pointer to a factory instance...
std::map< std::string, TransportPropertyType > m_tranPropMap
Mapping between between the string name for a transport property and the integer name.
void setupSolidTransport(std::ostream &flog, thermo_t *thermo, int log_level, SolidTransportData &trParam)
Prepare to build a new transport manager for solids.
std::map< std::string, LiquidTranMixingModel > m_LTImodelMap
Mapping between between the string name for a liquid mixture transport property model and the integer...
virtual LiquidTranInteraction * newLTI(const XML_Node &trNode, TransportPropertyType tp_ind, LiquidTransportParams &trParam)
Factory function for the construction of new LiquidTranInteraction objects, which are transport model...
std::map< std::string, int > m_models
Mapping between between the string name for a transport model and the integer name.
void setupMM(std::ostream &flog, const std::vector< const XML_Node * > &transport_database, thermo_t *thermo, int mode, int log_level, GasTransportParams &tr)
Prepare to build a new kinetic-theory-based transport manager for low-density gases.
bool m_verbose
Boolean indicating whether to turn on verbose printing.
Class LTPspecies holds transport parameters for a specific liquid-phase species.
Definition: LTPspecies.h:73
static TransportFactory * factory()
Return a pointer to a TransportFactory instance.
void makePolarCorrections(size_t i, size_t j, const GasTransportParams &tr, doublereal &f_eps, doublereal &f_sigma)
Corrections for polar-nonpolar binary diffusion coefficients.
virtual void initLiquidTransport(Transport *tr, thermo_t *thermo, int log_level=0)
Initialize an existing transport manager for liquid phase.
std::map< std::string, LTPTemperatureDependenceType > m_LTRmodelMap
Mapping between between the string name for a species-specific transport property model and the integ...
void setupLiquidTransport(std::ostream &flog, thermo_t *thermo, int log_level, LiquidTransportParams &trParam)
Prepare to build a new transport manager for liquids assuming that viscosity transport data is provid...
Calculation of Collision integrals.
void fitCollisionIntegrals(std::ostream &logfile, GasTransportParams &tr, MMCollisionInt &integrals)
Generate polynomial fits to collision integrals.
virtual LTPspecies * newLTP(const XML_Node &trNode, const std::string &name, TransportPropertyType tp_ind, thermo_t *thermo)
Make one of several transport models, and return a base class pointer to it.
Transport * newDefaultTransportMgr(thermo_t *thermo, int loglevel, TransportFactory *f)
Create a new transport manager instance.
virtual void initSolidTransport(Transport *tr, thermo_t *thermo, int log_level=0)
Initialize an existing transport manager for solid phase.
static mutex_t transport_mutex
Static instance of the mutex used to ensure the proper reading of the transport database.
virtual void deleteFactory()
Deletes the statically allocated factory instance.
Class SolidTransportData holds transport parameters for a specific solid-phase species.
Base class to handle transport property evaluation in a mixture.
File contains the FactoryBase class declarations.