Cantera  2.0
LTPspecies.cpp
Go to the documentation of this file.
1 /**
2  * @file LTPspecies.cpp \
3  * definitions for the LTPspecies objects and its children, which is the virtual base class
4  * for describing temperature dependence of submodels for transport parameters
5  * (see \ref tranprops and \link Cantera::LTPspecies LTPspecies \endlink) .
6  */
7 
9 using namespace std;
10 using namespace ctml;
11 
12 namespace Cantera
13 {
14 //====================================================================================================================
15 //! Exception thrown if an error is encountered while reading the transport database.
16 class LTPError : public CanteraError
17 {
18 public:
19 
20  //! Constructor is a wrapper around CanteraError
21  /*!
22  * @param msg Informative message
23  */
24  LTPError(std::string msg) :
25  CanteraError("LTPspecies", "error parsing transport data: " + msg + "\n") {
26  }
27 };
28 //====================================================================================================================
29 //! getArrhenius() parses the xml element called Arrhenius.
30 /*!
31  * The Arrhenius expression is
32  * \f[
33  * k = A T^(b) exp (-E_a / RT)
34  * \f]
35  *
36  * @param node XML_Node to be read
37  * @param A Output pre-exponential factor. The units are variable.
38  * @param b output temperature power
39  * @param E Output activation energy in units of Kelvin
40  */
41 static void getArrhenius(const XML_Node& node,
42  doublereal& A, doublereal& b, doublereal& E)
43 {
44  /* parse the children for the A, b, and E components.
45  */
46  A = getFloat(node, "A", "toSI");
47  b = getFloat(node, "b");
48  E = getFloat(node, "E", "actEnergy");
49  E /= GasConstant;
50 }
51 //====================================================================================================================
52 // Construct an LTPspecies object for a liquid transport property.
53 /*
54  * The species transport property is constructed from the XML node,
55  * \verbatim <propNode>, \endverbatim that is a child of the
56  * \verbatim <transport> \endverbatim node in the species block and specifies a type of transport
57  * property (like viscosity)
58  *
59  * @param propNode Pointer to the XML node that contains the property information
60  * @param name String containing the species name
61  * @param tp_ind enum TransportPropertyType containing the property id that this object
62  * is creating a parameterization for (e.g., viscosity)
63  * @param thermo const pointer to the ThermoPhase object, which is used to find the temperature.
64  */
65 LTPspecies::LTPspecies(const XML_Node* const propNode, std::string name,
66  TransportPropertyType tp_ind, const thermo_t* thermo) :
67  m_speciesName(name),
68  m_model(LTP_TD_NOTSET),
69  m_property(tp_ind),
70  m_thermo(thermo),
71  m_mixWeight(1.0)
72 {
73  if (propNode) {
74  if (propNode->hasChild("mixtureWeighting")) {
75  m_mixWeight = getFloat(*propNode, "mixtureWeighting");
76  }
77  }
78 }
79 //====================================================================================================================
80 // Copy constructor
82 {
83  *this = right;
84 }
85 //====================================================================================================================
86 // Assignment operator
88 {
89  if (&right != this) {
91  m_property = right.m_property;
92  m_model = right.m_model;
93  m_coeffs = right.m_coeffs;
94  m_thermo = right.m_thermo;
95  m_mixWeight = right.m_mixWeight;
96  }
97  return *this;
98 }
99 //====================================================================================================================
100 // Duplication routine
101 /*
102  * @return Returns a copy of this routine as a pointer to LTPspecies
103  */
105 {
106  LTPspecies* prp = new LTPspecies(*this);
107  return prp;
108 }
109 //====================================================================================================================
111 {
112 }
113 //====================================================================================================================
114 // Returns the vector of pure species transport property
115 /*
116  * The pure species transport property (i.e. pure species viscosity)
117  * is returned. Any temperature and composition dependence will be
118  * adjusted internally according to the information provided by the
119  * subclass object.
120  */
122 {
123  return 0.0;
124 }
125 //====================================================================================================================
126 // Check to see if the property evaluation will be positive
128 {
129  return (m_coeffs[0] > 0);
130 }
131 //====================================================================================================================
132 doublereal LTPspecies::getMixWeight() const
133 {
134  return m_mixWeight;
135 }
136 //====================================================================================================================
137 // Internal model to adjust species-specific properties for composition.
138 /*
139  * Currently just a place holder, but this method could take
140  * the composition from the thermo object and adjust coefficients
141  * accoding to some unspecified model.
142  */
144 {
145 }
146 //====================================================================================================================
147 // Construct an LTPspecies object for a liquid transport property
148 // expressed as a constant value.
149 /* The transport property is constructed from the XML node,
150  * \verbatim <propNode>, \endverbatim that is a child of the
151  * \verbatim <transport> \endverbatim node and specifies a type of
152  * transport property (like viscosity)
153  */
154 LTPspecies_Const::LTPspecies_Const(const XML_Node& propNode, std::string name,
155  TransportPropertyType tp_ind, const thermo_t* const thermo) :
156  LTPspecies(&propNode, name, tp_ind, thermo)
157 {
158  m_model = LTP_TD_CONSTANT;
159  double A_k = getFloatCurrent(propNode, "toSI");
160  if (A_k > 0.0) {
161  m_coeffs.push_back(A_k);
162  } else {
163  throw LTPError("negative or zero " + propNode.name());
164  }
165 }
166 //====================================================================================================================
167 // Copy constructor
169  : LTPspecies()
170 {
171  *this = right; //use assignment operator to do other work
172 }
173 //====================================================================================================================
174 // Assignment operator
176 {
177  if (&right != this) {
178  LTPspecies::operator=(right);
179  }
180  return *this;
181 }
182 //====================================================================================================================
184 {
185 }
186 //====================================================================================================================
187 // Duplication routine
188 /*
189  * @return Returns a copy of this routine as a pointer to LTPspecies
190  */
192 {
193  LTPspecies_Const* prp = new LTPspecies_Const(*this);
194  return (dynamic_cast<LTPspecies*>(prp));
195 }
196 //====================================================================================================================
197 // Return the (constant) value for this transport property
199 {
200  return m_coeffs[0];
201 }
202 //====================================================================================================================
203 // Construct an LTPspecies object for a liquid transport property
204 // expressed in extended Arrhenius form.
205 /*
206  * The transport property is constructed from the XML node,
207  * \verbatim <propNode>, \endverbatim that is a child of the
208  * \verbatim <transport> \endverbatim node and specifies a type of transport property (like viscosity)
209  *
210  *
211  * @param propNode Reference to the XML node that contains the property information.This class
212  * is assumed to be parameterized by reading XML_Node information.
213  * @param name String containing the species name
214  * @param tp_ind enum TransportPropertyType containing the property id that this object
215  * is creating a parameterization for (e.g., viscosity)
216  * @param thermo const pointer to the ThermoPhase object, which is used to find the temperature.
217  *
218  */
219 LTPspecies_Arrhenius::LTPspecies_Arrhenius(const XML_Node& propNode, std::string name,
220  TransportPropertyType tp_ind, const thermo_t* thermo) :
221  LTPspecies(&propNode, name, tp_ind, thermo)
222 {
223  m_model = LTP_TD_ARRHENIUS;
224  m_temp = 0.0;
225  m_prop = 0.0;
226 
227  doublereal A_k, n_k, Tact_k;
228  getArrhenius(propNode, A_k, n_k, Tact_k);
229  if (A_k <= 0.0) {
230  throw LTPError("negative or zero " + propNode.name());
231  }
232  m_coeffs.push_back(A_k);
233  m_coeffs.push_back(n_k);
234  m_coeffs.push_back(Tact_k);
235  m_coeffs.push_back(log(A_k));
236 }
237 //====================================================================================================================
238 // Copy constructor
240  : LTPspecies()
241 {
242  *this = right;
243 }
244 //====================================================================================================================
245 // Assignment operator
247 {
248  if (&right != this) {
249  LTPspecies::operator=(right);
250  m_temp = right.m_temp;
251  m_logt = right.m_logt;
252  m_prop = right.m_prop;
253  m_logProp = right.m_logProp;
254  }
255  return *this;
256 }
257 //====================================================================================================================
258 // Destructor
260 {
261 }
262 //====================================================================================================================
263 // Duplication routine
264 /*
265  * @return Returns a copy of this routine as a pointer to LTPspecies
266  */
268 {
269  LTPspecies_Arrhenius* prp = new LTPspecies_Arrhenius(*this);
270  return (dynamic_cast<LTPspecies*>(prp));
271 }
272 //===================================================================================================================
273 // Return the pure species value for this transport property evaluated
274 // from the Arrhenius expression
275 /*
276  * In general the Arrhenius expression is
277  *
278  * \f[
279  * \mu = A T^n \exp(- E / R T).
280  * \f]
281  *
282  * Note that for viscosity, the convention is such that
283  * a positive activation energy corresponds to the typical
284  * case of a positive argument to the exponential so that
285  * the Arrhenius expression is
286  *
287  * \f[
288  * \mu = A T^n \exp(+ E / R T).
289  * \f]
290  *
291  * Any temperature and composition dependence will be
292  * adjusted internally according to the information provided.
293  */
295 {
296 
297  doublereal t = m_thermo->temperature();
298  //m_coeffs[0] holds A
299  //m_coeffs[1] holds n
300  //m_coeffs[2] holds Tact
301  //m_coeffs[3] holds log(A)
302  if (t != m_temp) {
303  m_prop = 0;
304  m_logProp = 0;
305  m_temp = t;
306  m_logt = log(m_temp);
307  //For viscosity the sign convention on positive activation energy is swithced
308  if (m_property == TP_VISCOSITY) {
309  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt + m_coeffs[2] / m_temp ;
310  } else {
311  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt - m_coeffs[2] / m_temp ;
312  }
313  m_prop = exp(m_logProp);
314  }
315  return m_prop;
316 }
317 //====================================================================================================================
318 // Construct an LTPspecies object for a liquid transport property expressed as a polynomial in temperature.
319 /*
320  * The transport property is constructed from the XML node, \verbatim <propNode>, \endverbatim that is a child of the
321  * \verbatim <transport> \endverbatim node and specifies a type of transport property (like viscosity).
322  *
323  *
324  * @param propNode Reference to the XML node that contains the property information. This class
325  * must be parameterized by reading XML_Node information.
326  * @param name String containing the species name
327  * @param tp_ind enum TransportPropertyType containing the property id that this object
328  * is creating a parameterization for (e.g., viscosity)
329  * @param thermo const pointer to the ThermoPhase object, which is used to find the temperature.
330  *
331  */
332 LTPspecies_Poly::LTPspecies_Poly(const XML_Node& propNode, std::string name,
333  TransportPropertyType tp_ind, const thermo_t* thermo) :
334  LTPspecies(&propNode, name, tp_ind, thermo),
335  m_temp(-1.0),
336  m_prop(0.0)
337 {
338  m_model = LTP_TD_POLY;
339  getFloatArray(propNode, m_coeffs, "true", "toSI");
340 }
341 //====================================================================================================================
342 // Copy constructor
344  : LTPspecies()
345 {
346  *this = right;
347 }
348 //====================================================================================================================
349 // Assignment operator
351 {
352  if (&right != this) {
353  LTPspecies::operator=(right);
354  m_temp = right.m_temp;
355  m_prop = right.m_prop;
356  }
357  return *this;
358 }
359 //====================================================================================================================
361 {
362 }
363 //====================================================================================================================
364 // Duplication routine
365 /*
366  * @return Returns a copy of this routine as a pointer to LTPspecies
367  */
369 {
370  LTPspecies_Poly* prp = new LTPspecies_Poly(*this);
371  return (dynamic_cast<LTPspecies*>(prp));
372 }
373 //====================================================================================================================
374 // Return the value for this transport property evaluated from the polynomial expression
376 {
377  doublereal t = m_thermo->temperature();
378  if (t != m_temp) {
379  m_prop = 0.0;
380  m_temp = t;
381  double tempN = 1.0;
382  for (int i = 0; i < (int) m_coeffs.size() ; i++) {
383  m_prop += m_coeffs[i] * tempN;
384  tempN *= m_temp;
385  }
386  }
387  return m_prop;
388 }
389 //====================================================================================================================
390 // Construct an LTPspecies object for a liquid transport property
391 // expressed as an exponential in temperature.
392 /*
393  * The transport property is constructed from the XML node, \verbatim <propNode>, \endverbatim that is a child of the
394  * \verbatim <transport> \endverbatim node and specifies a type of transport property (like viscosity).
395  *
396  *
397  * @param propNode Reference to the XML node that contains the property information. This class
398  * must be parameterized by reading XML_Node information.
399  * @param name String containing the species name
400  * @param tp_ind enum TransportPropertyType containing the property id that this object
401  * is creating a parameterization for (e.g., viscosity)
402  * @param thermo const pointer to the ThermoPhase object, which is used to find the temperature.
403  *
404  */
405 LTPspecies_ExpT::LTPspecies_ExpT(const XML_Node& propNode, std::string name, TransportPropertyType tp_ind,
406  const thermo_t* thermo) :
407  LTPspecies(&propNode, name, tp_ind, thermo),
408  m_temp(-1.0),
409  m_prop(0.0)
410 {
411  m_model = LTP_TD_EXPT;
412  getFloatArray(propNode, m_coeffs, "true", "toSI");
413 }
414 //====================================================================================================================
415 // Copy constructor
417  : LTPspecies()
418 {
419  *this = right; //use assignment operator to do other work
420 }
421 //====================================================================================================================
422 // Assignment operator
424 {
425  if (&right != this) {
426  LTPspecies::operator=(right);
427  m_temp = right.m_temp;
428  m_prop = right.m_prop;
429  }
430  return *this;
431 }
432 //====================================================================================================================
434 {
435 }
436 //====================================================================================================================
437 // Duplication routine
438 /*
439  * @return Returns a copy of this routine as a pointer to LTPspecies
440  */
442 {
443  LTPspecies_ExpT* prp = new LTPspecies_ExpT(*this);
444  return (dynamic_cast<LTPspecies*>(prp));
445 }
446 //====================================================================================================================
447 // Return the value for this transport property evaluated
448 // from the exponential in temperature expression
450 {
451  doublereal t = m_thermo->temperature();
452  if (t != m_temp) {
453  m_temp=t;
454  m_prop = m_coeffs[0];
455  doublereal tempN = 1.0;
456  doublereal tmp = 0.0;
457  for (int i = 1; i < (int) m_coeffs.size() ; i++) {
458  tempN *= m_temp;
459  tmp += m_coeffs[i] * tempN;
460  }
461  m_prop *= exp(tmp);
462  }
463  return m_prop;
464 }
465 //====================================================================================================================
466 }