antioch-0.4.0
Functions
kinetics_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/vector_utils_decl.h"
#include "antioch/vexcl_utils_decl.h"
#include "antioch/antioch_asserts.h"
#include "antioch/chemical_species.h"
#include "antioch/chemical_mixture.h"
#include "antioch/reaction_set.h"
#include "antioch/read_reaction_set_data.h"
#include "antioch/cea_thermo.h"
#include "antioch/kinetics_evaluator.h"
#include "antioch/eigen_utils.h"
#include "antioch/metaphysicl_utils.h"
#include "antioch/valarray_utils.h"
#include "antioch/vector_utils.h"
#include "antioch/vexcl_utils.h"
#include <limits>
#include <string>
#include <vector>

Go to the source code of this file.

Functions

template<typename PairScalars >
int vectester (const std::string &input_name, const PairScalars &example, const std::string &testname)
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 206 of file kinetics_vec_unit.C.

References antioch_error, and vectester().

207 {
208  // Check command line count.
209  if( argc < 2 )
210  {
211  // TODO: Need more consistent error handling.
212  std::cerr << "Error: Must specify reaction set XML input file." << std::endl;
213  antioch_error();
214  }
215 
216  int returnval = 0;
217 
218  returnval = returnval ||
219  vectester (argv[1], std::valarray<float>(2*ANTIOCH_N_TUPLES), "valarray<float>");
220  returnval = returnval ||
221  vectester (argv[1], std::valarray<double>(2*ANTIOCH_N_TUPLES), "valarray<double>");
222  returnval = returnval ||
223  vectester (argv[1], std::valarray<long double>(2*ANTIOCH_N_TUPLES), "valarray<ld>");
224 #ifdef ANTIOCH_HAVE_EIGEN
225  returnval = returnval ||
226  vectester (argv[1], Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXf");
227  returnval = returnval ||
228  vectester (argv[1], Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXd");
229  returnval = returnval ||
230  vectester (argv[1], Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXld");
231 #endif
232 #ifdef ANTIOCH_HAVE_METAPHYSICL
233  returnval = returnval ||
234  vectester (argv[1], MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float>(0), "NumberArray<float>");
235  returnval = returnval ||
236  vectester (argv[1], MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double>(0), "NumberArray<double>");
237  returnval = returnval ||
238  vectester (argv[1], MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double>(0), "NumberArray<ld>");
239 #endif
240 #ifdef ANTIOCH_HAVE_VEXCL
241  vex::Context ctx_f (vex::Filter::All);
242  if (!ctx_f.empty())
243  returnval = returnval ||
244  vectester (argv[1], vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
245 
246  vex::Context ctx_d (vex::Filter::DoublePrecision);
247  if (!ctx_d.empty())
248  returnval = returnval ||
249  vectester (argv[1], vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
250 #endif
251 
252 #ifdef ANTIOCH_HAVE_GRVY
253  gt.Finalize();
254  gt.Summarize();
255 #endif
256 
257  return returnval;
258 }
#define antioch_error()
int vectester(const std::string &input_name, const PairScalars &example, const std::string &testname)
template<typename PairScalars >
int vectester ( const std::string &  input_name,
const PairScalars &  example,
const std::string &  testname 
)

Definition at line 84 of file kinetics_vec_unit.C.

References Antioch::ChemicalMixture< CoeffType >::chemical_species(), Antioch::CEAThermodynamics< CoeffType >::h_RT_minus_s_R(), Antioch::max(), Antioch::ChemicalMixture< CoeffType >::molar_densities, and Antioch::ChemicalMixture< CoeffType >::R().

Referenced by main().

87 {
88  using std::abs;
89 
90  typedef typename Antioch::value_type<PairScalars>::type Scalar;
91 
92  std::vector<std::string> species_str_list;
93  const unsigned int n_species = 5;
94  species_str_list.reserve(n_species);
95  species_str_list.push_back( "N2" );
96  species_str_list.push_back( "O2" );
97  species_str_list.push_back( "N" );
98  species_str_list.push_back( "O" );
99  species_str_list.push_back( "NO" );
100 
101  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
102  Antioch::ReactionSet<Scalar> reaction_set( chem_mixture );
103  Antioch::CEAThermodynamics<Scalar> thermo( chem_mixture );
104 
105  Antioch::read_reaction_set_data_xml<Scalar>( input_name, true, reaction_set );
106 
107  Antioch::KineticsEvaluator<Scalar,PairScalars> kinetics( reaction_set, example );
108  std::vector<PairScalars> omega_dot(n_species, example);
109 
110  PairScalars P = example;
111 
112  // Mass fractions
113  PairScalars Y_vals = example;
114 
115  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
116  {
117  P[2*tuple ] = 1.0e5;
118  P[2*tuple+1] = 1.2e5;
119 
120  Y_vals[2*tuple ] = 0.2;
121  Y_vals[2*tuple+1] = 0.25;
122  }
123 
124  std::vector<PairScalars> Y(n_species,Y_vals);
125 
126  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
127  Y[4][2*tuple+1] = 0;
128 
129  const unsigned int n_T_samples = 10;
130  const Scalar T0 = 500;
131  const Scalar T_inc = 500;
132 
133  const PairScalars R_mix = chem_mixture.R(Y);
134 
135  std::vector<PairScalars> molar_densities(n_species,example);
136  std::vector<PairScalars> h_RT_minus_s_R(n_species, example);
137 
138  int return_flag = 0;
139 
140  for( unsigned int i = 0; i < n_T_samples; i++ )
141  {
142  PairScalars T = example;
143 
144  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
145  {
146  T[2*tuple ] = T0 + T_inc*static_cast<Scalar>(i);
147  T[2*tuple+1] = T[0]+T_inc/2;
148  }
149 
151 
152 #ifdef ANTIOCH_HAVE_GRVY
153  const std::string testnormal = testname + "-normal";
154  gt.BeginTimer(testnormal);
155 #endif
156 
157  const PairScalars rho = P/(R_mix*T);
158  chem_mixture.molar_densities(rho,Y,molar_densities);
159 
160  typedef typename Antioch::CEAThermodynamics<Scalar>::
161  template Cache<PairScalars> Cache;
162 
163  thermo.h_RT_minus_s_R(Cache(T),h_RT_minus_s_R);
164 
165  kinetics.compute_mass_sources( cond, molar_densities, h_RT_minus_s_R, omega_dot );
166 
167 #ifdef ANTIOCH_HAVE_GRVY
168  gt.EndTimer(testnormal);
169 #endif
170 
171  // Omega dot had better sum to 0.0
172  PairScalars sum = omega_dot[0];
173  for( unsigned int s = 1; s < n_species; s++ )
174  {
175  sum += omega_dot[s];
176  }
177  const Scalar sum_tol = std::numeric_limits<Scalar>::epsilon() * 5e6; // 5e-10;
178  const PairScalars abs_sum = abs(sum);
179  if( Antioch::max(abs_sum) > sum_tol )
180  {
181  return_flag = 1;
182  std::cerr << "Error: omega_dot did not sum to 0.0." << std::endl
183  << std::scientific << std::setprecision(16)
184  << "T = " << T << std::endl
185  << "sum = " << sum << ", sum_tol = " << sum_tol << std::endl;
186  for( unsigned int s = 0; s < n_species; s++ )
187  {
188  std::cerr << std::scientific << std::setprecision(16)
189  << "omega_dot(" << chem_mixture.chemical_species()[s]->species() << ") = "
190  << omega_dot[s] << std::endl;
191  }
192  std::cout << std::endl << std::endl;
193  }
194  }
195 
196 #ifdef ANTIOCH_HAVE_EIGEN
197  {
198  // To do: tests with Eigen instead of std vectors
199  }
200 #endif // ANTIOCH_HAVE_EIGEN
201 
202  return return_flag;
203 }
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
Class to handle computing mass source terms for a given ReactionSet.
Class storing chemical mixture properties.
StateType h_RT_minus_s_R(const Cache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
Definition: cea_thermo.h:420
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