antioch-0.4.0
Functions
berthelot_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/berthelot_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 berthelot_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 216 of file berthelot_rate_vec_unit.C.

References vectester().

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

References check_rate_and_derivative(), Antioch::KineticsModel::D, Antioch::BerthelotRate< CoeffType >::derivative(), and Antioch::BerthelotRate< CoeffType >::rate_and_derivative.

Referenced by main().

130 {
131  using std::abs;
132  using std::exp;
133 
134  typedef typename Antioch::value_type<PairScalars>::type Scalar;
135 
136  const Scalar Cf = 1.4;
137  const Scalar D = -2.5;
138 
139  Antioch::BerthelotRate<Scalar> berthelot_rate(Cf,D);
140 
141  // Construct from example to avoid resizing issues
142  PairScalars T = example;
143  PairScalars rate_exact = example;
144  PairScalars derive_exact = example;
145  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
146  {
147  T[2*tuple] = 1500.1;
148  T[2*tuple+1] = 1600.1;
149  rate_exact[2*tuple] = Cf*exp(D*1500.1);
150  rate_exact[2*tuple+1] = Cf*exp(D*1600.1);
151  derive_exact[2*tuple] = D * Cf * exp(D*Scalar(1500.1));
152  derive_exact[2*tuple+1] = D * Cf * exp(D*Scalar(1600.1));
153  }
155 
156  int return_flag = 0;
157 
158 // KineticsConditions
159 #ifdef ANTIOCH_HAVE_GRVY
160  gt.BeginTimer(testname);
161 #endif
162 
163  PairScalars rate = berthelot_rate(cond);
164  PairScalars derive = berthelot_rate.derivative(cond);
165 
166 #ifdef ANTIOCH_HAVE_GRVY
167  gt.EndTimer(testname);
168 #endif
169 
170  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
171 
172 #ifdef ANTIOCH_HAVE_GRVY
173  gt.BeginTimer(testname);
174 #endif
175 
176  berthelot_rate.rate_and_derivative(cond,rate,derive);
177 
178 #ifdef ANTIOCH_HAVE_GRVY
179  gt.EndTimer(testname);
180 #endif
181 
182  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
183 
184 // T
185 #ifdef ANTIOCH_HAVE_GRVY
186  gt.BeginTimer(testname);
187 #endif
188 
189  rate = berthelot_rate(T);
190  derive = berthelot_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 
202  berthelot_rate.rate_and_derivative(T,rate,derive);
203 
204 #ifdef ANTIOCH_HAVE_GRVY
205  gt.EndTimer(testname);
206 #endif
207 
208  return_flag = check_rate_and_derivative(rate_exact, derive_exact, rate, derive,T) || return_flag;
209 
210  std::cout << "Berthelot rate: " << berthelot_rate << std::endl;
211 
212  return return_flag;
213 }
Berthelot 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