Cantera  2.1.2
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  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 
74 LTPspecies& LTPspecies::operator=(const LTPspecies& right)
75 {
76  if (&right != this) {
77  m_speciesName = right.m_speciesName;
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 
92 LTPspecies::~LTPspecies()
93 {
94 }
95 
97 {
98  return 0.0;
99 }
100 
102 {
103  return (m_coeffs[0] > 0);
104 
105 }
106 
107 doublereal LTPspecies::getMixWeight() const
108 {
109  return m_mixWeight;
110 }
111 
113 {
114 }
115 
116 LTPspecies_Const::LTPspecies_Const(const XML_Node& propNode, const std::string name,
117  TransportPropertyType tp_ind, const thermo_t* const thermo) :
118  LTPspecies(&propNode, name, tp_ind, thermo)
119 {
120  m_model = LTP_TD_CONSTANT;
121  double A_k = getFloatCurrent(propNode, "toSI");
122  if (A_k > 0.0) {
123  m_coeffs.push_back(A_k);
124  } else {
125  throw LTPError("negative or zero " + propNode.name());
126  }
127 }
128 
130  : LTPspecies()
131 {
132  *this = right; //use assignment operator to do other work
133 }
134 
135 LTPspecies_Const& LTPspecies_Const::operator=(const LTPspecies_Const& right)
136 {
137  if (&right != this) {
138  LTPspecies::operator=(right);
139  }
140  return *this;
141 }
142 
144 {
145  return new LTPspecies_Const(*this);
146 }
147 
149 {
150  return m_coeffs[0];
151 
152 }
153 
154 LTPspecies_Arrhenius::LTPspecies_Arrhenius(const XML_Node& propNode, const std::string name,
155  TransportPropertyType tp_ind, const thermo_t* thermo) :
156  LTPspecies(&propNode, name, tp_ind, thermo)
157 {
158 
159  m_model = LTP_TD_ARRHENIUS;
160  m_temp = 0.0;
161  m_prop = 0.0;
162 
163  doublereal A_k, n_k, Tact_k;
164  getArrhenius(propNode, A_k, n_k, Tact_k);
165  if (A_k <= 0.0) {
166  throw LTPError("negative or zero " + propNode.name());
167  }
168  m_coeffs.push_back(A_k);
169  m_coeffs.push_back(n_k);
170  m_coeffs.push_back(Tact_k);
171  m_coeffs.push_back(log(A_k));
172 }
173 
175  : LTPspecies()
176 {
177  *this = right;
178 }
179 
180 LTPspecies_Arrhenius& LTPspecies_Arrhenius::operator=(const LTPspecies_Arrhenius& right)
181 {
182  if (&right != this) {
183  LTPspecies::operator=(right);
184  m_temp = right.m_temp;
185  m_logt = right.m_logt;
186  m_prop = right.m_prop;
187  m_logProp = right.m_logProp;
188  }
189  return *this;
190 }
191 
193 {
194  return new LTPspecies_Arrhenius(*this);
195 }
196 
198 {
199  doublereal t = m_thermo->temperature();
200  //m_coeffs[0] holds A
201  //m_coeffs[1] holds n
202  //m_coeffs[2] holds Tact
203  //m_coeffs[3] holds log(A)
204  if (t != m_temp) {
205  m_prop = 0;
206  m_logProp = 0;
207  m_temp = t;
208  m_logt = log(m_temp);
209  //For viscosity the sign convention on positive activation energy is swithced
210  if (m_property == TP_VISCOSITY) {
211  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt + m_coeffs[2] / m_temp ;
212  } else {
213  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt - m_coeffs[2] / m_temp ;
214  }
215  m_prop = exp(m_logProp);
216  }
217  return m_prop;
218 }
219 
220 LTPspecies_Poly::LTPspecies_Poly(const XML_Node& propNode, const std::string name,
221  TransportPropertyType tp_ind, const thermo_t* thermo) :
222  LTPspecies(&propNode, name, tp_ind, thermo),
223  m_temp(-1.0),
224  m_prop(0.0)
225 {
226  m_model = LTP_TD_POLY;
227  getFloatArray(propNode, m_coeffs, "true", "toSI");
228 }
229 
231  : LTPspecies()
232 {
233  *this = right;
234 }
235 
236 LTPspecies_Poly& LTPspecies_Poly::operator=(const LTPspecies_Poly& right)
237 {
238  if (&right != this) {
239  LTPspecies::operator=(right);
240  m_temp = right.m_temp;
241  m_prop = right.m_prop;
242  }
243  return *this;
244 }
245 
247 {
248  return new LTPspecies_Poly(*this);
249 }
250 
252 {
253  doublereal t = m_thermo->temperature();
254  if (t != m_temp) {
255  m_prop = 0.0;
256  m_temp = t;
257  double tempN = 1.0;
258  for (int i = 0; i < (int) m_coeffs.size() ; i++) {
259  m_prop += m_coeffs[i] * tempN;
260  tempN *= m_temp;
261  }
262  }
263  return m_prop;
264 }
265 
266 LTPspecies_ExpT::LTPspecies_ExpT(const XML_Node& propNode, const std::string name, TransportPropertyType tp_ind,
267  const thermo_t* thermo) :
268 
269  LTPspecies(&propNode, name, tp_ind, thermo),
270  m_temp(-1.0),
271  m_prop(0.0)
272 {
273  m_model = LTP_TD_EXPT;
274  getFloatArray(propNode, m_coeffs, "true", "toSI");
275 }
276 
278  : LTPspecies()
279 {
280  *this = right; //use assignment operator to do other work
281 }
282 
283 LTPspecies_ExpT& LTPspecies_ExpT::operator=(const LTPspecies_ExpT& right)
284 {
285  if (&right != this) {
286  LTPspecies::operator=(right);
287  m_temp = right.m_temp;
288  m_prop = right.m_prop;
289  }
290  return *this;
291 }
292 
294 {
295  return new LTPspecies_ExpT(*this);
296 }
297 
299 {
300  doublereal t = m_thermo->temperature();
301  if (t != m_temp) {
302  m_temp=t;
303  m_prop = m_coeffs[0];
304  doublereal tempN = 1.0;
305  doublereal tmp = 0.0;
306  for (int i = 1; i < (int) m_coeffs.size() ; i++) {
307  tempN *= m_temp;
308  tmp += m_coeffs[i] * tempN;
309  }
310  m_prop *= exp(tmp);
311  }
312  return m_prop;
313 }
314 
315 }
doublereal m_logProp
logarithm of most recent evaluation of transport property
Definition: LTPspecies.h:298
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:143
TransportPropertyType
Enumeration of the types of transport properties that can be handled by the variables in the various ...
Definition: LTPspecies.h:32
virtual doublereal getSpeciesTransProp()
Returns the vector of pure species transport property.
Definition: LTPspecies.cpp:96
virtual void adjustCoeffsForComposition()
Internal model to adjust species-specific properties for composition.
Definition: LTPspecies.cpp:112
doublereal m_logt
logarithm of current temperature
Definition: LTPspecies.h:292
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:116
doublereal getSpeciesTransProp()
Returns the pure species transport property.
Definition: LTPspecies.cpp:298
virtual bool checkPositive() const
Check to see if the property evaluation will be positive.
Definition: LTPspecies.cpp:101
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
doublereal getSpeciesTransProp()
Returns the pure species transport property.
Definition: LTPspecies.cpp:148
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
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.
Definition: LTPspecies.h:134
Class LTPspecies_Arrhenius holds transport parameters for a specific liquid-phase species (LTPspecies...
Definition: LTPspecies.h:241
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:289
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:154
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:246
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:295
const thermo_t * m_thermo
Pointer to a const thermo object to get current temperature.
Definition: LTPspecies.h:146
doublereal getMixWeight() const
Return the weight mixture.
Definition: LTPspecies.cpp:107
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:192
doublereal getSpeciesTransProp()
Return the pure species value for this transport property evaluated from the Arrhenius expression...
Definition: LTPspecies.cpp:197
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:220
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:266
LTPTemperatureDependenceType m_model
Model type for the temperature dependence.
Definition: LTPspecies.h:137
std::string name() const
Returns the name of the XML node.
Definition: xml.h:390
doublereal getFloatCurrent(const Cantera::XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
Definition: ctml.cpp:279
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
vector_fp m_coeffs
Model temperature-dependence ceofficients.
Definition: LTPspecies.h:143
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:293
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:574
doublereal getSpeciesTransProp()
Returns the pure species transport property.
Definition: LTPspecies.cpp:251
Class LTPspecies_Const holds transport parameters for a specific liquid-phase species (LTPspecies) wh...
Definition: LTPspecies.h:182
Class LTPspecies holds transport parameters for a specific liquid-phase species.
Definition: LTPspecies.h:73
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:87
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
Class LTPspecies_ExpT holds transport parameters for a specific liquid- phase species (LTPspecies) wh...
Definition: LTPspecies.h:391
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:361
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:425
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:358
LTPError(const std::string &msg)
Constructor is a wrapper around CanteraError.
Definition: LTPspecies.cpp:24
doublereal m_mixWeight
Weighting used for mixing.
Definition: LTPspecies.h:160
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:428
Class LTPspecies_Poly holds transport parameters for a specific liquid-phase species (LTPspecies) whe...
Definition: LTPspecies.h:326
size_t getFloatArray(const Cantera::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:419
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:140
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