antioch-0.4.0
Functions
kooij_rate_vec_unit.C File Reference
#include "antioch_config.h"
#include <valarray>
#include "Eigen/Dense"
#include "metaphysicl/numberarray.h"
#include "vexcl/vexcl.hpp"
#include "antioch/eigen_utils_decl.h"
#include "antioch/metaphysicl_utils_decl.h"
#include "antioch/valarray_utils_decl.h"
#include "antioch/kooij_rate.h"
#include "antioch/eigen_utils.h"
#include "antioch/metaphysicl_utils.h"
#include "antioch/valarray_utils.h"
#include <cmath>
#include <limits>

Go to the source code of this file.

Functions

template<typename PairScalars >
int check_rate_and_derivative (const PairScalars &rate_exact, const PairScalars &derive_exact, const PairScalars &rate, const PairScalars &derive, const PairScalars &T)
 
template<typename PairScalars >
int vectester (const PairScalars &example, const std::string &testname)
 
int main ()
 

Function Documentation

template<typename PairScalars >
int check_rate_and_derivative ( const PairScalars &  rate_exact,
const PairScalars &  derive_exact,
const PairScalars &  rate,
const PairScalars &  derive,
const PairScalars &  T 
)

Definition at line 66 of file kooij_rate_vec_unit.C.

Referenced by vectester().

68 {
69  typedef typename Antioch::value_type<PairScalars>::type Scalar;
70  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
71 
72  int return_flag(0);
73  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
74  {
75  if( abs( (rate[2*tuple] - rate_exact[2*tuple])/rate_exact[2*tuple] ) > tol )
76  {
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;
84 
85  return_flag = 1;
86  }
87  if( abs( (rate[2*tuple+1] - rate_exact[2*tuple+1])/rate_exact[2*tuple+1] ) > tol )
88  {
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;
96 
97  return_flag = 1;
98  }
99  if( abs( (derive[2*tuple] - derive_exact[2*tuple])/derive_exact[2*tuple] ) > tol )
100  {
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;
108 
109  return_flag = 1;
110  }
111  if( abs( (derive[2*tuple+1] - derive_exact[2*tuple+1])/derive_exact[2*tuple+1] ) > tol )
112  {
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;
120 
121  return_flag = 1;
122  }
123 
124  }
125  return return_flag;
126 }
int main ( )

Definition at line 217 of file kooij_rate_vec_unit.C.

References vectester().

218 {
219  int returnval = 0;
220 
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");
234 #endif
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>");
242 #endif
243 #ifdef ANTIOCH_HAVE_VEXCL
244  vex::Context ctx_f (vex::Filter::All);
245  if (!ctx_f.empty())
246  returnval = returnval ||
247  vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
248 
249  vex::Context ctx_d (vex::Filter::DoublePrecision);
250  if (!ctx_d.empty())
251  returnval = returnval ||
252  vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
253 #endif
254 
255 #ifdef ANTIOCH_HAVE_GRVY
256  gt.Finalize();
257  gt.Summarize();
258 #endif
259 
260  return returnval;
261 }
int vectester(const PairScalars &example, const std::string &testname)
template<typename PairScalars >
int vectester ( const PairScalars &  example,
const std::string &  testname 
)

Definition at line 129 of file kooij_rate_vec_unit.C.

References check_rate_and_derivative(), Antioch::KooijRate< CoeffType >::derivative(), std::pow(), and Antioch::KooijRate< CoeffType >::rate_and_derivative.

Referenced by main().

130 {
131  using std::abs;
132  using std::exp;
133  using std::pow;
134 
135  typedef typename Antioch::value_type<PairScalars>::type Scalar;
136 
137  const Scalar Cf = 1.4;
138  const Scalar eta = 1.2;
139  const Scalar Ea = 5.0;
140 
141  Antioch::KooijRate<Scalar> kooij_rate(Cf,eta,Ea,1.,1.);
142 
143  // Construct from example to avoid resizing issues
144  PairScalars T = example;
145  PairScalars rate_exact = example;
146  PairScalars derive_exact = example;
147 
148  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
149  {
150  T[2*tuple] = 1500.1;
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 );
156  }
158 
159  int return_flag = 0;
160 
161 // KineticsConditions
162 #ifdef ANTIOCH_HAVE_GRVY
163  gt.BeginTimer(testname);
164 #endif
165  PairScalars rate = kooij_rate(cond);
166  PairScalars derive = kooij_rate.derivative(cond);
167 
168 #ifdef ANTIOCH_HAVE_GRVY
169  gt.EndTimer(testname);
170 #endif
171 
172  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
173 
174 #ifdef ANTIOCH_HAVE_GRVY
175  gt.BeginTimer(testname);
176 #endif
177 
178  kooij_rate.rate_and_derivative(cond,rate,derive);
179 
180 #ifdef ANTIOCH_HAVE_GRVY
181  gt.EndTimer(testname);
182 #endif
183 
184  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
185 
186 // T
187 #ifdef ANTIOCH_HAVE_GRVY
188  gt.BeginTimer(testname);
189 #endif
190  rate = kooij_rate(T);
191  derive = kooij_rate.derivative(T);
192 
193 #ifdef ANTIOCH_HAVE_GRVY
194  gt.EndTimer(testname);
195 #endif
196 
197  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
198 
199 #ifdef ANTIOCH_HAVE_GRVY
200  gt.BeginTimer(testname);
201 #endif
202 
203  kooij_rate.rate_and_derivative(T,rate,derive);
204 
205 #ifdef ANTIOCH_HAVE_GRVY
206  gt.EndTimer(testname);
207 #endif
208 
209  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
210 
211  std::cout << "Kooij rate: " << kooij_rate << std::endl;
212 
213  return return_flag;
214 }
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
int check_rate_and_derivative(const PairScalars &rate_exact, const PairScalars &derive_exact, const PairScalars &rate, const PairScalars &derive, const PairScalars &T)
Kooij rate equation.
Definition: kinetics_type.h:59
This class contains the conditions of the chemistry.

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