antioch-0.4.0
troe_falloff.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #ifndef ANTIOCH_TROE_FALLOFF_H
28 #define ANTIOCH_TROE_FALLOFF_H
29 
30 //Antioch
31 #include "antioch/math_constants.h"
32 #include "antioch/cmath_shims.h"
33 
34 namespace Antioch
35 {
109  template <typename CoeffType = double>
110  class TroeFalloff
111  {
112  public:
113  TroeFalloff(const unsigned int nspec, const CoeffType alpha=0,
114  const CoeffType T3 = 0, const CoeffType T1 = 0,
115  const CoeffType T2 = 1e50);
116 
117  ~TroeFalloff();
118 
119  void set_alpha(const CoeffType &al);
120  void set_T1(const CoeffType &T);
121  void set_T2(const CoeffType &T);
122  void set_T3(const CoeffType &T);
123 
124  CoeffType get_alpha() const;
125  CoeffType get_T1() const;
126  CoeffType get_T2() const;
127  CoeffType get_T3() const;
128 
129  template <typename StateType>
130  StateType operator()(const StateType &T,
131  const StateType &M,
132  const StateType &k0,
133  const StateType &kinf) const;
134 
135  template <typename StateType, typename VectorStateType>
136  void F_and_derivatives(const StateType& T,
137  const StateType &M,
138  const StateType &k0,
139  const StateType &dk0_dT,
140  const StateType &kinf,
141  const StateType &dkinf_dT,
142  StateType &F,
143  StateType &dF_dT,
144  VectorStateType &dF_dX) const;
145 
146  private:
147 
148  unsigned int n_spec;
149  CoeffType _alpha;
150  CoeffType _T3;
151  CoeffType _T1;
152  CoeffType _T2;
153 
155 
156  CoeffType _c_coeff;
157 
159 
160  CoeffType _n_coeff;
161 
162  template <typename StateType>
163  StateType Fcent(const StateType &T) const;
164 
165  template <typename StateType>
166  void Fcent_and_derivatives( const StateType &T,
167  StateType &Fc,
168  StateType &dFc_dT ) const;
169 
170  };
171 
172  template<typename CoeffType>
173  inline
174  void TroeFalloff<CoeffType>::set_alpha(const CoeffType& al)
175  {
176  _alpha = al;
177  return;
178  }
179 
180  template<typename CoeffType>
181  inline
182  void TroeFalloff<CoeffType>::set_T1(const CoeffType& T)
183  {
184  _T1 = T;
185  return;
186  }
187 
188  template<typename CoeffType>
189  inline
190  void TroeFalloff<CoeffType>::set_T2(const CoeffType& T)
191  {
192  _T2 = T;
193  return;
194  }
195 
196  template<typename CoeffType>
197  inline
198  void TroeFalloff<CoeffType>::set_T3(const CoeffType& T)
199  {
200  _T3 = T;
201  return;
202  }
203 
204  template<typename CoeffType>
205  inline
207  {
208  return _alpha;
209  }
210 
211  template<typename CoeffType>
212  inline
214  {
215  return _T1;
216  }
217 
218  template<typename CoeffType>
219  inline
221  {
222  return _T2;
223  }
224 
225  template<typename CoeffType>
226  inline
228  {
229  return _T3;
230  }
231 
232 
233  template<typename CoeffType>
234  template<typename StateType>
235  inline
236  StateType TroeFalloff<CoeffType>::operator()(const StateType& T,
237  const StateType &M,
238  const StateType &k0,
239  const StateType &kinf) const
240  {
241 
242  //compute log(Fcent) once
243  StateType logFcent = ant_log(this->Fcent(T));
244 
245  // Pr = [M] * k0/kinf
246  ANTIOCH_AUTO(StateType) Pr = M * k0/kinf;
247  // c = -0.4 - 0.67 * log10(Fcent)
248  // Note log10(x) = (1.0/log(10))*log(x)
249  StateType c = - CoeffType(0.4L) - _c_coeff * logFcent;
250 
251  // n = 0.75 - 1.27 * log10(Fcent)
252  // Note log10(x) = (1.0/log(10))*log(x)
253  ANTIOCH_AUTO(StateType) n = CoeffType(0.75L) - _n_coeff * logFcent;
254  ANTIOCH_AUTO(StateType) d = constant_clone(T,CoeffType(0.14L));
255 
256  StateType log10Pr = Constants::log10_to_log<CoeffType>() * ant_log(Pr);
257 
258  //log10F = log10(Fcent) / [1+((log10(Pr) + c)/(n - d*(log10(Pr) + c) ))^2]
259  //logF = log(Fcent) / [1+((log10(Pr) + c)/(n - d*(log10(Pr) + c) ))^2]
260  ANTIOCH_AUTO(StateType) logF =
261  logFcent/(1 + ant_pow(((log10Pr + c)/(n - d*(log10Pr + c) )),2) );
262 
263  return ant_exp(logF);
264  }
265 
266 
267  template <typename CoeffType>
268  template <typename StateType>
269  inline
270  StateType TroeFalloff<CoeffType>::Fcent(const StateType &T) const
271  {
272 
273  // Fcent = (1.-alpha)*exp(-T/T***) + alpha * exp(-T/T*) + exp(-T**/T)
274  StateType Fc = (1 - _alpha) * ant_exp(-T/_T3) + _alpha * ant_exp(-T/_T1);
275 
276  if(_T2 != 1e50)Fc += ant_exp(-_T2/T);
277 
278  return Fc;
279  }
280 
281  template <typename CoeffType>
282  template <typename StateType>
283  inline
284  void TroeFalloff<CoeffType>::Fcent_and_derivatives(const StateType &T, StateType &Fc, StateType &dFc_dT) const
285  {
286 
287  // Fcent = (1.-alpha)*exp(-T/T***) + alpha * exp(-T/T*) + exp(-T**/T)
288  Fc = (1 - _alpha) * ant_exp(-T/_T3) + _alpha * ant_exp(-T/_T1);
289  dFc_dT = (_alpha - 1)/_T3 * ant_exp(-T/_T3) - _alpha/_T1 * ant_exp(-T/_T1);
290 
291  if(_T2 != 1e50)
292  {
293  Fc += ant_exp(-_T2/T);
294  dFc_dT += _T2/(T*T) * ant_exp(-_T2/T);
295  }
296 
297  return;
298  }
299 
300  template <typename CoeffType>
301  template <typename StateType, typename VectorStateType>
302  inline
304  const StateType &M,
305  const StateType &k0,
306  const StateType &dk0_dT,
307  const StateType &kinf,
308  const StateType &dkinf_dT,
309  StateType &F,
310  StateType &dF_dT,
311  VectorStateType &dF_dX) const
312  {
313 
314  antioch_assert_equal_to(dF_dX.size(),this->n_spec);
315 
316  //declarations
317  // Pr and derivatives
318  StateType Pr = M * k0/kinf;
319  StateType dPr_dT = Pr * (dk0_dT/k0 - dkinf_dT/kinf);
320  StateType log10Pr = Constants::log10_to_log<CoeffType>() * ant_log(Pr);
321  StateType dlog10Pr_dT = Constants::log10_to_log<CoeffType>()*dPr_dT/Pr;
322  VectorStateType dlog10Pr_dX = Antioch::zero_clone(dF_dX);
323  for(unsigned int ip = 0; ip < dlog10Pr_dX.size(); ip++)
324  {//dlog10Pr_dX = 1/(ln(10)*Pr) * dPr_dX
325  dlog10Pr_dX[ip] = Constants::log10_to_log<CoeffType>()/M; //dPr_dX = k0/kinf, Pr = M k0/kinf => dlog10Pr_dX = 1/(ln(10)*M)
326  }
327  // Fcent and derivatives
328  StateType Fcent = Antioch::zero_clone(T);
329  StateType dFcent_dT = Antioch::zero_clone(T);
330  this->Fcent_and_derivatives(T,Fcent,dFcent_dT);
331  StateType dlog10Fcent_dT = Constants::log10_to_log<CoeffType>()*dFcent_dT/Fcent;
332  // Compute log(Fcent) once
333  StateType logFcent = ant_log(Fcent);
334  // n and c and derivatives
335  StateType d = Antioch::constant_clone(T, CoeffType(0.14L));
336  StateType c = - CoeffType(0.4L) - _c_coeff * logFcent;
337  StateType n = CoeffType(0.75L) - _n_coeff * logFcent;
338  StateType dc_dT = - _c_coeff * dFcent_dT/Fcent;
339  ANTIOCH_AUTO(StateType) dn_dT = - _n_coeff * dFcent_dT/Fcent;
340 
341  //log10F
342  StateType logF = logFcent/(1 + ant_pow(((log10Pr + c)/(n - d*(log10Pr + c) )),2));
343  StateType dlogF_dT = logF * (dlog10Fcent_dT / Fcent
344  - 2 * ant_pow((log10Pr + c)/(n - d * (log10Pr + c)),2)
345  * ((dlog10Pr_dT + dc_dT)/(log10Pr + c) -
346  (dn_dT - d * (dlog10Pr_dT + dc_dT))/(n - d * (log10Pr + c))
347  )
348  / (1 + ant_pow((log10Pr + c)/(n - d * (log10Pr + c)),2))
349  );
350  VectorStateType dlogF_dX = Antioch::zero_clone(dF_dX);
351  for(unsigned int ip = 0; ip < dlog10Pr_dX.size(); ip++)
352  {//dlogF_dX = - logF^2/log(Fcent) * dlog10Pr_dX * (1 - 1/(n - d * (log10Pr + c))) * (log10Pr + c)
353  dlogF_dX[ip] = - ant_pow(logF,2)/logFcent * dlog10Pr_dX[ip] *(1 - 1/(n - d * (log10Pr + c))) * (log10Pr + c);
354  }
355 
356  F = ant_exp(logF);
357  dF_dT = F * dlogF_dT;
358  for(unsigned int ip = 0; ip < dlog10Pr_dX.size(); ip++)
359  {//dF_dX = F * dlogF_dX
360  dF_dX[ip] = F * dlogF_dX[ip];
361  }
362 
363  return;
364  }
365 
366 
367  template<typename CoeffType>
368  inline
369  TroeFalloff<CoeffType>::TroeFalloff(const unsigned int nspec, const CoeffType alpha,
370  const CoeffType T3, const CoeffType T1, const CoeffType T2):
371  n_spec(nspec),
372  _alpha(alpha),
373  _T3(T3),
374  _T1(T1),
375  _T2(T2),
376  _c_coeff( CoeffType(0.67L) * Constants::log10_to_log<CoeffType>() ),
377  _n_coeff( CoeffType(1.27L) * Constants::log10_to_log<CoeffType>() )
378  {
379  return;
380  }
381 
382  template<typename CoeffType>
383  inline
385  {
386  return;
387  }
388 
389 } // end namespace Antioch
390 
391 #endif // ANTIOCH_TROE_FALLOFF_H
StateType Fcent(const StateType &T) const
Definition: troe_falloff.h:270
void set_T1(const CoeffType &T)
Definition: troe_falloff.h:182
TroeFalloff(const unsigned int nspec, const CoeffType alpha=0, const CoeffType T3=0, const CoeffType T1=0, const CoeffType T2=1e50)
Definition: troe_falloff.h:369
CoeffType log10_to_log()
1/ln(10)
#define antioch_assert_equal_to(expr1, expr2)
CoeffType get_T2() const
Definition: troe_falloff.h:220
Scalar F(const Scalar &x)
CoeffType get_T1() const
Definition: troe_falloff.h:213
void set_alpha(const CoeffType &al)
Definition: troe_falloff.h:174
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
CoeffType _n_coeff
Precompute coefficient for log conversion.
Definition: troe_falloff.h:160
CoeffType _c_coeff
Precompute coefficient for log conversion.
Definition: troe_falloff.h:156
CoeffType get_alpha() const
Definition: troe_falloff.h:206
unsigned int n_spec
Definition: troe_falloff.h:148
StateType operator()(const StateType &T, const StateType &M, const StateType &k0, const StateType &kinf) const
Definition: troe_falloff.h:236
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
void set_T2(const CoeffType &T)
Definition: troe_falloff.h:190
The parameters are reduced parameters.
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
Definition: eigen_utils.h:145
void Fcent_and_derivatives(const StateType &T, StateType &Fc, StateType &dFc_dT) const
Definition: troe_falloff.h:284
void set_T3(const CoeffType &T)
Definition: troe_falloff.h:198
CoeffType get_T3() const
Definition: troe_falloff.h:227
void F_and_derivatives(const StateType &T, const StateType &M, const StateType &k0, const StateType &dk0_dT, const StateType &kinf, const StateType &dkinf_dT, StateType &F, StateType &dF_dT, VectorStateType &dF_dX) const
Definition: troe_falloff.h:303

Generated on Thu Jul 7 2016 11:09:45 for antioch-0.4.0 by  doxygen 1.8.8