Cantera  2.4.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() :
53  m_speciesName("-"),
54  m_model(LTP_TD_NOTSET),
55  m_property(TP_UNKNOWN),
56  m_thermo(0),
57  m_mixWeight(1.0)
58 {
59  warn_deprecated("class LTPspecies", "To be removed after Cantera 2.4");
60 }
61 
62 LTPspecies* LTPspecies::duplMyselfAsLTPspecies() const
63 {
64  return new LTPspecies(*this);
65 }
66 
67 doublereal LTPspecies::getSpeciesTransProp()
68 {
69  return 0.0;
70 }
71 
72 bool LTPspecies::checkPositive() const
73 {
74  return (m_coeffs[0] > 0);
75 }
76 
77 doublereal LTPspecies::getMixWeight() const
78 {
79  return m_mixWeight;
80 }
81 
82 void LTPspecies::adjustCoeffsForComposition()
83 {
84 }
85 
86 LTPspecies_Const::LTPspecies_Const()
87 {
88  m_model = LTP_TD_CONSTANT;
89 }
90 
91 void LTPspecies_Const::setupFromXML(const XML_Node& propNode)
92 {
93  double A_k = getFloatCurrent(propNode, "toSI");
94  if (A_k > 0.0) {
95  setCoeff(A_k);
96  } else {
97  throw LTPError("negative or zero " + propNode.name());
98  }
99 }
100 
101 void LTPspecies_Const::setCoeff(double C)
102 {
103  m_coeffs = {C};
104 }
105 
106 LTPspecies* LTPspecies_Const::duplMyselfAsLTPspecies() const
107 {
108  return new LTPspecies_Const(*this);
109 }
110 
111 doublereal LTPspecies_Const::getSpeciesTransProp()
112 {
113  return m_coeffs[0];
114 }
115 
116 LTPspecies_Arrhenius::LTPspecies_Arrhenius()
117 {
118  m_model = LTP_TD_ARRHENIUS;
119  m_temp = 0.0;
120  m_prop = 0.0;
121 }
122 
123 LTPspecies* LTPspecies_Arrhenius::duplMyselfAsLTPspecies() const
124 {
125  return new LTPspecies_Arrhenius(*this);
126 }
127 
128 void LTPspecies_Arrhenius::setupFromXML(const XML_Node& propNode)
129 {
130  doublereal A_k, n_k, Tact_k;
131  getArrhenius(propNode, A_k, n_k, Tact_k);
132  if (A_k <= 0.0) {
133  throw LTPError("negative or zero " + propNode.name());
134  }
135  setCoeffs(A_k, n_k, Tact_k);
136 }
137 
138 void LTPspecies_Arrhenius::setCoeffs(double A, double n, double Tact)
139 {
140  m_coeffs = {A, n, Tact, log(A)};
141 }
142 
143 doublereal LTPspecies_Arrhenius::getSpeciesTransProp()
144 {
145  doublereal t = m_thermo->temperature();
146  //m_coeffs[0] holds A
147  //m_coeffs[1] holds n
148  //m_coeffs[2] holds Tact
149  //m_coeffs[3] holds log(A)
150  if (t != m_temp) {
151  m_prop = 0;
152  m_logProp = 0;
153  m_temp = t;
154  m_logt = log(m_temp);
155  //For viscosity the sign convention on positive activation energy is swithced
156  if (m_property == TP_VISCOSITY) {
157  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt + m_coeffs[2] / m_temp;
158  } else {
159  m_logProp = m_coeffs[3] + m_coeffs[1] * m_logt - m_coeffs[2] / m_temp;
160  }
161  m_prop = exp(m_logProp);
162  }
163  return m_prop;
164 }
165 
166 LTPspecies_Poly::LTPspecies_Poly() :
167  m_temp(-1.0),
168  m_prop(0.0)
169 {
170  m_model = LTP_TD_POLY;
171 }
172 
174 {
175  return new LTPspecies_Poly(*this);
176 }
177 
179 {
180  vector_fp coeffs;
181  getFloatArray(propNode, coeffs, "true", "toSI");
182  setCoeffs(coeffs.size(), coeffs.data());
183 }
184 
185 void LTPspecies_Poly::setCoeffs(size_t N, const double* coeffs)
186 {
187  m_coeffs.assign(coeffs, coeffs+N);
188 }
189 
191 {
192  doublereal t = m_thermo->temperature();
193  if (t != m_temp) {
194  m_prop = 0.0;
195  m_temp = t;
196  double tempN = 1.0;
197  for (int i = 0; i < (int) m_coeffs.size() ; i++) {
198  m_prop += m_coeffs[i] * tempN;
199  tempN *= m_temp;
200  }
201  }
202  return m_prop;
203 }
204 
205 LTPspecies_ExpT::LTPspecies_ExpT() :
206  m_temp(-1.0),
207  m_prop(0.0)
208 {
209  m_model = LTP_TD_EXPT;
210 }
211 
213 {
214  return new LTPspecies_ExpT(*this);
215 }
216 
218 {
219  vector_fp coeffs;
220  getFloatArray(propNode, coeffs, "true", "toSI");
221  setCoeffs(coeffs.size(), coeffs.data());
222 }
223 
224 void LTPspecies_ExpT::setCoeffs(size_t N, const double* coeffs)
225 {
226  m_coeffs.assign(coeffs, coeffs+N);
227 }
228 
230 {
231  doublereal t = m_thermo->temperature();
232  if (t != m_temp) {
233  m_temp=t;
234  m_prop = m_coeffs[0];
235  doublereal tempN = 1.0;
236  doublereal tmp = 0.0;
237  for (int i = 1; i < (int) m_coeffs.size() ; i++) {
238  tempN *= m_temp;
239  tmp += m_coeffs[i] * tempN;
240  }
241  m_prop *= exp(tmp);
242  }
243  return m_prop;
244 }
245 
246 }
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
virtual void setupFromXML(const XML_Node &propNode)
Set up the species transport property from the XML node, <propNode> that is a child of the <transport...
Definition: LTPspecies.cpp:178
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
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:256
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:173
doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:229
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
STL namespace.
Header file defining class LTPspecies and its child classes.
Class LTPspecies_Arrhenius holds transport parameters for a specific liquid- phase species (LTPspecie...
Definition: LTPspecies.h:232
virtual LTPspecies * duplMyselfAsLTPspecies() const
Duplication routine.
Definition: LTPspecies.cpp:212
const thermo_t * m_thermo
Pointer to a const thermo object to get current temperature.
Definition: LTPspecies.h:155
doublereal getFloatCurrent(const XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
Definition: ctml.cpp:177
LTPTemperatureDependenceType m_model
Model type for the temperature dependence.
Definition: LTPspecies.h:146
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
vector_fp m_coeffs
Model temperature-dependence ceofficients.
Definition: LTPspecies.h:152
virtual void setupFromXML(const XML_Node &propNode)
Set up the species transport property from the XML node, <propNode> that is a child of the <transport...
Definition: LTPspecies.cpp:217
doublereal getSpeciesTransProp()
Returns the vector of standard state species transport property.
Definition: LTPspecies.cpp:190
Class LTPspecies_Const holds transport parameters for a specific liquid- phase species (LTPspecies) w...
Definition: LTPspecies.h:190
Class LTPspecies holds transport parameterizations for a specific liquid- phase species.
Definition: LTPspecies.h:78
Class LTPspecies_ExpT holds transport parameters for a specific liquid- phase species (LTPspecies) wh...
Definition: LTPspecies.h:350
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
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:164
doublereal m_prop
most recent evaluation of transport property
Definition: LTPspecies.h:320
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:365
doublereal m_temp
temperature from thermo object
Definition: LTPspecies.h:317
LTPError(const std::string &msg)
Constructor is a wrapper around CanteraError.
Definition: LTPspecies.cpp:26
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
doublereal m_prop
most recent evaluation of the transport property
Definition: LTPspecies.h:368
Class LTPspecies_Poly holds transport parameters for a specific liquid-phase species (LTPspecies) whe...
Definition: LTPspecies.h:303
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