antioch-0.4.0
Functions
hercourtessen_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/hercourtessen_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 67 of file hercourtessen_rate_vec_unit.C.

Referenced by vectester().

69 {
70  typedef typename Antioch::value_type<PairScalars>::type Scalar;
71  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
72 
73  int return_flag(0);
74  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
75  {
76  if( abs( (rate[2*tuple] - rate_exact[2*tuple])/rate_exact[2*tuple] ) > tol )
77  {
78  std::cout << std::scientific << std::setprecision(16)
79  << "Error: Mismatch in rate values." << std::endl
80  << "T = " << T << " 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;
85 
86  return_flag = 1;
87  }
88  if( abs( (rate[2*tuple+1] - rate_exact[2*tuple+1])/rate_exact[2*tuple+1] ) > tol )
89  {
90  std::cout << std::scientific << std::setprecision(16)
91  << "Error: Mismatch in rate values." << std::endl
92  << "T = " << T << " 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;
97 
98  return_flag = 1;
99  }
100  if( abs( (derive[2*tuple] - derive_exact[2*tuple])/derive_exact[2*tuple] ) > tol )
101  {
102  std::cout << std::scientific << std::setprecision(16)
103  << "Error: Mismatch in rate derivative values." << std::endl
104  << "T = " << T << " 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;
109 
110  return_flag = 1;
111  }
112  if( abs( (derive[2*tuple+1] - derive_exact[2*tuple+1])/derive_exact[2*tuple+1] ) > tol )
113  {
114  std::cout << std::scientific << std::setprecision(16)
115  << "Error: Mismatch in rate derivative values." << std::endl
116  << "T = " << T << " 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;
121 
122  return_flag = 1;
123  }
124 
125  }
126  return return_flag;
127 }
int main ( )

Definition at line 215 of file hercourtessen_rate_vec_unit.C.

References vectester().

216 {
217  int returnval = 0;
218 
219  returnval = returnval ||
220  vectester (std::valarray<float>(2*ANTIOCH_N_TUPLES), "valarray<float>");
221  returnval = returnval ||
222  vectester (std::valarray<double>(2*ANTIOCH_N_TUPLES), "valarray<double>");
223  returnval = returnval ||
224  vectester (std::valarray<long double>(2*ANTIOCH_N_TUPLES), "valarray<ld>");
225 #ifdef ANTIOCH_HAVE_EIGEN
226  returnval = returnval ||
227  vectester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXf");
228  returnval = returnval ||
229  vectester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXd");
230  returnval = returnval ||
231  vectester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXld");
232 #endif
233 #ifdef ANTIOCH_HAVE_METAPHYSICL
234  returnval = returnval ||
235  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray<float>");
236  returnval = returnval ||
237  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray<double>");
238  returnval = returnval ||
239  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray<ld>");
240 #endif
241 #ifdef ANTIOCH_HAVE_VEXCL
242  vex::Context ctx_f (vex::Filter::All);
243  if (!ctx_f.empty())
244  returnval = returnval ||
245  vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
246 
247  vex::Context ctx_d (vex::Filter::DoublePrecision);
248  if (!ctx_d.empty())
249  returnval = returnval ||
250  vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
251 #endif
252 
253 #ifdef ANTIOCH_HAVE_GRVY
254  gt.Finalize();
255  gt.Summarize();
256 #endif
257 
258  return returnval;
259 }
int vectester(const PairScalars &example, const std::string &testname)
template<typename PairScalars >
int vectester ( const PairScalars &  example,
const std::string &  testname 
)

Definition at line 130 of file hercourtessen_rate_vec_unit.C.

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

Referenced by main().

131 {
132  using std::abs;
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 
140  Antioch::HercourtEssenRate<Scalar> hercourtessen_rate(Cf,eta);
141 
142  // Construct from example to avoid resizing issues
143  PairScalars T = example;
144  PairScalars rate_exact = example;
145  PairScalars derive_exact = example;
146  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
147  {
148  T[2*tuple] = 1500.1L;
149  T[2*tuple+1] = 1600.1L;
150  rate_exact[2*tuple] = Cf*pow(Scalar(1500.1),eta);
151  rate_exact[2*tuple+1] = Cf*pow(Scalar(1600.1),eta);
152  derive_exact[2*tuple] = eta * Cf * pow(Scalar(1500.1),eta)/Scalar(1500.1);
153  derive_exact[2*tuple+1] = eta * Cf * pow(Scalar(1600.1),eta)/Scalar(1600.1);
154  }
156 
157  int return_flag = 0;
158 
159 #ifdef ANTIOCH_HAVE_GRVY
160  gt.BeginTimer(testname);
161 #endif
162 
163 // KineticsConditions
164  PairScalars rate = hercourtessen_rate(cond);
165  PairScalars derive = hercourtessen_rate.derivative(cond);
166 
167 #ifdef ANTIOCH_HAVE_GRVY
168  gt.EndTimer(testname);
169 #endif
170 
171  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
172 
173 #ifdef ANTIOCH_HAVE_GRVY
174  gt.BeginTimer(testname);
175 #endif
176 
177  hercourtessen_rate.rate_and_derivative(cond,rate,derive);
178 
179 #ifdef ANTIOCH_HAVE_GRVY
180  gt.EndTimer(testname);
181 #endif
182 
183  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
184 
185 // T
186 #ifdef ANTIOCH_HAVE_GRVY
187  gt.BeginTimer(testname);
188 #endif
189  rate = hercourtessen_rate(T);
190  derive = hercourtessen_rate.derivative(T);
191 
192 #ifdef ANTIOCH_HAVE_GRVY
193  gt.EndTimer(testname);
194 #endif
195 
196  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
197 
198 #ifdef ANTIOCH_HAVE_GRVY
199  gt.BeginTimer(testname);
200 #endif
201  hercourtessen_rate.rate_and_derivative(T,rate,derive);
202 
203 #ifdef ANTIOCH_HAVE_GRVY
204  gt.EndTimer(testname);
205 #endif
206 
207  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
208 
209  std::cout << "Hercourt Essen rate: " << hercourtessen_rate << std::endl;
210 
211  return return_flag;
212 }
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
Hercourt-Essen rate equation.
int check_rate_and_derivative(const PairScalars &rate_exact, const PairScalars &derive_exact, const PairScalars &rate, const PairScalars &derive, const PairScalars &T)
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