antioch-0.4.0
kooij_rate_unit.C
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 // C++
28 #include <limits>
29 #include <vector>
30 // Antioch
31 #include "antioch/kooij_rate.h"
33 #include "antioch/units.h"
34 
35 template <typename Scalar>
36 int check_rate_and_derivative(const Scalar & rate_exact, const Scalar & derive_exact,
37  const Scalar & rate, const Scalar & derive, const Scalar & T)
38 {
39  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
40  int return_flag(0);
41  if( abs( (rate - rate_exact)/rate_exact ) > tol )
42  {
43  std::cout << std::scientific << std::setprecision(16)
44  << "Error: Mismatch in rate values." << std::endl
45  << "T = " << T << " K" << std::endl
46  << "rate(T) = " << rate << std::endl
47  << "rate_exact = " << rate_exact << std::endl
48  << "relative difference = " << abs( (rate - rate_exact)/rate_exact ) << std::endl
49  << "tolerance = " << tol << std::endl;
50 
51  return_flag = 1;
52  }
53  if( abs( (derive - derive_exact)/derive_exact ) > tol )
54  {
55  std::cout << std::scientific << std::setprecision(16)
56  << "Error: Mismatch in rate derivative values." << std::endl
57  << "T = " << T << " K" << std::endl
58  << "drate_dT(T) = " << derive << std::endl
59  << "derive_exact = " << derive_exact << std::endl
60  << "relative difference = " << abs( (derive - derive_exact)/derive_exact ) << std::endl
61  << "tolerance = " << tol << std::endl;
62 
63  return_flag = 1;
64  }
65 
66  return return_flag;
67 }
68 
69 template <typename Scalar>
70 int test_values(const Scalar & Cf, const Scalar & eta, const Scalar & Ea, const Scalar & Tref, const Scalar & R, const Antioch::KooijRate<Scalar> & kooij_rate)
71 {
72  using std::abs;
73  using std::exp;
74  using std::pow;
75 
76  int return_flag = 0;
77 
78  for(Scalar T = 300.1L; T <= 2500.1L; T += 10.L)
79  {
80 
81  const Scalar rate_exact = Cf*pow(T/Tref,eta)*exp(-Ea/(R*T));
82  const Scalar derive_exact = exp(-Ea/(R*T)) * pow(T/Tref,eta) * Cf * (Ea/(R*T*T) + eta/T );
84 
85 // KineticsConditions
86  Scalar rate = kooij_rate(cond);
87  Scalar deriveRate = kooij_rate.derivative(cond);
88 
89  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
90 
91  kooij_rate.rate_and_derivative(cond,rate,deriveRate);
92 
93  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
94 
95 // T
96  rate = kooij_rate(T);
97  deriveRate = kooij_rate.derivative(T);
98 
99  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
100 
101  kooij_rate.rate_and_derivative(T,rate,deriveRate);
102 
103  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
104 
105  }
106  return return_flag;
107 }
108 
109 template <typename Scalar>
110 int tester()
111 {
112 
113  Scalar Cf = 1.4L;
114  Scalar eta = 1.2L;
115  Scalar Ea = 298.0L;
116  Scalar Tref = 1.L;
117  Scalar R = 1.L;
118 
119  Antioch::KooijRate<Scalar> kooij_rate(Cf,eta,Ea,Tref,R);
120 
121  int return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate);
122 
123  Cf = 1e-7L;
124  eta = 0.7L;
125  Ea = 36000.0L;
126  Tref = 298.;
127  R = Antioch::Constants::R_universal<Scalar>() * Antioch::Units<Scalar>("cal").get_SI_factor();
128  kooij_rate.set_Cf(Cf);
129  kooij_rate.set_eta(eta);
130  kooij_rate.set_Ea(Ea);
131  kooij_rate.set_Tref(Tref);
132  kooij_rate.set_rscale(R);
133 
134  return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate) || return_flag;
135 
136  Cf = 2.1e-7L;
137  eta = 1.1L;
138  Ea = 23000.0L;
139  std::vector<Scalar> values(3);
140  values[0] = Cf;
141  values[1] = eta;
142  values[2] = Ea;
143  kooij_rate.reset_coefs(values);
144 
145  return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate) || return_flag;
146 
147  Cf = 2.1e-11L;
148  eta = -0.01L;
149  Ea = 100000.0L;
150  R = Antioch::Constants::R_universal<Scalar>();
151  Tref= 300.L;
152  values.resize(5);
153  values[0] = Cf;
154  values[1] = eta;
155  values[2] = Ea;
156  values[3] = Tref;
157  values[4] = R;
158  kooij_rate.reset_coefs(values);
159 
160  return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate) || return_flag;
161 
162  return return_flag;
163 }
164 
165 int main()
166 {
167  return (tester<double>() ||
168  tester<long double>() ||
169  tester<float>());
170 }
void set_Tref(const CoeffType Tref)
Definition: kooij_rate.h:220
void set_Ea(const CoeffType Ea)
set _raw_Ea, unit is known (cal.mol-1, J.mol-1, whatever), _Ea is computed
Definition: kooij_rate.h:239
void set_rscale(const CoeffType scale)
Definition: kooij_rate.h:257
int main()
int check_rate_and_derivative(const Scalar &rate_exact, const Scalar &derive_exact, const Scalar &rate, const Scalar &derive, const Scalar &T)
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
Definition: kooij_rate.h:163
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
T get_SI_factor() const
Multiplicative coefficient getter.
Definition: units.h:334
void set_Cf(const CoeffType Cf)
Definition: kooij_rate.h:210
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs
Definition: kooij_rate.h:267
void set_eta(const CoeffType eta)
Definition: kooij_rate.h:230
Advanced unit class.
int tester()
int test_values(const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &Tref, const Scalar &R, const Antioch::KooijRate< Scalar > &kooij_rate)
Kooij rate equation.
Definition: kinetics_type.h:59
An advanced unit class.
Definition: units.h:111
This class contains the conditions of the chemistry.

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