antioch-0.4.0
berthelot_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 #ifndef ANTIOCH_BERTHELOT_RATE_H
28 #define ANTIOCH_BERTHELOT_RATE_H
29 
30 //Antioch
32 #include "antioch/kinetics_type.h"
33 #include "antioch/cmath_shims.h"
34 
35 // C++
36 #include <cmath>
37 #include <iostream>
38 #include <sstream>
39 
40 namespace Antioch
41 {
43 
54  template<typename CoeffType=double>
55  class BerthelotRate:public KineticsType<CoeffType>
56  {
57 
58  private:
59 
60  CoeffType _Cf;
61  CoeffType _D;
62 
63  public:
64 
65  BerthelotRate (const CoeffType Cf=0., const CoeffType D=0.);
67 
68  void set_Cf( const CoeffType Cf );
69  void set_D( const CoeffType D );
70 
72  void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value);
73 
75  CoeffType get_parameter(KineticsModel::Parameters parameter) const;
76 
78  //
79  // \todo, solve this
80  template <typename VectorCoeffType>
81  void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value){antioch_error();}
82 
87  template <typename VectorCoeffType>
88  void reset_coefs(const VectorCoeffType & coefficients);
89 
90  // \todo delete this method, why does it exist?
91  void scale_D( const CoeffType scale );
92 
93  CoeffType Cf() const;
94  CoeffType D() const;
95 
97  template <typename StateType>
98  ANTIOCH_AUTO(StateType)
99  rate(const StateType& T) const
100  ANTIOCH_AUTOFUNC(StateType, _Cf* (ant_exp(_D*T)))
101 
103  template <typename StateType>
104  ANTIOCH_AUTO(StateType)
105  operator()(const StateType& T) const
106  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
107 
109  template <typename StateType>
110  ANTIOCH_AUTO(StateType)
111  derivative( const StateType& T ) const
112  ANTIOCH_AUTOFUNC(StateType, (*this)(T)*_D)
113 
115  template <typename StateType>
116  void rate_and_derivative(const StateType& T, StateType& rate, StateType& drate_dT) const;
117 
118 // KineticsConditions overloads
119 
121  template <typename StateType, typename VectorStateType>
122  ANTIOCH_AUTO(StateType)
123  rate(const KineticsConditions<StateType,VectorStateType>& T) const
124  ANTIOCH_AUTOFUNC(StateType, _Cf * ant_exp(_D * T.T()) )
125 
127  template <typename StateType, typename VectorStateType>
128  ANTIOCH_AUTO(StateType)
129  operator()(const KineticsConditions<StateType,VectorStateType>& T) const
130  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
131 
133  template <typename StateType, typename VectorStateType>
134  ANTIOCH_AUTO(StateType)
135  derivative( const KineticsConditions<StateType,VectorStateType>& T ) const
136  ANTIOCH_AUTOFUNC(StateType, (*this)(T) * _D )
137 
139  template <typename StateType,typename VectorStateType>
140  void rate_and_derivative(const KineticsConditions<StateType,VectorStateType>& T, StateType& rate, StateType& drate_dT) const;
141 
143  const std::string numeric() const;
144  };
145 
146  template<typename CoeffType>
147  BerthelotRate<CoeffType>::BerthelotRate(const CoeffType Cf, const CoeffType D)
148  : KineticsType<CoeffType>(KineticsModel::BERTHELOT),
149  _Cf(Cf),
150  _D(D)
151  {
152  return;
153  }
154 
155  template<typename CoeffType>
157  {
158  return;
159  }
160 
161  template<typename CoeffType>
162  const std::string BerthelotRate<CoeffType>::numeric() const
163  {
164  std::stringstream os;
165  os << _Cf;
166  os << "*exp(" << _D << "*T)";
167 
168  return os.str();
169  }
170 
171  /* ------------------------- Inline Functions -------------------------*/
172  template<typename CoeffType>
173  inline
174  void BerthelotRate<CoeffType>::set_Cf( const CoeffType Cf )
175  {
176  _Cf = Cf;
177  return;
178  }
179 
180  template<typename CoeffType>
181  inline
182  void BerthelotRate<CoeffType>::set_D( const CoeffType D )
183  {
184  _D = D;
185  return;
186  }
187 
188  template<typename CoeffType>
189  template <typename VectorCoeffType>
190  inline
191  void BerthelotRate<CoeffType>::reset_coefs(const VectorCoeffType & coefficients)
192  {
193  antioch_assert_equal_to(coefficients.size(),2);
194  this->set_Cf(coefficients[0]);
195  this->set_D(coefficients[1]);
196  }
197 
198  template<typename CoeffType>
199  inline
201  {
202  switch(parameter)
203  {
205  {
206  this->set_Cf(new_value);
207  }
208  break;
210  {
211  this->set_D(new_value);
212  }
213  break;
214  default:
215  {
216  antioch_error();
217  }
218  break;
219  }
220  }
221 
222  template<typename CoeffType>
223  inline
225  {
226  switch(parameter)
227  {
229  {
230  return this->Cf();
231  }
232  break;
234  {
235  return this->D();
236  }
237  break;
238  default:
239  {
240  antioch_error();
241  }
242  break;
243  }
244  return 0;
245  }
246 
247  template<typename CoeffType>
248  inline
249  void BerthelotRate<CoeffType>::scale_D( const CoeffType scale )
250  {
251  _D *= scale;
252  return;
253  }
254 
255  template<typename CoeffType>
256  inline
258  { return _Cf; }
259 
260  template<typename CoeffType>
261  inline
262  CoeffType BerthelotRate<CoeffType>::D() const
263  { return _D; }
264 
265  template<typename CoeffType>
266  template<typename StateType>
267  inline
268  void BerthelotRate<CoeffType>::rate_and_derivative( const StateType& T,
269  StateType& rate,
270  StateType& drate_dT) const
271  {
272  rate = (*this)(T);
273  drate_dT = rate*_D;
274  return;
275  }
276 
277  template<typename CoeffType>
278  template <typename StateType,typename VectorStateType>
279  inline
280  void BerthelotRate<CoeffType>::rate_and_derivative(const KineticsConditions<StateType,VectorStateType>& T,
281  StateType& rate, StateType& drate_dT) const
282  {
283  rate = (*this)(T);
284  drate_dT = rate*_D;
285  return;
286  }
287 
288 } // end namespace Antioch
289 
290 #endif // ANTIOCH_BERTHELOT_RATE_H
Berthelot rate equation.
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
_Cf(* this)(T)*_D) template< typename StateType > void rate_and_derivative(const StateType &T
Simultaneously evaluate the rate and its derivative at T.
base class for kinetics models
Definition: kinetics_type.h:82
#define antioch_assert_equal_to(expr1, expr2)
_Cf * ant_exp(_D *T))) template< typename StateType > operator()(const StateType &T) const template< typename StateType > derivative(const StateType &T) const ANTIOCH_AUTOFUNC(StateType
CoeffType D() const
_Cf(*) StateType StateType &drate_d const)
CoeffType get_parameter(KineticsModel::Parameters parameter) const
get one parameter, characterized by enum
void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value)
set one parameter, characterized by enum
#define antioch_error()
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs
void set_D(const CoeffType D)
void set_Cf(const CoeffType Cf)
void scale_D(const CoeffType scale)
void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value)
for compatibility purpose with photochemistry (particle flux reactions)
const std::string numeric() const
print equation
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
The parameters are reduced parameters.
BerthelotRate(const CoeffType Cf=0., const CoeffType D=0.)
CoeffType Cf() const
_Cf(*) StateType rate)
This class contains the conditions of the chemistry.
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType

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