antioch-0.4.0
Functions
wilke_transport_vec_unit.C File Reference
#include "antioch_config.h"
#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/chemical_mixture.h"
#include "antioch/transport_mixture.h"
#include "antioch/default_filename.h"
#include "antioch/stat_mech_thermo.h"
#include "antioch/cea_curve_fit.h"
#include "antioch/nasa_mixture.h"
#include "antioch/nasa_evaluator.h"
#include "antioch/nasa_mixture_parsing.h"
#include "antioch/eucken_thermal_conductivity.h"
#include "antioch/blottner_viscosity.h"
#include "antioch/mixture_viscosity.h"
#include "antioch/constant_lewis_diffusivity.h"
#include "antioch/mixture_diffusion.h"
#include "antioch/wilke_mixture.h"
#include "antioch/mixture_averaged_transport_mixture.h"
#include "antioch/mixture_averaged_transport_evaluator.h"
#include "antioch/blottner_parsing.h"
#include "antioch/eucken_thermal_conductivity_building.h"
#include "antioch/constant_lewis_diffusivity_building.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 <iostream>
#include <cmath>

Go to the source code of this file.

Functions

template<typename Scalar , typename PairScalars >
int test_val (const PairScalars val, const PairScalars val_exact, const Scalar tol, const std::string &val_name)
 
template<typename PairScalars >
int tester (const PairScalars &example, const std::string &testname)
 
int main ()
 

Function Documentation

int main ( )

Definition at line 260 of file wilke_transport_vec_unit.C.

References tester().

261 {
262  int returnval = 0;
263 
264  returnval = returnval ||
265  tester (std::valarray<float>(2*ANTIOCH_N_TUPLES), "valarray<float>");
266  returnval = returnval ||
267  tester (std::valarray<double>(2*ANTIOCH_N_TUPLES), "valarray<double>");
268  returnval = returnval ||
269  tester (std::valarray<long double>(2*ANTIOCH_N_TUPLES), "valarray<ld>");
270 #ifdef ANTIOCH_HAVE_EIGEN
271  returnval = returnval ||
272  tester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXf");
273  returnval = returnval ||
274  tester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXd");
275  returnval = returnval ||
276  tester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXld");
277 #endif
278 #ifdef ANTIOCH_HAVE_METAPHYSICL
279  returnval = returnval ||
280  tester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray<float>");
281  returnval = returnval ||
282  tester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray<double>");
283  returnval = returnval ||
284  tester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray<ld>");
285 #endif
286 #ifdef ANTIOCH_HAVE_VEXCL
287  vex::Context ctx_f (vex::Filter::All);
288  if (!ctx_f.empty())
289  returnval = returnval ||
290  tester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
291 
292  vex::Context ctx_d (vex::Filter::DoublePrecision);
293  if (!ctx_d.empty())
294  returnval = returnval ||
295  tester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
296 #endif
297 
298 #ifdef ANTIOCH_HAVE_GRVY
299  gt.Finalize();
300  gt.Summarize();
301 #endif
302 
303  return returnval;
304 }
int tester(const PairScalars &example, const std::string &testname)
template<typename Scalar , typename PairScalars >
int test_val ( const PairScalars  val,
const PairScalars  val_exact,
const Scalar  tol,
const std::string &  val_name 
)

Definition at line 94 of file wilke_transport_vec_unit.C.

References Antioch::max().

Referenced by tester().

96 {
97  using std::abs;
98 
99  int return_flag = 0;
100 
101  const PairScalars rel_error = (val - val_exact)/val_exact;
102  const PairScalars abs_rel_error = abs(rel_error);
103 
104  if( Antioch::max(abs_rel_error) > tol )
105  {
106  std::cerr << "Error: Mismatch in " << val_name << std::endl
107  << val_name << " = " << val << std::endl
108  << val_name+"_exact = " << val_exact << std::endl
109  << "abs_rel_error = " << abs_rel_error << std::endl
110  << "tol = " << tol << std::endl;
111  return_flag = 1;
112  }
113 
114  return return_flag;
115 }
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
template<typename PairScalars >
int tester ( const PairScalars &  example,
const std::string &  testname 
)

Definition at line 118 of file wilke_transport_vec_unit.C.

References Antioch::ASCII, Antioch::DefaultSourceFilename::blottner_data(), Antioch::MixtureAveragedTransportEvaluator< Diffusion, Viscosity, ThermalConductivity, CoeffType >::compute_mu_mu_sqrt(), Antioch::MixtureAveragedTransportEvaluator< Diffusion, Viscosity, ThermalConductivity, CoeffType >::compute_phi(), Antioch::KineticsModel::D, Antioch::init_constant(), Antioch::ChemicalMixture< CoeffType >::M(), std::pow(), Antioch::read_blottner_data_ascii(), Antioch::read_nasa_mixture_data(), Antioch::set_zero(), test_val(), Antioch::DefaultSourceFilename::thermo_data(), and Antioch::zero_clone().

Referenced by main().

