antioch-0.4.0
photochemical_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_PHOTOCHEMICAL_RATE_H
28 #define ANTIOCH_PHOTOCHEMICAL_RATE_H
29 
30 //Antioch
34 #include "antioch/kinetics_type.h"
35 #include "antioch/particle_flux.h"
36 
37 //C++
38 #include <vector>
39 #include <string>
40 #include <sstream>
41 
42 namespace Antioch{
52  template<typename CoeffType, typename VectorCoeffType = std::vector<CoeffType> >
53  class PhotochemicalRate:public KineticsType<CoeffType,VectorCoeffType>
54  {
55 
56  private:
57  VectorCoeffType _cross_section;
58  VectorCoeffType _lambda_grid;
60 
61  public:
62  PhotochemicalRate(const VectorCoeffType &cs, const VectorCoeffType &lambda);
65 
66 
67  VectorCoeffType cross_section() const;
68  VectorCoeffType lambda_grid() const;
69 
70 
72  void set_cross_section(const VectorCoeffType &cs);
73 
75  void set_lambda_grid(const VectorCoeffType &l);
76 
78  void set_cross_section(CoeffType cs, int il);
79 
81  void set_lambda_grid(CoeffType l, int il);
82 
84  void set_parameter(KineticsModel::Parameters parameter, int l, CoeffType new_value);
85 
87  CoeffType get_parameter(KineticsModel::Parameters parameter, int l) const;
88 
94  void reset_coefs(const VectorCoeffType & coefficients);
95 
97  template<typename VectorStateType>
98  void calculate_rate_constant(const VectorStateType &hv_flux, const VectorStateType &hv_lambda, bool x_update = true);
99 
101  template <typename VectorStateType>
103  operator()(const ParticleFlux<VectorStateType> & pf) const
104  ANTIOCH_AUTOFUNC(typename value_type<VectorStateType>::type , this->rate(pf))
105 
107  template <typename VectorStateType>
108  typename value_type<VectorStateType>::type
109  rate(const ParticleFlux<VectorStateType>& pf) const;
110 
112  template <typename VectorStateType>
113  ANTIOCH_AUTO(typename value_type<VectorStateType>::type)
114  derivative( const ParticleFlux<VectorStateType>& /* ex */) const
115  ANTIOCH_AUTOFUNC(typename value_type<VectorStateType>::type, 0)
116 
118  template <typename StateType, typename VectorStateType>
119  void rate_and_derivative(const ParticleFlux<VectorStateType>& pf, StateType& rate, StateType& drate_dT) const;
120 
122  const std::string numeric() const;
123 
124  };
125 
126  template<typename CoeffType, typename VectorCoeffType>
127  inline
128  PhotochemicalRate<CoeffType,VectorCoeffType>::PhotochemicalRate(const VectorCoeffType &cs,
129  const VectorCoeffType &lambda):
130  KineticsType<CoeffType,VectorCoeffType>(KineticsModel::PHOTOCHEM),
131  _cross_section(cs),
132  _lambda_grid(lambda)
133  {
134  return;
135  }
136 
137  template<typename CoeffType, typename VectorCoeffType>
138  inline
140  KineticsType<CoeffType,VectorCoeffType>(KineticsModel::PHOTOCHEM)
141  {
142  return;
143  }
144 
145  template<typename CoeffType, typename VectorCoeffType>
146  inline
148  {
149  return;
150  }
151 
152  template<typename CoeffType, typename VectorCoeffType>
153  inline
155  {
156  _cross_section = cs;
157  }
158 
159  template<typename CoeffType, typename VectorCoeffType>
160  inline
162  {
163  _lambda_grid = l;
164  }
165  template<typename CoeffType, typename VectorCoeffType>
166  inline
168  {
169  antioch_assert_less(il,_cross_section.size());
170 
171  _cross_section[il] = cs;
172  }
173 
174  template<typename CoeffType, typename VectorCoeffType>
175  inline
177  {
178  antioch_assert_less(il,_lambda_grid.size());
179 
180  _lambda_grid[il] = l;
181  }
182 
183  template<typename CoeffType, typename VectorCoeffType>
184  inline
185  void PhotochemicalRate<CoeffType,VectorCoeffType>::reset_coefs(const VectorCoeffType & coefficients)
186  {
187  // we require the two vectors being the same size
188  antioch_assert_equal_to(coefficients.size()%2,0);
189 
190  const unsigned int subsize(coefficients.size()/2);
191  VectorCoeffType l(subsize);
192  VectorCoeffType cs(subsize);
193  for(unsigned int il = 0; il < subsize; il++)
194  {
195  l[il] = coefficients[il];
196  cs[il] = coefficients[il + subsize];
197  }
198  this->set_lambda_grid(l);
199  this->set_cross_section(cs);
200  }
201 
202  template<typename CoeffType, typename VectorCoeffType>
203  inline
205  {
206 
207  switch(parameter)
208  {
210  {
211  this->set_lambda_grid(new_value,l);
212  }
213  break;
215  {
216  this->set_cross_section(new_value,l);
217  }
218  break;
219  default:
220  {
221  antioch_error();
222  }
223  break;
224  }
225  }
226 
227  template<typename CoeffType, typename VectorCoeffType>
228  inline
230  {
231 
232  antioch_assert_less(l,_cross_section.size());
233 
234  switch(parameter)
235  {
237  {
238  return this->lambda_grid()[l];
239  }
240  break;
242  {
243  return this->cross_section()[l];
244  }
245  break;
246  default:
247  {
248  antioch_error();
249  }
250  break;
251  }
252 
253  return 0;
254  }
255 
256  template<typename CoeffType, typename VectorCoeffType>
257  template<typename VectorStateType>
258  inline
261  {
262  const VectorStateType &hv_flux = pf.flux();
263  const VectorStateType &hv_lambda = pf.abscissa();
264 
265 //cross-section and lambda exists
266  antioch_assert_greater(_cross_section.size(),0);
267  antioch_assert_greater(_lambda_grid.size(),0);
268 
269 //needed grid to the right size
270  VectorStateType cross_section_on_flux_grid(hv_lambda.size());
271 
272 //put them on the right grid
273  _converter.y_on_custom_grid(_lambda_grid,_cross_section,hv_lambda,cross_section_on_flux_grid);
274 
275 //calculates
278  for(unsigned int ibin = 0; ibin < hv_lambda.size() - 1; ibin++)
279  {
280  k += cross_section_on_flux_grid[ibin] * hv_flux[ibin] * (hv_lambda[ibin+1] - hv_lambda[ibin]); //right stairs
281  }
282  return k;
283  }
284 
285  template<typename CoeffType, typename VectorCoeffType>
286  inline
288  {
289  std::stringstream os;
290  os << "int_0^infty sigma(lambda) * hv(lambda) * dlambda";
291 
292  return os.str();
293  }
294 
295 
296  template<typename CoeffType, typename VectorCoeffType>
297  template <typename StateType, typename VectorStateType>
298  inline
299  void PhotochemicalRate<CoeffType,VectorCoeffType>::rate_and_derivative(const ParticleFlux<VectorStateType> &pf, StateType& rate, StateType& drate_dT) const
300  {
301  Antioch::init_clone(rate,this->rate(pf));
302  Antioch::set_zero(drate_dT);
303  return;
304  }
305 
306  template<typename CoeffType, typename VectorCoeffType>
307  inline
309  {
310  return _cross_section;
311  }
312 
313  template<typename CoeffType, typename VectorCoeffType>
314  inline
316  {
317  return _lambda_grid;
318  }
319 
320 } //end namespace Antioch
321 
322 #endif
operator()(const ParticleFlux< VectorStateType > &pf) const template< typename VectorStateType > typename value_type< VectorStateType > derivative(const ParticleFlux< VectorStateType > &) const template< typename StateType
Simultaneously evaluate the rate and its derivative at T.
const std::string numeric() const
print equation
Stores the incoming flux of particles.
Definition: particle_flux.h:38
base class for kinetics models
Definition: kinetics_type.h:82
#define antioch_assert_equal_to(expr1, expr2)
#define antioch_assert_greater(expr1, expr2)
KineticsModel::KineticsModel type() const
const VectorCoeffType & flux() const
Definition: particle_flux.h:93
VectorCoeffType lambda_grid() const
#define antioch_assert_less(expr1, expr2)
void set_lambda_grid(const VectorCoeffType &l)
const VectorCoeffType & abscissa() const
Definition: particle_flux.h:86
#define antioch_error()
void init_clone(T &output, const T &example)
void reset_coefs(const VectorCoeffType &coefficients)
reset the coefficients
void set_cross_section(const VectorCoeffType &cs)
void set_parameter(KineticsModel::Parameters parameter, int l, CoeffType new_value)
set one value of one parameter, characterized by enum and its index
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
void y_on_custom_grid(const VectorCoeffType &x_old, const VectorCoeffType &y_old, const VectorStateType &x_new, VectorStateType &y_new) const
void calculate_rate_constant(const VectorStateType &hv_flux, const VectorStateType &hv_lambda, bool x_update=true)
calculate _k for a given photon flux
SigmaBinConverter< VectorCoeffType > _converter
The parameters are reduced parameters.
Photochemical rate.
Definition: kinetics_type.h:65
CoeffType get_parameter(KineticsModel::Parameters parameter, int l) const
set one parameter, characterized by enum
VectorCoeffType cross_section() const
operator()(const ParticleFlux< VectorStateType > &pf) const template< typename VectorStateType > typename value_type< VectorStateType > VectorStateType void rate_and_derivative(const ParticleFlux< VectorStateType > &pf, StateType &rate, StateType &drate_dT) const

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