antioch-0.4.0
Functions
arrhenius_rate_deriv.C File Reference
#include "antioch_config.h"
#include "metaphysicl/dualnumber.h"
#include "antioch/arrhenius_rate.h"
#include <iomanip>
#include <string>

Go to the source code of this file.

Functions

template<typename Scalar >
int tester (const std::string &testname)
 
int main ()
 

Function Documentation

int main ( )

Definition at line 119 of file arrhenius_rate_deriv.C.

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 }
template<typename Scalar >
int tester ( const std::string &  testname)

Definition at line 43 of file arrhenius_rate_deriv.C.

References std::pow(), and Antioch::ArrheniusRate< CoeffType >::rate_and_derivative.

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 }
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)

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