31 #include "antioch_config.h"
35 #ifdef ANTIOCH_HAVE_EIGEN
36 #include "Eigen/Dense"
39 #ifdef ANTIOCH_HAVE_METAPHYSICL
40 #include "metaphysicl/numberarray.h"
43 #ifdef ANTIOCH_HAVE_VEXCL
44 #include "vexcl/vexcl.hpp"
60 #ifdef ANTIOCH_HAVE_GRVY
63 GRVY::GRVY_Timer_Class gt;
66 template <
typename PairScalars>
68 const PairScalars & rate,
const PairScalars & derive,
const PairScalars & T)
71 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
74 for (
unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
76 if( abs( (rate[2*tuple] - rate_exact[2*tuple])/rate_exact[2*tuple] ) > tol )
78 std::cout << std::scientific << std::setprecision(16)
79 <<
"Error: Mismatch in rate values." << std::endl
80 <<
"T = " << T[2*tuple] <<
" K" << std::endl
81 <<
"rate(T) = " << rate[2*tuple] << std::endl
82 <<
"rate_exact = " << rate_exact[2*tuple] << std::endl
83 <<
"relative difference = " << abs( (rate[2*tuple] - rate_exact[2*tuple])/rate_exact[2*tuple] ) << std::endl
84 <<
"tolerance = " << tol << std::endl;
88 if( abs( (rate[2*tuple+1] - rate_exact[2*tuple+1])/rate_exact[2*tuple+1] ) > tol )
90 std::cout << std::scientific << std::setprecision(16)
91 <<
"Error: Mismatch in rate values." << std::endl
92 <<
"T = " << T[2*tuple+1] <<
" K" << std::endl
93 <<
"rate(T) = " << rate[2*tuple] << std::endl
94 <<
"rate_exact = " << rate_exact[2*tuple+1] << std::endl
95 <<
"relative difference = " << abs( (rate[2*tuple] - rate_exact[2*tuple+1])/rate_exact[2*tuple+1] ) << std::endl
96 <<
"tolerance = " << tol << std::endl;
100 if( abs( (derive[2*tuple] - derive_exact[2*tuple])/derive_exact[2*tuple] ) > tol )
102 std::cout << std::scientific << std::setprecision(16)
103 <<
"Error: Mismatch in rate derivative values." << std::endl
104 <<
"T = " << T[2*tuple] <<
" K" << std::endl
105 <<
"drate_dT(T) = " << derive[2*tuple] << std::endl
106 <<
"derive_exact = " << derive_exact[2*tuple] << std::endl
107 <<
"relative difference = " << abs( (derive[2*tuple] - derive_exact[2*tuple])/derive_exact[2*tuple] ) << std::endl
108 <<
"tolerance = " << tol << std::endl;
112 if( abs( (derive[2*tuple+1] - derive_exact[2*tuple+1])/derive_exact[2*tuple+1] ) > tol )
114 std::cout << std::scientific << std::setprecision(16)
115 <<
"Error: Mismatch in rate derivative values." << std::endl
116 <<
"T = " << T[2*tuple+1] <<
" K" << std::endl
117 <<
"drate_dT(T) = " << derive[2*tuple+1] << std::endl
118 <<
"derive_exact = " << derive_exact[2*tuple+1] << std::endl
119 <<
"relative difference = " << abs( (derive[2*tuple+1] - derive_exact[2*tuple+1])/derive_exact[2*tuple+1] ) << std::endl
120 <<
"tolerance = " << tol << std::endl;
129 template <
typename PairScalars>
130 int vectester(
const PairScalars& example,
const std::string & testname)
136 const Scalar Cf = 1.4L;
141 PairScalars T = example;
142 PairScalars rate_exact = example;
144 for (
unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
146 T[2*tuple] = 1500.1L;
147 T[2*tuple+1] = 1600.1L;
148 rate_exact[2*tuple] = Cf;
149 rate_exact[2*tuple+1] = Cf;
155 #ifdef ANTIOCH_HAVE_GRVY
156 gt.BeginTimer(testname);
160 PairScalars rate = constant_rate(cond);
161 PairScalars derive = constant_rate.
derivative(cond);
163 #ifdef ANTIOCH_HAVE_GRVY
164 gt.EndTimer(testname);
169 #ifdef ANTIOCH_HAVE_GRVY
170 gt.BeginTimer(testname);
175 #ifdef ANTIOCH_HAVE_GRVY
176 gt.EndTimer(testname);
183 #ifdef ANTIOCH_HAVE_GRVY
184 gt.BeginTimer(testname);
187 rate = constant_rate(T);
190 #ifdef ANTIOCH_HAVE_GRVY
191 gt.EndTimer(testname);
196 #ifdef ANTIOCH_HAVE_GRVY
197 gt.BeginTimer(testname);
202 #ifdef ANTIOCH_HAVE_GRVY
203 gt.EndTimer(testname);
216 returnval = returnval ||
217 vectester (std::valarray<float>(2*ANTIOCH_N_TUPLES),
"valarray<float>");
218 returnval = returnval ||
219 vectester (std::valarray<double>(2*ANTIOCH_N_TUPLES),
"valarray<double>");
220 returnval = returnval ||
221 vectester (std::valarray<long double>(2*ANTIOCH_N_TUPLES),
"valarray<ld>");
222 #ifdef ANTIOCH_HAVE_EIGEN
223 returnval = returnval ||
224 vectester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(),
"Eigen::ArrayXf");
225 returnval = returnval ||
226 vectester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(),
"Eigen::ArrayXd");
227 returnval = returnval ||
228 vectester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(),
"Eigen::ArrayXld");
230 #ifdef ANTIOCH_HAVE_METAPHYSICL
231 returnval = returnval ||
232 vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0),
"NumberArray<float>");
233 returnval = returnval ||
234 vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0),
"NumberArray<double>");
235 returnval = returnval ||
236 vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0),
"NumberArray<ld>");
238 #ifdef ANTIOCH_HAVE_VEXCL
239 vex::Context ctx_f (vex::Filter::All);
241 returnval = returnval ||
242 vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES),
"vex::vector<float>");
244 vex::Context ctx_d (vex::Filter::DoublePrecision);
246 returnval = returnval ||
247 vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES),
"vex::vector<double>");
250 #ifdef ANTIOCH_HAVE_GRVY
int vectester(const PairScalars &example, const std::string &testname)
int check_rate_and_derivative(const PairScalars &rate_exact, const PairScalars &derive_exact, const PairScalars &rate, const PairScalars &derive, const PairScalars &T)
VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &cond) const ANTIOCH_AUTOFUNC(StateType
VectorStateType VectorStateType VectorStateType void rate_and_derivative(const KineticsConditions< StateType, VectorStateType > &cond, StateType &rate, StateType &drate_dT) const
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
This class contains the conditions of the chemistry.