antioch-0.4.0
berthelothercourtessen_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
32 
33 
34 template <typename Scalar>
35 int check_rate_and_derivative(const Scalar & rate_exact, const Scalar & derive_exact,
36  const Scalar & rate, const Scalar & derive, const Scalar & T)
37 {
38  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
39  int return_flag(0);
40  if( abs( (rate - rate_exact)/rate_exact ) > tol )
41  {
42  std::cout << std::scientific << std::setprecision(16)
43  << "Error: Mismatch in rate values." << std::endl
44  << "T = " << T << " K" << std::endl
45  << "rate(T) = " << rate << std::endl
46  << "rate_exact = " << rate_exact << std::endl
47  << "relative difference = " << abs( (rate - rate_exact)/rate_exact ) << std::endl
48  << "tolerance = " << tol << std::endl;
49 
50  return_flag = 1;
51  }
52  if( abs( (derive - derive_exact)/derive_exact ) > tol )
53  {
54  std::cout << std::scientific << std::setprecision(16)
55  << "Error: Mismatch in rate derivative values." << std::endl
56  << "T = " << T << " K" << std::endl
57  << "drate_dT(T) = " << derive << std::endl
58  << "derive_exact = " << derive_exact << std::endl
59  << "relative difference = " << abs( (derive - derive_exact)/derive_exact ) << std::endl
60  << "tolerance = " << tol << std::endl;
61 
62  return_flag = 1;
63  }
64 
65  return return_flag;
66 }
67 
68 template <typename Scalar>
69 int test_values(const Scalar & Cf, const Scalar & eta, const Scalar & D, const Scalar & Tref, const Antioch::BerthelotHercourtEssenRate<Scalar> & berthelothercourtessen_rate)
70 {
71  using std::abs;
72  using std::exp;
73  using std::pow;
74  int return_flag = 0;
75 
76  for(Scalar T = 300.1L; T <= 2500.1L; T += 10.L)
77  {
78  const Scalar rate_exact = Cf*pow(T/Tref,eta)*exp(D*T);
79  const Scalar derive_exact = Cf * pow(T/Tref,eta) * exp(D*T) * (D + eta/T);
81 
82 // KineticsConditions
83  Scalar rate = berthelothercourtessen_rate(cond);
84  Scalar deriveRate = berthelothercourtessen_rate.derivative(cond);
85 
86  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
87 
88  berthelothercourtessen_rate.rate_and_derivative(cond,rate,deriveRate);
89 
90  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
91 
92 // T
93  rate = berthelothercourtessen_rate(T);
94  deriveRate = berthelothercourtessen_rate.derivative(T);
95 
96  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
97 
98  berthelothercourtessen_rate.rate_and_derivative(T,rate,deriveRate);
99 
100  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
101 
102  }
103  return return_flag;
104 
105 }
106 
107 
108 template <typename Scalar>
109 int tester()
110 {
111  Scalar Cf = 1.4L;
112  Scalar eta = 1.2L;
113  Scalar D = -5.0L;
114  Scalar Tref = 1.0L;
115 
116  Antioch::BerthelotHercourtEssenRate<Scalar> berthelothercourtessen_rate(Cf,eta,D);
117 
118  int return_flag = test_values(Cf,eta,D,Tref,berthelothercourtessen_rate);
119 
120  Cf = 1e-7L;
121  eta = 0.6L;
122  D = 1e-3L;
123  Tref = 298.0L;
124  berthelothercourtessen_rate.set_Cf(Cf);
125  berthelothercourtessen_rate.set_eta(eta);
126  berthelothercourtessen_rate.set_D(D);
127  berthelothercourtessen_rate.set_Tref(Tref);
128 
129  return_flag = test_values(Cf,eta,D,Tref,berthelothercourtessen_rate) || return_flag;
130 
131  Cf = 2.1e-7L;
132  eta = 0.35L;
133  D = 8.1e-3L;
134  std::vector<Scalar> values(3);
135  values[0] = Cf;
136  values[1] = eta;
137  values[2] = D;
138  berthelothercourtessen_rate.reset_coefs(values);
139 
140  return_flag = test_values(Cf,eta,D,Tref,berthelothercourtessen_rate) || return_flag;
141 
142  Cf = 2.1e-11L;
143  eta = -0.35L;
144  D = -2.1;
145  Tref = 300.L;
146  values.resize(4);
147  values[0] = Cf;
148  values[1] = eta;
149  values[2] = D;
150  values[3] = Tref;
151  berthelothercourtessen_rate.reset_coefs(values);
152 
153  return_flag = test_values(Cf,eta,D,Tref,berthelothercourtessen_rate) || return_flag;
154 
155 
156  return return_flag;
157 }
158 
159 int main()
160 {
161  return (tester<double>() ||
162  tester<long double>() ||
163  tester<float>());
164 }
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
Berthelot Hercourt-Essen rate equation.
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
int test_values(const Scalar &Cf, const Scalar &eta, const Scalar &D, const Scalar &Tref, const Antioch::BerthelotHercourtEssenRate< Scalar > &berthelothercourtessen_rate)
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs
int check_rate_and_derivative(const Scalar &rate_exact, const Scalar &derive_exact, const Scalar &rate, const Scalar &derive, const Scalar &T)
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