antioch-0.4.0
wilke_transport_vec_unit.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 //
27 // $Id$
28 //
29 //--------------------------------------------------------------------------
30 //--------------------------------------------------------------------------
31 
32 #include "antioch_config.h"
33 
34 #ifdef ANTIOCH_HAVE_EIGEN
35 #include "Eigen/Dense"
36 #endif
37 
38 #ifdef ANTIOCH_HAVE_METAPHYSICL
39 #include "metaphysicl/numberarray.h"
40 #endif
41 
42 #ifdef ANTIOCH_HAVE_VEXCL
43 #include "vexcl/vexcl.hpp"
44 #endif
45 
46 // Antioch
47 // Declare metaprogramming overloads before they're used
53 
57 
59 #include "antioch/cea_curve_fit.h"
60 #include "antioch/nasa_mixture.h"
61 #include "antioch/nasa_evaluator.h"
63 
69 
70 #include "antioch/wilke_mixture.h"
76 
77 #include "antioch/eigen_utils.h"
79 #include "antioch/valarray_utils.h"
80 #include "antioch/vector_utils.h"
81 #include "antioch/vexcl_utils.h"
82 
83 #ifdef ANTIOCH_HAVE_GRVY
84 #include "grvy.h"
85 
86 GRVY::GRVY_Timer_Class gt;
87 #endif
88 
89 // C++
90 #include <iostream>
91 #include <cmath>
92 
93 template <typename Scalar, typename PairScalars>
94 int test_val( const PairScalars val, const PairScalars val_exact,
95  const Scalar tol, const std::string& val_name )
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 }
116 
117 template <typename PairScalars>
118 int tester(const PairScalars& example, const std::string& testname)
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 }
259 
260 int main()
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 }
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
void compute_mu_mu_sqrt(const VectorStateType &mu, typename rebind< VectorStateType, VectorStateType >::type &mu_mu_sqrt) const
Helper function to reduce code duplication.
Container class for species viscosities.
value_type< VectorStateType >::type compute_phi(typename rebind< VectorStateType, VectorStateType >::type &mu_mu_sqrt, const VectorStateType &chi, const unsigned int s) const
Helper function to reduce code duplication.
int tester(const PairScalars &example, const std::string &testname)
Compute transport properties using ``mixture averaged" model.
CoeffType M(const unsigned int s) const
Molecular weight (molar mass) for species s in kg/mol.
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:47 for antioch-0.4.0 by  doxygen 1.8.8