antioch-0.4.0
falloff_reaction.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_FALLOFF_REACTION_H
28 #define ANTIOCH_FALLOFF_REACTION_H
29 
30 // Antioch
32 #include "antioch/cmath_shims.h"
33 #include "antioch/reaction.h"
36 #include "antioch/troe_falloff.h"
37 
38 //C++
39 #include <string>
40 #include <vector>
41 #include <iostream>
42 
43 namespace Antioch
44 {
97  template<typename CoeffType=double, typename FalloffType = LindemannFalloff<CoeffType> >
98  class FalloffReaction: public Reaction<CoeffType>
99  {
100  public:
101 
103  FalloffReaction( const unsigned int n_species,
104  const std::string &equation,
105  const bool &reversible = true,
108 
109  virtual ~FalloffReaction();
110 
112  template <typename StateType, typename VectorStateType>
113  StateType compute_forward_rate_coefficient( const VectorStateType& molar_densities,
114  const KineticsConditions<StateType,VectorStateType>& conditions ) const;
115 
117  template <typename StateType, typename VectorStateType>
118  void compute_forward_rate_coefficient_and_derivatives( const VectorStateType& molar_densities,
120  StateType& kfwd,
121  StateType& dkfwd_dT,
122  VectorStateType& dkfkwd_dX) const;
123 
124 
126  const FalloffType &F() const;
128  FalloffType &F();
129 
130  protected:
131 
132  FalloffType _F;
133 
134  };
135 
136  /* ------------------------- Inline Functions -------------------------*/
137  template<typename CoeffType, typename FalloffType>
138  inline
140  const std::string &equation,
141  const bool &reversible,
142  const ReactionType::ReactionType &falloffType,
144  :Reaction<CoeffType>(n_species,equation,reversible,falloffType,kin),
145  _F(n_species)
146 
147  {}
148 
149 
150  template<typename CoeffType, typename FalloffType>
151  inline
153  {
154  return;
155  }
156 
157  template<typename CoeffType, typename FalloffType>
158  inline
160  {
161  return _F;
162  }
163 
164  template<typename CoeffType, typename FalloffType>
165  inline
166  const FalloffType &FalloffReaction<CoeffType,FalloffType>::F() const
167  {
168  return _F;
169  }
170 
171  template<typename CoeffType, typename FalloffType>
172  template<typename StateType, typename VectorStateType>
173  inline
174  StateType FalloffReaction<CoeffType,FalloffType>::compute_forward_rate_coefficient( const VectorStateType& molar_densities,
175  const KineticsConditions<StateType,VectorStateType>& conditions ) const
176  {
177 //falloff is k(T,[M]) = k0*[M]/(1 + [M]*k0/kinf) * F = k0 * ([M]^-1 + k0 * kinf^-1)^-1 * F
178  StateType M = Antioch::zero_clone(conditions.T());
179  for(unsigned int i = 0; i < molar_densities.size(); i++)
180  {
181  M += molar_densities[i];
182  }
183 
184  const StateType k0 = (*this->_forward_rate[0])(conditions);
185  const StateType kinf = (*this->_forward_rate[1])(conditions);
186 
187  return k0 / (ant_pow(M,-1) + k0 / kinf) * _F(conditions.T(),M,k0,kinf);
188  }
189 
190  template<typename CoeffType, typename FalloffType>
191  template<typename StateType, typename VectorStateType>
192  inline
195  StateType& kfwd,
196  StateType& dkfwd_dT,
197  VectorStateType& dkfwd_dX) const
198  {
199  //variables, k0,kinf and derivatives
200  StateType k0 = Antioch::zero_clone(conditions.T());
201  StateType dk0_dT = Antioch::zero_clone(conditions.T());
202  StateType kinf = Antioch::zero_clone(conditions.T());
203  StateType dkinf_dT = Antioch::zero_clone(conditions.T());
204 
205  this->_forward_rate[0]->compute_rate_and_derivative(conditions,k0,dk0_dT);
206  this->_forward_rate[1]->compute_rate_and_derivative(conditions,kinf,dkinf_dT);
207 
208  StateType M = Antioch::zero_clone(conditions.T());
209  for(unsigned int i = 0; i < molar_densities.size(); i++)
210  {
211  M += molar_densities[i];
212  }
213 
214  //F
215  StateType f = Antioch::zero_clone(M);
216  StateType df_dT = Antioch::zero_clone(M);
217  VectorStateType df_dX = Antioch::zero_clone(molar_densities);
218  _F.F_and_derivatives(conditions.T(),M,k0,dk0_dT,kinf,dkinf_dT,f,df_dT,df_dX);
219 
220 // k(T,[M]) = k0*[M]/(1 + [M]*k0/kinf) * F = k0 * ([M]^-1 + k0 * kinf^-1)^-1 * F
221  kfwd = k0 / (ant_pow(M,-1) + k0/kinf); //temp variable here for calculations dk_d{T,X}
222 
223  StateType temp = (kinf/M + k0);
224 //dk_dT = F * dkfwd_dT + kfwd * dF_dT
225 // = F * kfwd * (dk0_dT/k0 - dk0_dT/(kinf/[M] + k0) + k0 * dkinf_dT/(kinf * (kinf/[M] + k0) ) )
226 // + dF_dT * kfwd
227  dkfwd_dT = f * kfwd * (dk0_dT/k0 - dk0_dT/temp + dkinf_dT * k0/(kinf * temp))
228  + df_dT * kfwd;
229 
230  dkfwd_dX.resize(this->n_species(), kfwd);
231 //dkfwd_dX = F * dkfwd_dX + kfwd * dF_dX
232 // = F * kfwd / ([M] + [M]^2 k0/kinf) + kfwd * dF_dX
233  StateType tmp = f * kfwd / (M + ant_pow(M,2) * k0/kinf);
234  for(unsigned int ic = 0; ic < this->n_species(); ic++)
235  {
236  dkfwd_dX[ic] = tmp + df_dX[ic] * kfwd;
237  }
238 
239  kfwd *= f; //finalize
240 
241  return;
242  }
243 
244 } // namespace Antioch
245 
246 #endif // ANTIOCH_FALLOFF_REACTION_H
A single reaction mechanism.
Definition: reaction.h:108
const std::string & equation() const
unsigned int n_species() const
void compute_forward_rate_coefficient_and_derivatives(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions, StateType &kfwd, StateType &dkfwd_dT, VectorStateType &dkfkwd_dX) const
Base class for falloff processes.
FalloffReaction(const unsigned int n_species, const std::string &equation, const bool &reversible=true, const ReactionType::ReactionType &falloffType=ReactionType::LINDEMANN_FALLOFF, const KineticsModel::KineticsModel kin=KineticsModel::KOOIJ)
Construct a single reaction mechanism.
const FalloffType & F() const
Return const reference to the falloff object.
StateType compute_forward_rate_coefficient(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions) const
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
const StateType & T() const
This class contains the conditions of the chemistry.

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