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