antioch-0.4.0
arrhenius_rate_deriv.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 // $Id$
28 //
29 //--------------------------------------------------------------------------
30 //--------------------------------------------------------------------------
31 
32 #include "antioch_config.h"
33 
34 #ifdef ANTIOCH_HAVE_METAPHYSICL
35 #include "metaphysicl/dualnumber.h"
36 
37 #include "antioch/arrhenius_rate.h"
38 
39 #include <iomanip>
40 #include <string>
41 
42 template <typename Scalar>
43 int tester(const std::string& testname)
44 {
45  using std::abs;
46  using std::exp;
47  using std::pow;
48  using MetaPhysicL::DualNumber;
49 
50  int return_flag = 0;
51 
52  const Scalar Cf = 1.4;
53  const Scalar Ea = 5.0;
54 
55  const DualNumber<Scalar> Ea_DN(Ea, 1);
56 
57  Antioch::ArrheniusRate<Scalar> arrhenius_rate(Cf,Ea);
58 
59  const Scalar T = 1500.1;
60 
61  Scalar rate, deriveRate;
62 
63  arrhenius_rate.rate_and_derivative(T,rate,deriveRate);
64 
65 
67  arrhenius_T_sensitivity(Cf,Ea);
68 
69  const DualNumber<Scalar> T_DN(T, 1);
70 
71  DualNumber<Scalar> rate_DN_T = arrhenius_T_sensitivity(T_DN);
72 
73  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
74 
75  if( abs( (deriveRate - rate_DN_T.derivatives())/deriveRate) > tol )
76  {
77  std::cout << "Error: Mismatch in " << testname << " rate derivatives." << std::endl
78  << std::setprecision(25)
79  << "deriveRate(T) = " << deriveRate << std::endl
80  << "rate_DN_T' = " << rate_DN_T.derivatives() << std::endl;
81 
82  return_flag = 1;
83  }
84 
85 
87  arrhenius_Ea_sensitivity(Cf,Ea_DN);
88 
89  const Scalar perturb =
90  std::pow(std::numeric_limits<Scalar>::epsilon(), (1./3.)) * 100;
91 
92  Antioch::ArrheniusRate<Scalar> arrhenius_rate_Eaplus(Cf,Ea + perturb);
93  Antioch::ArrheniusRate<Scalar> arrhenius_rate_Eaminus(Cf,Ea - perturb);
94 
95  // FIXME - we need to upgrade the return type of templated functions
96  // in the case where the input StateType is *weaker* than CoeffType
97  DualNumber<Scalar> rate_DN_Ea =
98  arrhenius_Ea_sensitivity(DualNumber<Scalar>(T) );
99 
100  Scalar dR_dEa = (arrhenius_rate_Eaplus(T) -
101  arrhenius_rate_Eaminus(T)) / (2 * perturb);
102 
103  if( abs( (dR_dEa - rate_DN_Ea.derivatives())/dR_dEa) >
104  perturb * perturb * 100)
105  {
106  std::cout << "Error: Mismatch in " << testname << " rate derivatives." << std::endl
107  << std::setprecision(25)
108  << "perturb = " << perturb << std::endl
109  << "dR_dEa = " << dR_dEa << std::endl
110  << "rate_DN_Ea' = " << rate_DN_Ea.derivatives() << std::endl;
111 
112  return_flag = 1;
113  }
114 
115  return return_flag;
116 }
117 #endif
118 
119 int main()
120 {
121 #ifdef ANTIOCH_HAVE_METAPHYSICL
122  return (tester<double>("double") ||
123  tester<long double>("long double") ||
124  tester<float>("float"));
125 #else
126  return 77; // automake code for a skipped test
127 #endif
128 }
int main()
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
int tester(const std::string &testname)
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const

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