antioch-0.4.0
arrhenius_rate.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 
28 #ifndef ANTIOCH_ARRHENIUS_RATE_H
29 #define ANTIOCH_ARRHENIUS_RATE_H
30 
31 //Antioch
33 #include "antioch/cmath_shims.h"
34 #include "antioch/kinetics_type.h"
36 
37 // C++
38 #include <cmath>
39 #include <iostream>
40 #include <sstream>
41 
42 namespace Antioch
43 {
45 
58  template<typename CoeffType=double>
59  class ArrheniusRate: public KineticsType<CoeffType>
60  {
61 
62  // We declare private members early for use with decltype
63  private:
64 
65  CoeffType _Cf;
66  CoeffType _raw_Ea;
67  CoeffType _Ea;
68  CoeffType _rscale;
69 
70  public:
71 
72  ArrheniusRate (const CoeffType Cf=0., const CoeffType Ea=0., const CoeffType rscale = Constants::R_universal<CoeffType>());
74 
75  void set_Cf( const CoeffType Cf );
77  void set_Ea( const CoeffType Ea );
79  void reset_Ea( const CoeffType Ea );
80  void set_rscale( const CoeffType rscale );
81 
83  //
84  // Beware of the Ea parameter, it \e must be in Kelvin
85  void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value);
86 
88  CoeffType get_parameter(KineticsModel::Parameters parameter) const;
89 
91  //
92  // \todo, solve this
93  template <typename VectorCoeffType>
94  void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value){antioch_error();}
95 
106  template <typename VectorCoeffType>
107  void reset_coefs(const VectorCoeffType & coefficients);
108 
109  CoeffType Cf() const;
110  CoeffType Ea() const;
111  CoeffType Ea_K() const;
112  CoeffType rscale() const;
113 
115  template <typename StateType>
116  ANTIOCH_AUTO(StateType)
117  rate(const StateType& T) const
118  ANTIOCH_AUTOFUNC(StateType, _Cf* (ant_exp(-_Ea/T)))
119 
121  template <typename StateType>
122  ANTIOCH_AUTO(StateType)
123  operator()(const StateType& T) const
124  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
125 
127  template <typename StateType>
128  ANTIOCH_AUTO(StateType)
129  derivative( const StateType& T ) const
130  ANTIOCH_AUTOFUNC(StateType, (*this)(T)*(_Ea/(T*T)))
131 
133  template <typename StateType>
134  void rate_and_derivative(const StateType& T, StateType& rate, StateType& drate_dT) const;
135 
136 // KineticsConditions overloads
137 
139  template <typename StateType, typename VectorStateType>
140  ANTIOCH_AUTO(StateType)
141  rate(const KineticsConditions<StateType,VectorStateType>& T) const
142  ANTIOCH_AUTOFUNC(StateType, _Cf * ant_exp(- _Ea/T.T()))
143 
145  template <typename StateType, typename VectorStateType>
146  ANTIOCH_AUTO(StateType)
147  operator()(const KineticsConditions<StateType,VectorStateType>& T) const
148  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
149 
151  template <typename StateType, typename VectorStateType>
152  ANTIOCH_AUTO(StateType)
153  derivative( const KineticsConditions<StateType,VectorStateType>& T ) const
154  ANTIOCH_AUTOFUNC(StateType, (*this)(T) * (_Ea/T.temp_cache().T2) )
155 
157  template <typename StateType,typename VectorStateType>
158  void rate_and_derivative(const KineticsConditions<StateType,VectorStateType>& T, StateType& rate, StateType& drate_dT) const;
159 
161  const std::string numeric() const;
162 
163  };
164 
165  /* ------------------------- Inline Functions -------------------------*/
166  template<typename CoeffType>
167  ArrheniusRate<CoeffType>::ArrheniusRate(const CoeffType Cf, const CoeffType Ea, const CoeffType rscale)
168  : KineticsType<CoeffType>(KineticsModel::ARRHENIUS),
169  _Cf(Cf),
170  _raw_Ea(Ea),
171  _rscale(rscale)
172  {
173  _Ea = _raw_Ea / _rscale;
174  return;
175  }
176 
177  template<typename CoeffType>
179  {
180  return;
181  }
182 
183  template<typename CoeffType>
184  const std::string ArrheniusRate<CoeffType>::numeric() const
185  {
186  std::stringstream os;
187  os << _Cf;
188  os << "*exp(-" << _raw_Ea << "/(R*T))";
189 
190  return os.str();
191  }
192 
193  template<typename CoeffType>
194  inline
195  void ArrheniusRate<CoeffType>::set_Cf( const CoeffType Cf )
196  {
197  _Cf = Cf;
198  return;
199  }
200 
201  template<typename CoeffType>
202  inline
203  void ArrheniusRate<CoeffType>::set_Ea( const CoeffType Ea )
204  {
205  _raw_Ea = Ea;
206  _Ea = _raw_Ea / _rscale;
207  return;
208  }
209 
210  template<typename CoeffType>
211  inline
212  void ArrheniusRate<CoeffType>::reset_Ea( const CoeffType Ea )
213  {
214  _Ea = Ea;
215  _raw_Ea = _Ea * _rscale;
216  return;
217  }
218 
219  template<typename CoeffType>
220  inline
222  {
223  _rscale = rscale;
224  _Ea = _raw_Ea / _rscale;
225  return;
226  }
227 
228  template<typename CoeffType>
229  template <typename VectorCoeffType>
230  inline
231  void ArrheniusRate<CoeffType>::reset_coefs(const VectorCoeffType & coefficients)
232  {
233  antioch_assert_greater(coefficients.size(),1);
234  antioch_assert_less(coefficients.size(),4);
235  if(coefficients.size() == 3)this->set_rscale(coefficients[2]);
236  this->set_Cf(coefficients[0]);
237  this->set_Ea(coefficients[1]);
238  }
239 
240  template<typename CoeffType>
241  inline
243  {
244  switch(parameter)
245  {
247  {
248  this->set_Cf(new_value);
249  }
250  break;
252  {
253  this->reset_Ea(new_value);
254  }
255  break;
257  {
258  this->set_rscale(new_value);
259  }
260  break;
261  default:
262  {
263  antioch_error();
264  }
265  break;
266  }
267  }
268 
269  template<typename CoeffType>
270  inline
272  {
273  switch(parameter)
274  {
276  {
277  return this->Cf();
278  }
279  break;
281  {
282  return this->Ea();
283  }
284  break;
286  {
287  return this->rscale();
288  }
289  break;
290  default:
291  {
292  antioch_error();
293  }
294  break;
295  }
296  return 0;
297  }
298 
299  template<typename CoeffType>
300  inline
302  { return _Cf; }
303 
304  template<typename CoeffType>
305  inline
307  { return _raw_Ea; }
308 
309  template<typename CoeffType>
310  inline
312  { return _Ea; }
313 
314  template<typename CoeffType>
315  inline
317  { return _rscale; }
318 
319  template<typename CoeffType>
320  template<typename StateType>
321  inline
322  void ArrheniusRate<CoeffType>::rate_and_derivative( const StateType& T,
323  StateType& rate,
324  StateType& drate_dT) const
325  {
326  rate = (*this)(T);
327  drate_dT = rate*_Ea/(T*T);
328  return;
329  }
330 
331  template<typename CoeffType>
332  template <typename StateType,typename VectorStateType>
333  inline
334  void ArrheniusRate<CoeffType>::rate_and_derivative(const KineticsConditions<StateType,VectorStateType>& T,
335  StateType& rate,
336  StateType& drate_dT) const
337  {
338  rate = (*this)(T);
339  drate_dT = rate * _Ea/(T.temp_cache().T2);
340  return;
341  }
342 
343 } // end namespace Antioch
344 
345 #endif // ANTIOCH_ARRHENIUS_RATE_H
Arrhenius rate equation.
base class for kinetics models
Definition: kinetics_type.h:82
#define antioch_assert_greater(expr1, expr2)
_Cf * ant_exp(-_Ea/T))) template< typename StateType > operator()(const StateType &T) const template< typename StateType > derivative(const StateType &T) const ANTIOCH_AUTOFUNC(StateType
#define antioch_assert_less(expr1, expr2)
void set_Cf(const CoeffType Cf)
#define antioch_error()
ArrheniusRate(const CoeffType Cf=0., const CoeffType Ea=0., const CoeffType rscale=Constants::R_universal< CoeffType >())
_Cf(*) StateType rate)
const std::string numeric() const
print equation
CoeffType get_parameter(KineticsModel::Parameters parameter) const
get one parameter, characterized by enum
CoeffType Ea_K() const
void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value)
for compatibility purpose with photochemistry (particle flux reactions)
CoeffType rscale() const
_Cf(* this)(T)*(_Ea/(T *T))) template< typename StateType > void rate_and_derivative(const StateType &T
Simultaneously evaluate the rate and its derivative at T.
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
_Cf(*) StateType StateType &drate_d const)
CoeffType Cf() const
void reset_Ea(const CoeffType Ea)
set Ea, no rescaling, unit is K
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value)
set one parameter, characterized by enum
CoeffType Ea() const
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
The parameters are reduced parameters.
void set_Ea(const CoeffType Ea)
set Ea, rescale the value, unit is known
This class contains the conditions of the chemistry.
void set_rscale(const CoeffType rscale)
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs

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