30 #include "antioch_config.h"
34 #ifdef ANTIOCH_HAVE_EIGEN
35 #include "Eigen/Dense"
38 #ifdef ANTIOCH_HAVE_METAPHYSICL
39 #include "metaphysicl/numberarray.h"
42 #ifdef ANTIOCH_HAVE_VEXCL
43 #include "vexcl/vexcl.hpp"
59 #ifdef ANTIOCH_HAVE_GRVY
62 GRVY::GRVY_Timer_Class gt;
65 template <
typename PairScalars>
67 const PairScalars & rate,
const PairScalars & derive,
const PairScalars & T)
70 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
73 for (
unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
75 if( abs( (rate[2*tuple] - rate_exact[2*tuple])/rate_exact[2*tuple] ) > tol )
77 std::cout << std::scientific << std::setprecision(16)
78 <<
"Error: Mismatch in rate values." << std::endl
79 <<
"T = " << T <<
" K" << std::endl
80 <<
"rate(T) = " << rate[2*tuple] << std::endl
81 <<
"rate_exact = " << rate_exact[2*tuple] << std::endl
82 <<
"relative difference = " << abs( (rate[2*tuple] - rate_exact[2*tuple])/rate_exact[2*tuple] ) << std::endl
83 <<
"tolerance = " << tol << std::endl;
87 if( abs( (rate[2*tuple+1] - rate_exact[2*tuple+1])/rate_exact[2*tuple+1] ) > tol )
89 std::cout << std::scientific << std::setprecision(16)
90 <<
"Error: Mismatch in rate values." << std::endl
91 <<
"T = " << T <<
" K" << std::endl
92 <<
"rate(T) = " << rate[2*tuple] << std::endl
93 <<
"rate_exact = " << rate_exact[2*tuple+1] << std::endl
94 <<
"relative difference = " << abs( (rate[2*tuple] - rate_exact[2*tuple+1])/rate_exact[2*tuple+1] ) << std::endl
95 <<
"tolerance = " << tol << std::endl;
99 if( abs( (derive[2*tuple] - derive_exact[2*tuple])/derive_exact[2*tuple] ) > tol )
101 std::cout << std::scientific << std::setprecision(16)
102 <<
"Error: Mismatch in rate derivative values." << std::endl
103 <<
"T = " << T <<
" K" << std::endl
104 <<
"drate_dT(T) = " << derive[2*tuple] << std::endl
105 <<
"derive_exact = " << derive_exact[2*tuple] << std::endl
106 <<
"relative difference = " << abs( (derive[2*tuple] - derive_exact[2*tuple])/derive_exact[2*tuple] ) << std::endl
107 <<
"tolerance = " << tol << std::endl;
111 if( abs( (derive[2*tuple+1] - derive_exact[2*tuple+1])/derive_exact[2*tuple+1] ) > tol )
113 std::cout << std::scientific << std::setprecision(16)
114 <<
"Error: Mismatch in rate derivative values." << std::endl
115 <<
"T = " << T <<
" K" << std::endl
116 <<
"drate_dT(T) = " << derive[2*tuple+1] << std::endl
117 <<
"derive_exact = " << derive_exact[2*tuple+1] << std::endl
118 <<
"relative difference = " << abs( (derive[2*tuple+1] - derive_exact[2*tuple+1])/derive_exact[2*tuple+1] ) << std::endl
119 <<
"tolerance = " << tol << std::endl;
128 template <
typename PairScalars>
129 int vectester(
const PairScalars& example,
const std::string & testname)
137 const Scalar Cf = 1.4;
138 const Scalar eta = 1.2;
139 const Scalar Ea = 5.0;
144 PairScalars T = example;
145 PairScalars rate_exact = example;
146 PairScalars derive_exact = example;
148 for (
unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
151 T[2*tuple+1] = 1600.1;
152 rate_exact[2*tuple] = Cf*
pow(Scalar(1500.1),eta)*exp(-Ea/1500.1);
153 rate_exact[2*tuple+1] = Cf*
pow(Scalar(1600.1),eta)*exp(-Ea/1600.1);
154 derive_exact[2*tuple] = exp(-Ea/Scalar(1500.1)) *
pow(Scalar(1500.1),eta) * Cf/Scalar(1500.1) * (Ea/Scalar(1500.1) + eta );
155 derive_exact[2*tuple+1] = exp(-Ea/Scalar(1600.1)) *
pow(Scalar(1600.1),eta) * Cf/Scalar(1600.1) * (Ea/Scalar(1600.1) + eta );
162 #ifdef ANTIOCH_HAVE_GRVY
163 gt.BeginTimer(testname);
165 PairScalars rate = kooij_rate(cond);
166 PairScalars derive = kooij_rate.
derivative(cond);
168 #ifdef ANTIOCH_HAVE_GRVY
169 gt.EndTimer(testname);
174 #ifdef ANTIOCH_HAVE_GRVY
175 gt.BeginTimer(testname);
180 #ifdef ANTIOCH_HAVE_GRVY
181 gt.EndTimer(testname);
187 #ifdef ANTIOCH_HAVE_GRVY
188 gt.BeginTimer(testname);
190 rate = kooij_rate(T);
193 #ifdef ANTIOCH_HAVE_GRVY
194 gt.EndTimer(testname);
199 #ifdef ANTIOCH_HAVE_GRVY
200 gt.BeginTimer(testname);
205 #ifdef ANTIOCH_HAVE_GRVY
206 gt.EndTimer(testname);
211 std::cout <<
"Kooij rate: " << kooij_rate << std::endl;
221 returnval = returnval ||
222 vectester (std::valarray<float>(2*ANTIOCH_N_TUPLES),
"valarray<float>");
223 returnval = returnval ||
224 vectester (std::valarray<double>(2*ANTIOCH_N_TUPLES),
"valarray<double>");
225 returnval = returnval ||
226 vectester (std::valarray<long double>(2*ANTIOCH_N_TUPLES),
"valarray<ld>");
227 #ifdef ANTIOCH_HAVE_EIGEN
228 returnval = returnval ||
229 vectester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(),
"Eigen::ArrayXf");
230 returnval = returnval ||
231 vectester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(),
"Eigen::ArrayXd");
232 returnval = returnval ||
233 vectester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(),
"Eigen::ArrayXld");
235 #ifdef ANTIOCH_HAVE_METAPHYSICL
236 returnval = returnval ||
237 vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0),
"NumberArray<float>");
238 returnval = returnval ||
239 vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0),
"NumberArray<double>");
240 returnval = returnval ||
241 vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0),
"NumberArray<ld>");
243 #ifdef ANTIOCH_HAVE_VEXCL
244 vex::Context ctx_f (vex::Filter::All);
246 returnval = returnval ||
247 vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES),
"vex::vector<float>");
249 vex::Context ctx_d (vex::Filter::DoublePrecision);
251 returnval = returnval ||
252 vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES),
"vex::vector<double>");
255 #ifdef ANTIOCH_HAVE_GRVY
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
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
int check_rate_and_derivative(const PairScalars &rate_exact, const PairScalars &derive_exact, const PairScalars &rate, const PairScalars &derive, const PairScalars &T)
int vectester(const PairScalars &example, const std::string &testname)
This class contains the conditions of the chemistry.