Cantera  2.3.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 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at http://www.cantera.org/license.txt for license and copyright information.
10 
12 #include "cantera/base/ctml.h"
13 
14 using namespace std;
15 
16 namespace Cantera
17 {
18 //! Exception thrown if an error is encountered while reading the transport database.
19 class LTPError : public CanteraError
20 {
21 public:
22  //! Constructor is a wrapper around CanteraError
23  /*!
24  * @param msg Informative message
25  */
26  explicit LTPError(const std::string& msg) :
27  CanteraError("LTPspecies", "error parsing transport data: " + msg + "\n") {
28  }
29 };
30 
31 //! Parses the XML element called Arrhenius.
32 /*!
33  * The Arrhenius expression is
34  * \f[
35  * k = A T^(b) exp (-E_a / RT)
36  * \f]
37  *
38  * @param node XML_Node to be read
39  * @param A Output pre-exponential factor. The units are variable.
40  * @param b output temperature power
41  * @param E Output activation energy in units of Kelvin
42  */
43 static void getArrhenius(const XML_Node& node,
44  doublereal& A, doublereal& b, doublereal& E)
45 {
46  // parse the children for the A, b, and E components.
47  A = getFloat(node, "A", "toSI");
48  b = getFloat(node, "b");
49  E = getFloat(node, "E", "actEnergy") / GasConstant;
50 }
51 
52 LTPspecies::LTPspecies(const XML_Node* const propNode, const std::string name,
53  TransportPropertyType tp_ind, const thermo_t* thermo) :
54  m_speciesName(name),
55  m_model(LTP_TD_NOTSET),
56  m_property(tp_ind),
57  m_thermo(thermo),
58  m_mixWeight(1.0)
59 {
60  if (propNode && propNode->hasChild("mixtureWeighting")) {
61  m_mixWeight = getFloat(*propNode, "mixtureWeighting");
62  }
63 }
64 
66 {
67  return new LTPspecies(*this);
68 }
69 
71 {
72  return 0.0;
73 }
74 
76 {
77  return (m_coeffs[0] > 0);
78 }
79 
80 doublereal LTPspecies::getMixWeight() const
81 {
82  return m_mixWeight;
83 }
84 
86 {
87 }
88 
89 LTPspecies_Const::LTPspecies_Const(const XML_Node& propNode, const std::string name,
90  TransportPropertyType tp_ind, const thermo_t* const thermo) :
91  LTPspecies(&propNode, name, tp_ind, thermo)
92 {
93  m_model = LTP_TD_CONSTANT;
94  double A_k = getFloatCurrent(propNode, "toSI");
95  if (A_k > 0.0) {
96  m_coeffs.push_back(A_k);
97  } else {
98  throw LTPError("negative or zero " + propNode.name());
99  }
100 }
101 
103 {
104  return new LTPspecies_Const(*this);
105 }
106 
108 {
109  return m_coeffs[0];
110 }
111 
112 LTPspecies_Arrhenius::LTPspecies_Arrhenius(const XML_Node& propNode, const std::string name,
113  TransportPropertyType tp_ind, const thermo_t* thermo) :
114  LTPspecies(&propNode, name, tp_ind, thermo)
115 {
116  m_model = LTP_TD_ARRHENIUS;
117  m_temp = 0.0;
118  m_prop = 0.0;
119 
120  doublereal A_k, n_k, Tact_k;
121  getArrhenius(propNode, A_k, n_k, Tact_k);
122  if (A_k <= 0.0) {
123  throw LTPError("negative or zero " + propNode.name());
124  }
125  m_coeffs.push_back(A_k);
126  m_coeffs.push_back(n_k);
127  m_coeffs.push_back(Tact_k);
128  m_coeffs.push_back(log(A_k));
129 }
130 
132 {
133  return new LTPspecies_Arrhenius(*this);
134 }
135 
137 {
138  doublereal t = m_thermo->temperature();
139  //m_coeffs[0] holds A
140  //m_coeffs[1] holds n
141  //m_coeffs[2] holds Tact
142  //m_coeffs[3] holds log(A)
143  if (t != m_temp) {
144  m_prop = 0;
145  m_logProp = 0;
146  m_temp = t;
147  m_logt = log(m_temp);
148  //For viscosity the sign convention on positive activation energy is swithced
149  if (m_property == TP_VISCOSITY) {
150  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt + m_coeffs[2] / m_temp;
151  } else {
152  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt - m_coeffs[2] / m_temp;
153  }
154  m_prop = exp(m_logProp);
155  }
156  return m_prop;
157 }
158 
159 LTPspecies_Poly::LTPspecies_Poly(const XML_Node& propNode, const std::string name,
160  TransportPropertyType tp_ind, const thermo_t* thermo) :
161  LTPspecies(&propNode, name, tp_ind, thermo),
162  m_temp(-1.0),
163  m_prop(0.0)
164 {
165  m_model = LTP_TD_POLY;
166  getFloatArray(propNode, m_coeffs, "true", "toSI");
167 }
168 
170 {
171  return new LTPspecies_Poly(*this);
172 }
173 
175 {
176  doublereal t = m_thermo->temperature();
177  if (t != m_temp) {
178  m_prop = 0.0;
179  m_temp = t;
180  double tempN = 1.0;
181  for (int i = 0; i < (int) m_coeffs.size() ; i++) {
182  m_prop += m_coeffs[i] * tempN;
183  tempN *= m_temp;
184  }
185  }
186  return m_prop;
187 }
188 
189 LTPspecies_ExpT::LTPspecies_ExpT(const XML_Node& propNode, const std::string name, TransportPropertyType tp_ind,
190  const thermo_t* thermo) :
191 
192  LTPspecies(&propNode, name, tp_ind, thermo),
193  m_temp(-1.0),
194  m_prop(0.0)
195 {
196  m_model = LTP_TD_EXPT;
197  getFloatArray(propNode, m_coeffs, "true", "toSI");
198 }
199 
201 {
202  return new LTPspecies_ExpT(*this);
203 }
204 
206 {
207  doublereal t = m_thermo->temperature();
208  if (t != m_temp) {
209  m_temp=t;
210  m_prop = m_coeffs[0];
211  doublereal tempN = 1.0;
212  doublereal tmp = 0.0;
213  for (int i = 1; i < (int) m_coeffs.size() ; i++) {
214  tempN *= m_temp;
215  tmp += m_coeffs[i] * tempN;
216  }
217  m_prop *= exp(tmp);
218  }
219  return m_prop;
220 }
221 
222 }
doublereal m_logProp
logarithm of most recent evaluation of transport property
Definition: LTPspecies.h:294
size_t getFloatArray(const XML_Node &node, vector_fp &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:299
TransportPropertyType
Enumeration of the types of transport properties that can be handled by the variables in the various ...
Definition: LTPspecies.h:34
virtual doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:70
virtual void adjustCoeffsForComposition()
Internal model to adjust species-specific properties for the composition.
Definition: LTPspecies.cpp:85
doublereal m_logt
logarithm of current temperature
Definition: LTPspecies.h:288
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
Definition: xml.h:370
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
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:89
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:169
doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:205
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:107
STL namespace.
Header file defining class LTPspecies and its child classes.
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:285
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:112
virtual bool checkPositive() const
Check to see if the property evaluation will be positive.
Definition: LTPspecies.cpp:75
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:65
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:200
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:291
const thermo_t * m_thermo
Pointer to a const thermo object to get current temperature.
Definition: LTPspecies.h:148
doublereal getMixWeight() const
Return the weight mixture.
Definition: LTPspecies.cpp:80
doublereal getSpeciesTransProp()
Return the standard state species value for this transport property evaluated from the Arrhenius expr...
Definition: LTPspecies.cpp:136
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:159
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:189
doublereal getFloatCurrent(const XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
Definition: ctml.cpp:191
LTPTemperatureDependenceType m_model
Model type for the temperature dependence.
Definition: LTPspecies.h:139
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
vector_fp m_coeffs
Model temperature-dependence ceofficients.
Definition: LTPspecies.h:145
doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:174
Class LTPspecies holds transport parameterizations for a specific liquid- phase species.
Definition: LTPspecies.h:76
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
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:178
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:352
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:410
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:349
LTPError(const std::string &msg)
Constructor is a wrapper around CanteraError.
Definition: LTPspecies.cpp:26
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:131
doublereal m_mixWeight
Weighting used for mixing.
Definition: LTPspecies.h:161
Namespace for the Cantera kernel.
Definition: application.cpp:29
doublereal m_prop
most recent evaluation of the transport property
Definition: LTPspecies.h:413
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:102
static void getArrhenius(const XML_Node &node, doublereal &A, doublereal &b, doublereal &E)
Parses the XML element called Arrhenius.
Definition: LTPspecies.cpp:43
Exception thrown if an error is encountered while reading the transport database. ...
Definition: LTPspecies.cpp:19
TransportPropertyType m_property
enum indicating which property this is (i.e viscosity)
Definition: LTPspecies.h:142
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:52