Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include "cantera/base/ctml.h"
10 
11 using namespace std;
12 
13 namespace Cantera
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  explicit LTPError(const std::string& msg) :
25  CanteraError("LTPspecies", "error parsing transport data: " + msg + "\n") {
26  }
27 };
28 
29 //! 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 
53 LTPspecies::LTPspecies(const XML_Node* const propNode, const std::string name,
54  TransportPropertyType tp_ind, const thermo_t* thermo) :
55  m_speciesName(name),
56  m_model(LTP_TD_NOTSET),
57  m_property(tp_ind),
58  m_thermo(thermo),
59  m_mixWeight(1.0)
60 {
61  if (propNode) {
62  if (propNode->hasChild("mixtureWeighting")) {
63  m_mixWeight = getFloat(*propNode, "mixtureWeighting");
64  }
65  }
66 }
67 
69 {
70 
71  *this = right;
72 }
73 
75 {
76  if (&right != this) {
78  m_property = right.m_property;
79  m_model = right.m_model;
80  m_coeffs = right.m_coeffs;
81  m_thermo = right.m_thermo;
82  m_mixWeight = right.m_mixWeight;
83  }
84  return *this;
85 }
86 
88 {
89  return new LTPspecies(*this);
90 }
91 
93 {
94  return 0.0;
95 }
96 
98 {
99  return (m_coeffs[0] > 0);
100 
101 }
102 
103 doublereal LTPspecies::getMixWeight() const
104 {
105  return m_mixWeight;
106 }
107 
109 {
110 }
111 
112 LTPspecies_Const::LTPspecies_Const(const XML_Node& propNode, const std::string name,
113  TransportPropertyType tp_ind, const thermo_t* const thermo) :
114  LTPspecies(&propNode, name, tp_ind, thermo)
115 {
116  m_model = LTP_TD_CONSTANT;
117  double A_k = getFloatCurrent(propNode, "toSI");
118  if (A_k > 0.0) {
119  m_coeffs.push_back(A_k);
120  } else {
121  throw LTPError("negative or zero " + propNode.name());
122  }
123 }
124 
126  : LTPspecies()
127 {
128  *this = right; //use assignment operator to do other work
129 }
130 
132 {
133  if (&right != this) {
134  LTPspecies::operator=(right);
135  }
136  return *this;
137 }
138 
140 {
141  return new LTPspecies_Const(*this);
142 }
143 
145 {
146  return m_coeffs[0];
147 
148 }
149 
150 LTPspecies_Arrhenius::LTPspecies_Arrhenius(const XML_Node& propNode, const std::string name,
151  TransportPropertyType tp_ind, const thermo_t* thermo) :
152  LTPspecies(&propNode, name, tp_ind, thermo)
153 {
154 
155  m_model = LTP_TD_ARRHENIUS;
156  m_temp = 0.0;
157  m_prop = 0.0;
158 
159  doublereal A_k, n_k, Tact_k;
160  getArrhenius(propNode, A_k, n_k, Tact_k);
161  if (A_k <= 0.0) {
162  throw LTPError("negative or zero " + propNode.name());
163  }
164  m_coeffs.push_back(A_k);
165  m_coeffs.push_back(n_k);
166  m_coeffs.push_back(Tact_k);
167  m_coeffs.push_back(log(A_k));
168 }
169 
171 {
172  *this = right;
173 }
174 
176 {
177  if (&right != this) {
178  LTPspecies::operator=(right);
179  m_temp = right.m_temp;
180  m_logt = right.m_logt;
181  m_prop = right.m_prop;
182  m_logProp = right.m_logProp;
183  }
184  return *this;
185 }
186 
188 {
189  return new LTPspecies_Arrhenius(*this);
190 }
191 
193 {
194  doublereal t = m_thermo->temperature();
195  //m_coeffs[0] holds A
196  //m_coeffs[1] holds n
197  //m_coeffs[2] holds Tact
198  //m_coeffs[3] holds log(A)
199  if (t != m_temp) {
200  m_prop = 0;
201  m_logProp = 0;
202  m_temp = t;
203  m_logt = log(m_temp);
204  //For viscosity the sign convention on positive activation energy is swithced
205  if (m_property == TP_VISCOSITY) {
206  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt + m_coeffs[2] / m_temp ;
207  } else {
208  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt - m_coeffs[2] / m_temp ;
209  }
210  m_prop = exp(m_logProp);
211  }
212  return m_prop;
213 }
214 
215 LTPspecies_Poly::LTPspecies_Poly(const XML_Node& propNode, const std::string name,
216  TransportPropertyType tp_ind, const thermo_t* thermo) :
217  LTPspecies(&propNode, name, tp_ind, thermo),
218  m_temp(-1.0),
219  m_prop(0.0)
220 {
221  m_model = LTP_TD_POLY;
222  getFloatArray(propNode, m_coeffs, "true", "toSI");
223 }
224 
226  : LTPspecies()
227 {
228  *this = right;
229 }
230 
232 {
233  if (&right != this) {
234  LTPspecies::operator=(right);
235  m_temp = right.m_temp;
236  m_prop = right.m_prop;
237  }
238  return *this;
239 }
240 
242 {
243  return new LTPspecies_Poly(*this);
244 }
245 
247 {
248  doublereal t = m_thermo->temperature();
249  if (t != m_temp) {
250  m_prop = 0.0;
251  m_temp = t;
252  double tempN = 1.0;
253  for (int i = 0; i < (int) m_coeffs.size() ; i++) {
254  m_prop += m_coeffs[i] * tempN;
255  tempN *= m_temp;
256  }
257  }
258  return m_prop;
259 }
260 
261 LTPspecies_ExpT::LTPspecies_ExpT(const XML_Node& propNode, const std::string name, TransportPropertyType tp_ind,
262  const thermo_t* thermo) :
263 
264  LTPspecies(&propNode, name, tp_ind, thermo),
265  m_temp(-1.0),
266  m_prop(0.0)
267 {
268  m_model = LTP_TD_EXPT;
269  getFloatArray(propNode, m_coeffs, "true", "toSI");
270 }
271 
273  : LTPspecies()
274 {
275  *this = right; //use assignment operator to do other work
276 }
277 
279 {
280  if (&right != this) {
281  LTPspecies::operator=(right);
282  m_temp = right.m_temp;
283  m_prop = right.m_prop;
284  }
285  return *this;
286 }
287 
289 {
290  return new LTPspecies_ExpT(*this);
291 }
292 
294 {
295  doublereal t = m_thermo->temperature();
296  if (t != m_temp) {
297  m_temp=t;
298  m_prop = m_coeffs[0];
299  doublereal tempN = 1.0;
300  doublereal tmp = 0.0;
301  for (int i = 1; i < (int) m_coeffs.size() ; i++) {
302  tempN *= m_temp;
303  tmp += m_coeffs[i] * tempN;
304  }
305  m_prop *= exp(tmp);
306  }
307  return m_prop;
308 }
309 
310 }
doublereal m_logProp
logarithm of most recent evaluation of transport property
Definition: LTPspecies.h:345
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplicates the current object given the parent class reference.
Definition: LTPspecies.cpp:139
TransportPropertyType
Enumeration of the types of transport properties that can be handled by the variables in the various ...
Definition: LTPspecies.h:31
virtual doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:92
LTPspecies_Const & operator=(const LTPspecies_Const &right)
Assignment operator.
Definition: LTPspecies.cpp:131
virtual void adjustCoeffsForComposition()
Internal model to adjust species-specific properties for the composition.
Definition: LTPspecies.cpp:108
doublereal m_logt
logarithm of current temperature
Definition: LTPspecies.h:339
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
LTPspecies_Const(const XML_Node &propNode, const std::string name, TransportPropertyType tp_ind, const thermo_t *const thermo)
Construct an LTPspecies object for a liquid transport property expressed as a constant value...
Definition: LTPspecies.cpp:112
doublereal getSpeciesTransProp()
Returns the standard state species transport property.
Definition: LTPspecies.cpp:293
virtual bool checkPositive() const
Check to see if the property evaluation will be positive.
Definition: LTPspecies.cpp:97
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
doublereal getSpeciesTransProp()
Returns the standard state species transport property.
Definition: LTPspecies.cpp:144
static void getArrhenius(const XML_Node &node, int &labeled, doublereal &A, doublereal &b, doublereal &E)
getArrhenius() parses the XML element called Arrhenius.
Header file defining class LTPspecies and its child classes.
std::string m_speciesName
Species Name for the property that is being described.
Definition: LTPspecies.h:148
Class LTPspecies_Arrhenius holds transport parameters for a specific liquid-phase species (LTPspecies...
Definition: LTPspecies.h:271
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:336
LTPspecies & operator=(const LTPspecies &right)
Assignment operator.
Definition: LTPspecies.cpp:74
LTPspecies_Arrhenius(const XML_Node &propNode, const std::string name, TransportPropertyType tp_ind, const thermo_t *thermo)
Construct an LTPspecies object for a liquid transport property expressed in extended Arrhenius form...
Definition: LTPspecies.cpp:150
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplicates the current object given the parent class reference.
Definition: LTPspecies.cpp:241
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:342
const thermo_t * m_thermo
Pointer to a const thermo object to get current temperature.
Definition: LTPspecies.h:160
doublereal getMixWeight() const
Return the weight mixture.
Definition: LTPspecies.cpp:103
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplicates the current object given the parent class reference.
Definition: LTPspecies.cpp:187
doublereal getSpeciesTransProp()
Return the standard state species value for this transport property evaluated from the Arrhenius expr...
Definition: LTPspecies.cpp:192
LTPspecies_Poly(const XML_Node &propNode, const std::string name, TransportPropertyType tp_ind, const thermo_t *thermo)
Construct an LTPspecies object for a liquid transport property expressed as a polynomial in temperatu...
Definition: LTPspecies.cpp:215
LTPspecies_ExpT(const XML_Node &propNode, const std::string name, TransportPropertyType tp_ind, const thermo_t *thermo)
Construct an LTPspecies object for a liquid transport property expressed as an exponential in tempera...
Definition: LTPspecies.cpp:261
doublereal getFloatCurrent(const XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
Definition: ctml.cpp:206
LTPTemperatureDependenceType m_model
Model type for the temperature dependence.
Definition: LTPspecies.h:151
std::string name() const
Returns the name of the XML node.
Definition: xml.h:394
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
vector_fp m_coeffs
Model temperature-dependence ceofficients.
Definition: LTPspecies.h:157
LTPspecies_Arrhenius & operator=(const LTPspecies_Arrhenius &right)
Assignment operator.
Definition: LTPspecies.cpp:175
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplicates the current object given the parent class reference.
Definition: LTPspecies.cpp:288
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:563
doublereal getSpeciesTransProp()
Returns the standard state species transport property.
Definition: LTPspecies.cpp:246
Class LTPspecies_Const holds transport parameters for a specific liquid-phase species (LTPspecies) wh...
Definition: LTPspecies.h:195
Class LTPspecies holds transport parameterizations for a specific liquid-phase species.
Definition: LTPspecies.h:72
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:87
LTPspecies_Poly & operator=(const LTPspecies_Poly &right)
Assignment operator.
Definition: LTPspecies.cpp:231
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
Class LTPspecies_ExpT holds transport parameters for a specific liquid- phase species (LTPspecies) wh...
Definition: LTPspecies.h:455
size_t getFloatArray(const XML_Node &node, std::vector< doublereal > &v, const bool convert, const std::string &unitsString, const std::string &nodeName)
This function reads the current node or a child node of the current node with the default name...
Definition: ctml.cpp:323
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:194
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:425
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:506
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:422
LTPError(const std::string &msg)
Constructor is a wrapper around CanteraError.
Definition: LTPspecies.cpp:24
LTPspecies_ExpT & operator=(const LTPspecies_ExpT &right)
Assignment operator.
Definition: LTPspecies.cpp:278
doublereal m_mixWeight
Weighting used for mixing.
Definition: LTPspecies.h:174
doublereal m_prop
most recent evaluation of the transport property
Definition: LTPspecies.h:509
Class LTPspecies_Poly holds transport parameters for a specific liquid-phase species (LTPspecies) whe...
Definition: LTPspecies.h:373
static void getArrhenius(const XML_Node &node, doublereal &A, doublereal &b, doublereal &E)
Parses the XML element called Arrhenius.
Definition: LTPspecies.cpp:41
Exception thrown if an error is encountered while reading the transport database. ...
TransportPropertyType m_property
enum indicating which property this is (i.e viscosity)
Definition: LTPspecies.h:154
LTPspecies(const XML_Node *const propNode=0, const std::string name="-", TransportPropertyType tp_ind=TP_UNKNOWN, const thermo_t *thermo=0)
Construct an LTPspecies object for a liquid transport property.
Definition: LTPspecies.cpp:53