antioch-0.4.0
wilke_transport_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 // C++
33 #include <iostream>
34 #include <cmath>
35 
36 // Antioch
37 #include "antioch_config.h"
39 
43 #include "antioch/cea_curve_fit.h"
44 #include "antioch/nasa_mixture.h"
45 #include "antioch/nasa_evaluator.h"
47 
54 
55 #ifdef ANTIOCH_HAVE_GSL
56 
60 #include "antioch/gsl_spliner.h"
62 
63 #endif
64 //
65 #include "antioch/wilke_mixture.h" // backward compatiblity
66 #include "antioch/wilke_evaluator.h" // backward compatiblity
69 
73 
74 #include "antioch/vector_utils.h"
75 
76 template <typename Scalar>
77 int test_val( const Scalar val, const Scalar val_exact, const Scalar tol, const std::string& val_name )
78 {
79  using std::abs;
80 
81  int return_flag = 0;
82 
83  const Scalar rel_error = abs( (val - val_exact)/val_exact);
84 
85  if( rel_error > tol )
86  {
87  std::cerr << std::setprecision(20) << std::scientific
88  << "Error: Mismatch in " << val_name << std::endl
89  << val_name << " = " << val << std::endl
90  << val_name+"_exact = " << val_exact << std::endl
91  << "rel_error = " << rel_error << std::endl
92  << "tol = " << tol << std::endl;
93  return_flag = 1;
94  }
95 
96  return return_flag;
97 }
98 
99 template <typename Scalar>
100 int tester()
101 {
102  using std::pow;
103 
104  std::vector<std::string> species_str_list;
105  const unsigned int n_species = 5;
106  species_str_list.reserve(n_species);
107  species_str_list.push_back( "N2" );
108  species_str_list.push_back( "O2" );
109  species_str_list.push_back( "N" );
110  species_str_list.push_back( "O" );
111  species_str_list.push_back( "NO" );
112 
113 // mixture and thermo for conduction
114  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
115 
116 // micro thermo
117  Antioch::StatMechThermodynamics<Scalar> thermo_stat( chem_mixture );
118 
119  typedef Antioch::StatMechThermodynamics<Scalar> MicroThermo;
120 
121 // macro thermo for cp (diffusion)
125 
126  Antioch::TransportMixture<Scalar> tran_mixture( chem_mixture );
127 
128 //
130  k( tran_mixture );
131  Antioch::build_eucken_thermal_conductivity<MicroThermo,Scalar>(k,thermo_stat);
132 
133 
136 
137 
138 // pure species set, all internally set
139 #ifdef ANTIOCH_HAVE_GSL
141  ps_mu(tran_mixture);
142  Antioch::build_kinetics_theory_viscosity<Scalar,Antioch::GSLSpliner>(ps_mu);
143 
145  bimol_D( tran_mixture );
146 
147 #endif
148 
150  ps_k( tran_mixture );
151 
152  Antioch::build_kinetics_theory_thermal_conductivity<MicroThermo,Scalar>(ps_k,thermo_stat);
153 
154 //Eucken is internally set
155 
157  D( tran_mixture );
158 
159  const Scalar Le = 1.4;
160  Antioch::build_constant_lewis_diffusivity<Scalar>( D, Le);
161 
162 // non kinetics theory
163  Antioch::MixtureAveragedTransportMixture<Scalar> wilke_mixture( tran_mixture );
164 
168  Scalar>
169  wilke( wilke_mixture, D, mu, k );
170 
171 
172 // kinetics theory full
173 #ifdef ANTIOCH_HAVE_GSL
174 
176  Antioch::KineticsTheoryViscosity<Scalar,Antioch::GSLSpliner>,
178  Scalar>
179  wilke_ps_evaluator(wilke_mixture,bimol_D,ps_mu,ps_k);
180 
181 #endif
182 
183  Antioch::WilkeMixture<Scalar> wilke_mix_dep( chem_mixture );
184 
185  Antioch::EuckenThermalConductivity<MicroThermo> k_eucken(thermo_stat);
186 
188  Antioch::EuckenThermalConductivity<MicroThermo>,
189  Scalar> wilke_eval_dep( wilke_mix_dep, mu, k_eucken );
190 
191  int return_flag = 0;
192 
193  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 5;
194 
195  // First check phi calculation
196  // phi_s = sum_r (chi_r*(1+sqrt(mu_s/mu_r)*(Mr/Ms)^(1/4))^2)/sqrt(8*(1+Ms/Mr))
197  {
198  std::vector<Scalar> mu( 5 );
199  mu[0] = 0.1L;
200  mu[1] = 0.2L;
201  mu[2] = 0.3L;
202  mu[3] = 0.15L;
203  mu[4] = 0.25L;
204 
205  std::vector<Scalar> chi( 5 );
206  chi[0] = 0.1L;
207  chi[1] = 0.2L;
208  chi[2] = 0.3L;
209  chi[3] = 0.15L;
210  chi[4] = 0.25L;
211 
212  Scalar phi_N_exact = 0.0L;
213  unsigned int N_index = 2;
214  Scalar M_N = chem_mixture.M(N_index);
215 
216  for( unsigned int r = 0; r < 5; r++ )
217  {
218  Scalar M_r = chem_mixture.M(r);
219  Scalar dummy = 1.0L + std::sqrt(mu[N_index]/mu[r])*pow( M_r/M_N, Scalar(0.25L) );
220  phi_N_exact += chi[r]*dummy*dummy/std::sqrt(8.0L*( 1.0L + M_N/M_r ) );
221  }
222 
223  Scalar phi_N;
224  std::vector<std::vector<Scalar> > mu_mu_sqrt(mu.size());
225  Antioch::init_constant(mu_mu_sqrt,mu);
226  Antioch::set_zero(mu_mu_sqrt);
227 
228  wilke.compute_mu_mu_sqrt( mu, mu_mu_sqrt);
229  phi_N = wilke.compute_phi( mu_mu_sqrt, chi, N_index );
230 
231  return_flag = test_val( phi_N, phi_N_exact, tol, std::string("phi") );
232  }
233 
234  const Scalar P = 1e5;
235  std::vector<Scalar> mass_fractions( 5, 0.2L);
236  const Scalar T = 1000.0L;
237  const Antioch::TempCache<Scalar> T_cache(T);
238 
239  const Scalar R_mix = chem_mixture.R(mass_fractions); // get R_tot in J.kg-1.K-1
240  const Scalar rho = P/(R_mix*T); // kg.m-3
241  const Scalar cp = thermo_mix.cp( T_cache, mass_fractions );
242 
243  const Scalar wilke_mu_long_double = 4.51233094078102111066e-05L;
244  const Scalar wilke_k_long_double = 8.01027375195322618301e-02L;
245 
246  Scalar wilke_mu = wilke.mu(T, mass_fractions );
247  Scalar wilke_k = wilke.k(T, mass_fractions );
248 
249  return_flag = test_val( wilke_mu, wilke_mu_long_double, tol, "wilke mixture viscosity") || return_flag;
250  return_flag = test_val( wilke_k, wilke_k_long_double, tol, "wilke mixture thermal conduction") || return_flag;
251 
252  std::vector<Scalar> lewis_D(5,0);
253 
254  wilke.mu_and_k(T,mass_fractions,wilke_mu,wilke_k);
255 
256  return_flag = test_val( wilke_mu, wilke_mu_long_double, tol, "wilke mixture viscosity") || return_flag;
257  return_flag = test_val( wilke_k, wilke_k_long_double, tol, "wilke mixture thermal conduction") || return_flag;
258 
259  wilke.mu_and_k_and_D( T, rho, cp, mass_fractions, wilke_mu, wilke_k, lewis_D );
260 
261  Scalar D_lewis_exact = wilke_k/(rho*cp*Le);
262 
263  for(unsigned int s = 0; s < lewis_D.size(); s++)
264  return_flag = test_val( lewis_D[s], D_lewis_exact, tol, "constant Lewis diffusion for species " + species_str_list[s]) || return_flag;
265 
266 #if ANTIOCH_HAVE_GSL
267 /* \todo better the test
268  Alright we need something to test, so here's the sorry version.
269  It is the long double values, we're thus just verifying that
270  future development won't change them.
271 
272  the smart test would be to make up molecules where the
273  reduced dipole moment fall into a node (easy part, 0 works)
274  and the reduced temperature falls also on a node (less easy).
275  Then we will have a theoretical independant value.
276 */
277 
278  const Scalar mu_kt_long_double = 4.49877527305932602332e-05L;
279  const Scalar k_kt_long_double = 8.22050332419571328635e-02L;
280 
281  std::vector<Scalar> D_kt_long_double(5,0);
282  D_kt_long_double[0] = 1.95418749838889089562e-04L;
283  D_kt_long_double[1] = 1.92376915629762328034e-04L;
284  D_kt_long_double[2] = 2.98006144849143296987e-04L;
285  D_kt_long_double[3] = 3.08179434829991685679e-04L;
286  D_kt_long_double[4] = 1.90508644119203653519e-04L;
287  Scalar mu_kt, k_kt;
288  std::vector<Scalar> D_kt(5,0);
289  wilke_ps_evaluator.mu_and_k_and_D( T, rho, cp, mass_fractions, mu_kt, k_kt, D_kt );
290 
291 
292  return_flag = test_val( mu_kt, mu_kt_long_double, tol, "kinetics theory viscosity") || return_flag;
293  return_flag = test_val( k_kt, k_kt_long_double, tol, "kinetics theory thermal conduction") || return_flag;
294  for(unsigned int s = 0; s < D_kt.size(); s++)
295  return_flag = test_val( D_kt[s], D_kt_long_double[s], tol, "kinetics theory diffusion for species " + species_str_list[s]) || return_flag;
296 
297  std::vector<Scalar> D_kt_2(5,0);
298  wilke_ps_evaluator.D(rho, T, mass_fractions, D_kt_2 );
299 
300  for(unsigned int s = 0; s < D_kt.size(); s++)
301  return_flag = test_val( D_kt_2[s], D_kt_long_double[s], tol, "kinetics theory diffusion for species " + species_str_list[s]) || return_flag;
302 
303  // Mass flux, mass fraction test
304  {
306  Antioch::KineticsTheoryViscosity<Scalar,Antioch::GSLSpliner>,
307  Antioch::KineticsTheoryThermalConductivity<MicroThermo,Scalar>,
308  Scalar>::DiffusivityType
310  Antioch::KineticsTheoryViscosity<Scalar,Antioch::GSLSpliner>,
311  Antioch::KineticsTheoryThermalConductivity<MicroThermo,Scalar>,
312  Scalar>::MASS_FLUX_MASS_FRACTION;
313 
314  std::vector<Scalar> D_kt_mass_mass_long_double(5);
315  D_kt_mass_mass_long_double[0] = 2.049224418207810845348e-04L;
316  D_kt_mass_mass_long_double[1] = 2.065920312318615510015e-04L;
317  D_kt_mass_mass_long_double[2] = 2.550809908204135170620e-04L;
318  D_kt_mass_mass_long_double[3] = 2.790464132548291530901e-04L;
319  D_kt_mass_mass_long_double[4] = 2.024029424511201457822e-04L;
320 
321  std::vector<Scalar> D_kt_mass_mass(5,0);
322  wilke_ps_evaluator.D(rho, T, mass_fractions, D_kt_mass_mass, diff_type );
323 
324  for(unsigned int s = 0; s < D_kt.size(); s++)
325  return_flag = test_val( D_kt_mass_mass[s], D_kt_mass_mass_long_double[s], tol, "kinetics theory diffusion (mass flux, mass fraction) for species " + species_str_list[s]) || return_flag;
326 
327  }
328 
329  // Mole flux, mole fraction test
330  {
332  Antioch::KineticsTheoryViscosity<Scalar,Antioch::GSLSpliner>,
333  Antioch::KineticsTheoryThermalConductivity<MicroThermo,Scalar>,
334  Scalar>::DiffusivityType
336  Antioch::KineticsTheoryViscosity<Scalar,Antioch::GSLSpliner>,
337  Antioch::KineticsTheoryThermalConductivity<MicroThermo,Scalar>,
338  Scalar>::MOLE_FLUX_MOLE_FRACTION;
339 
340  std::vector<Scalar> D_kt_mole_mole_long_double(5);
341  D_kt_mole_mole_long_double[0] = 2.070373009368896292617e-04L;
342  D_kt_mole_mole_long_double[1] = 2.083783534307470249142e-04L;
343  D_kt_mole_mole_long_double[2] = 2.589403037715613871414e-04L;
344  D_kt_mole_mole_long_double[3] = 2.824017881144487186270e-04L;
345  D_kt_mole_mole_long_double[4] = 2.042449798230576410557e-04L;
346 
347  std::vector<Scalar> D_kt_mole_mole(5,0);
348  wilke_ps_evaluator.D(rho, T, mass_fractions, D_kt_mole_mole, diff_type );
349 
350  for(unsigned int s = 0; s < D_kt.size(); s++)
351  return_flag = test_val( D_kt_mole_mole[s], D_kt_mole_mole_long_double[s], tol, "kinetics theory diffusion (mass flux, mass fraction) for species " + species_str_list[s]) || return_flag;
352 
353  }
354 
355 
356 
357 #endif
358 
359  return return_flag;
360 }
361 
362 int main()
363 {
364  return ( tester<double>() ||
365  tester<long double>() ||
366  tester<float>()
367  );
368 }
void compute_mu_mu_sqrt(const VectorStateType &mu, typename rebind< VectorStateType, VectorStateType >::type &mu_mu_sqrt) const
Helper function to reduce code duplication.
Deprecated. Use MixtureAveragedTransportEvaluator instead.
Container class for species viscosities.
CoeffType R(const unsigned int s) const
Gas constant for species s in [J/kg-K].
value_type< VectorStateType >::type k(const StateType &T, const VectorStateType &mass_fractions) const
Mixture conducivity, in [W/m-K].
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.
Compute transport properties using ``mixture averaged" model.
CoeffType M(const unsigned int s) const
Molecular weight (molar mass) for species s in kg/mol.
int main()
void mu_and_k_and_D(const StateType &T, const StateType &rho, const StateType &cp, const VectorStateType &mass_fractions, StateType &mu, StateType &k, VectorStateType &D_vec, DiffusivityType diff_type=DiffusivityType::MASS_FLUX_MOLE_FRACTION) const
Mixture viscosity, thermal conductivity, and diffusivities in [Pa-s], [W/m-K], [m^2/s] respectively...
Container class for species binary diffusion models.
Scalar cp(Scalar T, Scalar a0, Scalar a1, Scalar a2, Scalar a3, Scalar a4, Scalar a5, Scalar a6)
Conductivity based on kinetic theory of mixtures approximations.
int test_val(const Scalar val, const Scalar val_exact, const Scalar tol, const std::string &val_name)
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.
value_type< VectorStateType >::type mu(const StateType &T, const VectorStateType &mass_fractions) const
Mixture viscosity, in [Pa-s].
Class storing chemical mixture properties.
Definition: ascii_parser.h:55
void D(const StateType &rho, const StateType &T, const VectorStateType &mass_fractions, VectorStateType &D_vec, DiffusivityType diff_type=DiffusivityType::MASS_FLUX_MOLE_FRACTION) const
Mixture diffusivities for each species, in [m^2/s].
static const std::string & thermo_data()
static const std::string & blottner_data()
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
int tester()
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)
StateType cp(const TempCache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
Mixture object for MixtureAveragedTransport model.
void mu_and_k(const StateType &T, const VectorStateType &mass_fractions, StateType &mu, StateType &k) const
Mixture viscosity and thermal conductivity, in [Pa-s], [W/m-K] respectively.

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