119 {
120  using std::pow;
121  using std::sqrt;
122 
123  typedef typename Antioch::value_type<PairScalars>::type Scalar;
124 
125  std::vector<std::string> species_str_list;
126  const unsigned int n_species = 5;
127  species_str_list.reserve(n_species);
128  species_str_list.push_back( "N2" );
129  species_str_list.push_back( "O2" );
130  species_str_list.push_back( "N" );
131  species_str_list.push_back( "O" );
132  species_str_list.push_back( "NO" );
133 
134  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
135 
136  Antioch::StatMechThermodynamics<Scalar> thermo( chem_mixture );
137 
138  typedef Antioch::StatMechThermodynamics< Scalar > MicroThermo;
139 
140 // thermo for cp (diffusion)
144 
145  Antioch::TransportMixture<Scalar> tran_mixture( chem_mixture );
146 
148  k( tran_mixture );
149 
152 
154  D( tran_mixture );
155 
156  Antioch::build_constant_lewis_diffusivity<Scalar>( D, 1.4);
157 
158 
159  Antioch::MixtureAveragedTransportMixture<Scalar> wilke_mixture( tran_mixture );
160 
164  Scalar>
165  wilke( wilke_mixture, D, mu, k );
166 
167  int return_flag = 0;
168 
169  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
170 
171  // First check phi calculation
172  // phi_s = sum_r (chi_r*(1+sqrt(mu_s/mu_r)*(Mr/Ms)^(1/4))^2)/sqrt(8*(1+Ms/Mr))
173  {
174  std::vector<PairScalars> mu(5, example);
175  std::vector<PairScalars> chi(5, example);
176 
177  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
178  {
179  mu[0][2*tuple ] = 0.1L;
180  mu[1][2*tuple ] = 0.2L;
181  mu[2][2*tuple ] = 0.3L;
182  mu[3][2*tuple ] = 0.15L;
183  mu[4][2*tuple ] = 0.25L;
184  mu[0][2*tuple+1] = 0.25L;
185  mu[1][2*tuple+1] = 0.15L;
186  mu[2][2*tuple+1] = 0.3L;
187  mu[3][2*tuple+1] = 0.2L;
188  mu[4][2*tuple+1] = 0.1L;
189 
190  chi[0][2*tuple ] = 0.1L;
191  chi[1][2*tuple ] = 0.2L;
192  chi[2][2*tuple ] = 0.3L;
193  chi[3][2*tuple ] = 0.15L;
194  chi[4][2*tuple ] = 0.25L;
195  chi[0][2*tuple+1] = 0.25L;
196  chi[1][2*tuple+1] = 0.15L;
197  chi[2][2*tuple+1] = 0.3L;
198  chi[3][2*tuple+1] = 0.2L;
199  chi[4][2*tuple+1] = 0.1L;
200  }
201 
202  PairScalars phi_N_exact = Antioch::zero_clone(example);
203  unsigned int N_index = 2;
204  const Scalar M_N = chem_mixture.M(N_index);
205 
206  for( unsigned int r = 0; r < 5; r++ )
207  {
208  Scalar M_r = chem_mixture.M(r);
209  PairScalars dummy = Scalar(1) + sqrt(mu[N_index]/mu[r])*pow( M_r/M_N, Scalar(0.25L) );
210  phi_N_exact += chi[r]*dummy*dummy/sqrt(Scalar(8)*( Scalar(1) + M_N/M_r ) );
211  }
212 
213 #ifdef ANTIOCH_HAVE_GRVY
214  gt.BeginTimer(testname);
215 #endif
216 
217  std::vector<std::vector<PairScalars> > mu_mu_sqrt(mu.size());
218  Antioch::init_constant(mu_mu_sqrt,mu);
219  Antioch::set_zero(mu_mu_sqrt);
220 
221  wilke.compute_mu_mu_sqrt( mu, mu_mu_sqrt);
222  const PairScalars phi_N = wilke.compute_phi( mu_mu_sqrt, chi, N_index );
223 
224 #ifdef ANTIOCH_HAVE_GRVY
225  gt.EndTimer(testname);
226 #endif
227 
228  std::cout << "mu = " << mu << std::endl;
229  std::cout << "chi = " << chi << std::endl;
230  std::cout << "phi_N = " << phi_N << std::endl;
231 
232  return_flag = test_val( phi_N, phi_N_exact, tol, std::string("phi") );
233  }
234 
235 
236  // PairScalars each_mass = example;
237 
238  // each_mass[2*tuple ] = 0.2L;
239  // each_mass[2*tuple+1] = 0.2L;
240 
241  // std::vector<PairScalars> mass_fractions( 5, each_mass);
242 
243  // Currently dummy
244  //const Scalar mu_exact = ;
245 
246  // PairScalars T = example;
247  // T[0] = 1000.0L;
248  // T[1] = 1200.0L;
249 
250  // PairScalars wilke_mu = wilke.mu(T, mass_fractions );
251  // PairScalars wilke_k = wilke.k(T, mass_fractions );
252 
253  int return_flag_temp = 0;
254  //return_flag_temp = test_mu( wilke.mu(T, mass_fractions ), mu_exact, tol );
255  if( return_flag_temp != 0 ) return_flag = 1;
256 
257  return return_flag;
258 }
Container class for species viscosities.
Compute transport properties using ``mixture averaged" model.
Container class for species binary diffusion models.
void read_nasa_mixture_data(NASAThermoMixture< NumericType, CurveType > &thermo, const std::string &filename=DefaultSourceFilename::thermo_data(), ParsingType=ASCII, bool verbose=true)
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
Species conductivity based on Eucken relation.
Class storing chemical mixture properties.
Definition: ascii_parser.h:55
static const std::string & thermo_data()
static const std::string & blottner_data()
int test_val(const PairScalars val, const PairScalars val_exact, const Scalar tol, const std::string &val_name)
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
Container class for species thermal conductivities.
Class storing chemical mixture properties.
void init_constant(Vector &output, const Scalar &example)
void read_blottner_data_ascii(MixtureViscosity< BlottnerViscosity< NumericType >, NumericType > &mu, const std::string &filename)
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
Definition: eigen_utils.h:145
Mixture object for MixtureAveragedTransport model.

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