antioch-0.4.0
mixture_averaged_transport_evaluator.h
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 #ifndef ANTIOCH_WILKE_TRANSPORT_EVALUATOR_H
33 #define ANTIOCH_WILKE_TRANSPORT_EVALUATOR_H
34 
35 // Antioch
39 #include "antioch/cmath_shims.h"
45 
46 namespace Antioch
47 {
49 
65  template<class Diffusion, class Viscosity, class ThermalConductivity,class CoeffType=double>
67  {
68  public:
69 
74 
76 
89 
91 
94  template <typename StateType, typename VectorStateType>
95  void D( const StateType & rho,
96  const StateType& T,
97  const VectorStateType& mass_fractions,
98  VectorStateType & D_vec,
99  DiffusivityType diff_type = DiffusivityType::MASS_FLUX_MOLE_FRACTION ) const;
100 
102  template <typename StateType, typename VectorStateType>
104  mu( const StateType& T, const VectorStateType& mass_fractions ) const;
105 
107 
109  template <typename StateType, typename VectorStateType>
111  k( const StateType & T, const VectorStateType& mass_fractions ) const;
112 
114 
116  template <typename StateType, typename VectorStateType>
117  void mu_and_k( const StateType& T, const VectorStateType& mass_fractions,
118  StateType& mu, StateType& k ) const;
119 
121 
122  template <typename StateType, typename VectorStateType>
123  void mu_and_k_and_D( const StateType& T, const StateType& rho, const StateType& cp,
124  const VectorStateType& mass_fractions,
125  StateType& mu, StateType& k, VectorStateType& D_vec,
126  DiffusivityType diff_type = DiffusivityType::MASS_FLUX_MOLE_FRACTION ) const;
127 
129 
133  template <typename StateType, typename VectorStateType>
134  void compute_mu_chi( const StateType& T,
135  const VectorStateType& mass_fractions,
136  VectorStateType& mu,
137  VectorStateType& chi ) const;
138 
140 
143  template <typename VectorStateType>
146  const VectorStateType& chi,
147  const unsigned int s ) const;
148 
150 
153  template <typename VectorStateType>
154  void compute_mu_mu_sqrt( const VectorStateType & mu,
155  typename rebind<VectorStateType,VectorStateType>::type & mu_mu_sqrt) const;
156 
157  protected:
158 
160 
162  template <typename VectorStateType, typename MatrixStateType>
164  const VectorStateType & mass_fractions,
165  const MatrixStateType & D_mat,
166  DiffusivityType diff_type,
167  VectorStateType & D_vec ) const;
168 
170 
172 
174 
176 
177  private:
178 
180 
181  };
182 
183  template<class Diff, class Visc, class TherCond, class CoeffType>
185  const MixtureDiffusion<Diff,CoeffType>& diffusion,
186  const MixtureViscosity<Visc,CoeffType>& viscosity,
187  const MixtureConductivity<TherCond,CoeffType>& conductivity )
188  : _mixture(mixture),
189  _diffusion(diffusion),
190  _viscosity(viscosity),
191  _conductivity(conductivity)
192  {
193  return;
194  }
195 
196  template<class Diff, class Visc, class TherCond, class CoeffType>
197  template <typename StateType, typename VectorStateType>
199  const StateType& T,
200  const VectorStateType& mass_fractions,
201  VectorStateType & D_vec,
202  DiffusivityType diff_type ) const
203  {
205  "ERROR: This function requires a binary diffusion model to compute D!");
206 
207  typename rebind<VectorStateType,VectorStateType>::type D_mat(D_vec.size());
208  init_constant(D_mat,D_vec);
209 
210  const StateType molar_density = rho / _mixture.chem_mixture().M(mass_fractions); // total molar density
211 
212  _diffusion.compute_binary_diffusion_matrix( T, molar_density, D_mat );
213 
214  this->diffusion_mixing_rule( _mixture.chem_mixture(),
215  mass_fractions,
216  D_mat,
217  diff_type,
218  D_vec );
219  }
220 
221  template<class Diff, class Visc, class TherCond, class CoeffType>
222  template <typename StateType, typename VectorStateType>
223  inline
226  const VectorStateType& mass_fractions ) const
227  {
228  typename value_type<VectorStateType>::type mu_mix = zero_clone(T);
229 
230  VectorStateType mu = zero_clone(mass_fractions);
231  VectorStateType chi = zero_clone(mass_fractions);
232 
233 
234  typename Antioch::rebind<VectorStateType,VectorStateType>::type mu_mu_sqrt(mu.size());
235  Antioch::init_constant(mu_mu_sqrt,mu);
236 
237  this->compute_mu_chi( T, mass_fractions, mu, chi );
238 
239  this->compute_mu_mu_sqrt( mu, mu_mu_sqrt);
240 
241  for( unsigned int s = 0; s < _mixture.chem_mixture().n_species(); s++ )
242  {
243  typename value_type<VectorStateType>::type phi_s = this->compute_phi( mu_mu_sqrt, chi, s );
244 
245  mu_mix += mu[s]*chi[s]/phi_s;
246  }
247 
248  return mu_mix;
249  }
250 
251  template<class Diff, class Visc, class TherCond, class CoeffType>
252  template <typename StateType, typename VectorStateType>
255  const VectorStateType& mass_fractions ) const
256  {
258  "This function requires a conductivity model independent of diffusion!");
259 
260  antioch_assert_equal_to(mass_fractions.size(), _mixture.chem_mixture().n_species());
261 
262  typename value_type<VectorStateType>::type k_mix = zero_clone(T);
263 
264  VectorStateType mu = zero_clone(mass_fractions);
265  VectorStateType chi = zero_clone(mass_fractions);
266 
267  typename Antioch::rebind<VectorStateType,VectorStateType>::type mu_mu_sqrt(mu.size());
268  Antioch::init_constant(mu_mu_sqrt,mu);
269 
270  this->compute_mu_chi( T, mass_fractions, mu, chi );
271 
272  this->compute_mu_mu_sqrt( mu, mu_mu_sqrt);
273 
274  for( unsigned int s = 0; s < _mixture.chem_mixture().n_species(); s++ )
275  {
276  typename value_type<VectorStateType>::type phi_s = this->compute_phi( mu_mu_sqrt, chi, s );
277 
279 
280  k_s = _conductivity.conductivity_without_diffusion( s,
281  T,
282  mu[s] );
283 
284  k_mix += k_s*chi[s]/phi_s;
285  }
286 
287  return k_mix;
288  }
289 
290  template<class Diff, class Visc, class TherCond, class CoeffType>
291  template <typename StateType, typename VectorStateType>
293  const VectorStateType& mass_fractions,
294  StateType& mu_mix,
295  StateType& k_mix ) const
296  {
298  "This function requires a conductivity model independent of diffusion!");
299 
300  mu_mix = zero_clone(T);
301  k_mix = zero_clone(T);
302 
303  VectorStateType mu = zero_clone(mass_fractions);
304  VectorStateType chi = zero_clone(mass_fractions);
305 
306  typename Antioch::rebind<VectorStateType,VectorStateType>::type mu_mu_sqrt(mu.size());
307  Antioch::init_constant(mu_mu_sqrt,mu);
308 
309  this->compute_mu_chi( T, mass_fractions, mu, chi );
310 
311  this->compute_mu_mu_sqrt( mu, mu_mu_sqrt);
312 
313  for( unsigned int s = 0; s < _mixture.transport_mixture().n_species(); s++ )
314  {
315  StateType phi_s = this->compute_phi( mu_mu_sqrt, chi, s );
316 
317  StateType k_s = zero_clone(T);
318 
319  k_s = _conductivity.conductivity_without_diffusion( s, T, mu[s] );
320 
321  mu_mix += mu[s]*chi[s]/phi_s;
322  k_mix += k_s*chi[s]/phi_s;
323  }
324 
325  return;
326  }
327 
328  template<class Diff, class Visc, class TherCond, class CoeffType>
329  template <typename StateType, typename VectorStateType>
331  const StateType & rho,
332  const StateType& cp,
333  const VectorStateType& mass_fractions,
334  StateType& mu_mix,
335  StateType& k_mix,
336  VectorStateType & D_vec,
337  DiffusivityType diff_type ) const
338  {
343  "Incompatible thermal conductivity and diffusion models!" );
344 
345  mu_mix = zero_clone(T);
346  k_mix = zero_clone(T);
347  D_vec = zero_clone(mass_fractions);
348 
349  VectorStateType mu = zero_clone(mass_fractions);
350  VectorStateType k = zero_clone(mass_fractions);
351  VectorStateType chi = zero_clone(mass_fractions);
352 
353  typedef typename Antioch::rebind<VectorStateType,VectorStateType>::type MatrixStateType;
354 
355  MatrixStateType mu_mu_sqrt(mu.size());
356  Antioch::init_constant(mu_mu_sqrt,mu);
357 
358  MatrixStateType D_mat(mass_fractions.size());
359  init_constant(D_mat,D_vec);
360 
361 
362  this->compute_mu_chi( T, mass_fractions, mu, chi );
363 
364  this->compute_mu_mu_sqrt( mu, mu_mu_sqrt);
365 
366  const StateType molar_density = rho / _mixture.chem_mixture().M(mass_fractions); // total molar density
367 
368  // If we're using a binary diffusion model, compute D_mat, D_vec now
370  {
371  _diffusion.compute_binary_diffusion_matrix(T, molar_density, D_mat);
372 
373  this->diffusion_mixing_rule<VectorStateType,MatrixStateType>( _mixture.chem_mixture(),
374  mass_fractions,
375  D_mat,
376  diff_type,
377  D_vec );
378  }
379 
380  for( unsigned int s = 0; s < _mixture.transport_mixture().n_species(); s++ )
381  {
382  StateType phi_s = this->compute_phi( mu_mu_sqrt, chi, s );
383 
385  {
386  k[s] = _conductivity.conductivity_with_diffusion( s,
387  T,
388  molar_density*_mixture.chem_mixture().M(s),
389  //rho*mass_fractions[s], see #146
390  mu[s],
391  D_mat[s][s] );
392 
393  }
394  else
395  {
396  k[s] = _conductivity.conductivity_without_diffusion( s,
397  T,
398  mu[s] );
399  }
400 
401  k_mix += k[s]*chi[s]/phi_s;
402  mu_mix += mu[s]*chi[s]/phi_s;
403 
404  }
405 
406 
407 
409  {
410  for( unsigned int s = 0; s < _mixture.transport_mixture().n_species(); s++ )
411  {
412  _diffusion.compute_species_diffusivity(s,
413  rho,
414  cp,
415  k_mix,
416  D_vec[s]);
417  }
418  }
419 
420  return;
421  }
422 
423  template<class Diff, class Visc, class TherCond, class CoeffType>
424  template <typename StateType, typename VectorStateType>
426  const VectorStateType& mass_fractions,
427  VectorStateType& mu,
428  VectorStateType& chi ) const
429  {
430  const typename value_type<VectorStateType>::type M = _mixture.chem_mixture().M(mass_fractions);
431 
432  // Precompute needed quantities
433  // chi_s = w_s*M/M_s
434  for( unsigned int s = 0; s < _mixture.chem_mixture().n_species(); s++ )
435  {
436  mu[s] = _viscosity(s,T);
437  chi[s] = mass_fractions[s]*M/_mixture.chem_mixture().M(s);
438  }
439 
440  return;
441  }
442 
443  template<class Diff, class Visc, class TherCond, class CoeffType>
444  template <typename VectorStateType>
445  typename
448  const VectorStateType& chi,
449  const unsigned int s ) const
450  {
451  using std::sqrt;
452 
453  typedef typename value_type<VectorStateType>::type StateType;
454 
455  /* We initialize to the first iterate and loop starting from 1
456  since some StateTypes have a hard time initializing from
457  a constant. */
458  // phi_s = sum_r (chi_r*(1+sqrt(mu_s/mu_r)*(Mr/Ms)^(1/4))^2)/sqrt(8*(1+Ms/Mr))
459  const StateType dummy = 1 + mu_mu_sqrt[s][0]*_mixture.Mr_Ms_to_the_one_fourth(0,s);
460  StateType phi_s = chi[0]*dummy*dummy/_mixture.denominator(0,s);
461 
462  for(unsigned int r = 1; r < _mixture.chem_mixture().n_species(); r++ )
463  {
464  const StateType numerator = 1 + mu_mu_sqrt[s][r]*_mixture.Mr_Ms_to_the_one_fourth(r,s);
465  phi_s += chi[r]*numerator*numerator/_mixture.denominator(r,s);
466  }
467 
468  return phi_s;
469  }
470 
471  template<class Diff, class Visc, class TherCond, class CoeffType>
472  template <typename VectorStateType>
473  inline
475  typename Antioch::rebind<VectorStateType,VectorStateType>::type & mu_mu_sqrt) const
476 
477  {
478  antioch_assert_equal_to(mu.size(),mu_mu_sqrt.size()); // indeed square matrix
479  antioch_assert_greater(mu.size(),0); // not empty
480 #ifndef NDEBUG
481  for(unsigned int i = 0; i < mu.size(); i++)
482  {
483  antioch_assert_equal_to(mu.size(),mu_mu_sqrt[i].size());
484  }
485 #endif
486 
488  for(unsigned int s = 0; s < mu.size(); s++)
489  {
490  mu_mu_sqrt[s][s] = Antioch::constant_clone(mu[s],1);
491  }
493  for(unsigned int s = 1; s < mu.size(); s++)
494  {
495  mu_mu_sqrt[0][s] = ant_sqrt(mu[0]/mu[s]);
496  mu_mu_sqrt[s][0] = Antioch::constant_clone(mu[0],1)/mu_mu_sqrt[0][s];
497  }
499  for(unsigned int s = 1; s < mu.size(); s++)
500  {
501  for(unsigned int l = 1; l < mu.size(); l++)
502  {
503  if(l == s)continue;
504  mu_mu_sqrt[s][l] = mu_mu_sqrt[s][0] * mu_mu_sqrt[0][l];
505  }
506  }
507  }
508 
509  template<class Diff, class Visc, class TherCond, class CoeffType>
510  template <typename VectorStateType, typename MatrixStateType>
512  const VectorStateType & mass_fractions,
513  const MatrixStateType & D_mat,
514  DiffusivityType diff_type,
515  VectorStateType & D_vec ) const
516  {
517  antioch_assert_equal_to(D_vec.size(),mixture.n_species());
518  antioch_assert_equal_to(D_vec.size(),mass_fractions.size());
519  antioch_assert_equal_to(D_vec.size(),D_mat.size());
520 
521 #ifndef NDEBUG
522  // D_Mat should be square
523  for(unsigned int s = 0; s < D_vec.size(); s++)
524  antioch_assert_equal_to(D_vec.size(),D_mat[s].size());
525 #endif
526 
527  switch(diff_type)
528  {
529  case(MASS_FLUX_MOLE_FRACTION):
530  {
531  VectorStateType molar_fractions = zero_clone(mass_fractions);
532 
533  mixture.X(mixture.M(mass_fractions),mass_fractions,molar_fractions);
534 
535  // D_s = (1 - Y_s) / (sum_{j \neq s} x_j/D_{s,j})
536  for(unsigned int s = 0; s < D_vec.size(); s++)
537  {
538  D_vec[s] = constant_clone(mass_fractions[s],1) - mass_fractions[s];
539 
540  typename value_type<VectorStateType>::type denom = zero_clone(mass_fractions[0]);
541 
542  for(unsigned int j = 0; j < D_vec.size(); j++)
543  {
544  if(j == s)
545  continue;
546 
547  denom += molar_fractions[j] / D_mat[s][j];
548  }
549 
550  D_vec[s] /= denom;
551  }
552  break;
553  }
554  case(MOLE_FLUX_MOLE_FRACTION):
555  {
556  VectorStateType molar_fractions = zero_clone(mass_fractions);
557 
558  mixture.X(mixture.M(mass_fractions),mass_fractions,molar_fractions);
559 
560  // D_s = (1 - X_s) / (sum_{j \neq s} X_j/D_{s,j})
561  for(unsigned int s = 0; s < D_vec.size(); s++)
562  {
563  // 1 - X_s
564  D_vec[s] = constant_clone(mass_fractions[s],1) - molar_fractions[s];
565 
566  typename value_type<VectorStateType>::type denom = zero_clone(mass_fractions[0]);
567 
568  for(unsigned int j = 0; j < D_vec.size(); j++)
569  {
570  if(j == s)
571  continue;
572 
573  denom += molar_fractions[j] / D_mat[s][j];
574  }
575 
576  D_vec[s] /= denom;
577  }
578  break;
579  }
580  case(MASS_FLUX_MASS_FRACTION):
581  {
582  VectorStateType molar_fractions = zero_clone(mass_fractions);
583 
584  mixture.X(mixture.M(mass_fractions),mass_fractions,molar_fractions);
585 
586  typename value_type<VectorStateType>::type one = constant_clone(mass_fractions[0],1);
587 
588  // term1 term2
589  // 1/D_s = (sum_{j\ne s} X_j/D_{s,j}) + X_s/(1-Y_s)\sum_{j\ne s} Y_j/D_{s,j}
590  for(unsigned int s = 0; s < D_vec.size(); s++)
591  {
592  typename value_type<VectorStateType>::type term1 = zero_clone(mass_fractions[0]);
593  typename value_type<VectorStateType>::type term2 = zero_clone(mass_fractions[0]);
594 
595  for(unsigned int j = 0; j < D_vec.size(); j++)
596  {
597  if(j == s)
598  continue;
599 
600  term1 += molar_fractions[j]/D_mat[s][j];
601 
602  term2 += mass_fractions[j]/D_mat[s][j];
603  }
604 
605  term2 *= molar_fractions[s]/(one - mass_fractions[s]);
606 
607  D_vec[s] = one/(term1+term2);
608  }
609  break;
610  }
611  default:
612  {
613  antioch_error_msg("ERROR: Invalid DiffusivityType in MixtureAveragedTransportEvaluator::diffusion_mixing_rule");
614  }
615  } // switch(diff_type)
616  }
617 
618 } // end namespace Antioch
619 
620 #endif // ANTIOCH_WILKE_TRANSPORT_EVALUATOR_H
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.
#define antioch_assert_equal_to(expr1, expr2)
value_type< VectorStateType >::type k(const StateType &T, const VectorStateType &mass_fractions) const
Mixture conducivity, in [W/m-K].
#define antioch_assert_greater(expr1, expr2)
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.
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)
DiffusivityType
For the mixture averaged diffusion models, there are three typical ways of computing an average diffu...
const MixtureConductivity< ThermalConductivity, CoeffType > & _conductivity
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
value_type< VectorStateType >::type mu(const StateType &T, const VectorStateType &mass_fractions) const
Mixture viscosity, in [Pa-s].
#define antioch_error_msg(errmsg)
void diffusion_mixing_rule(const ChemicalMixture< CoeffType > &mixture, const VectorStateType &mass_fractions, const MatrixStateType &D_mat, DiffusivityType diff_type, VectorStateType &D_vec) const
Compute species diffusion coefficients.
const MixtureViscosity< Viscosity, CoeffType > & _viscosity
unsigned int n_species() const
Returns the number of species in this mixture.
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].
Characteristics of various diffusion models.
#define antioch_static_assert_runtime_fallback(cond, errmsg)
const MixtureAveragedTransportMixture< CoeffType > & _mixture
const MixtureDiffusion< Diffusion, CoeffType > & _diffusion
Class storing chemical mixture properties.
void init_constant(Vector &output, const Scalar &example)
The parameters are reduced parameters.
_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.
void compute_mu_chi(const StateType &T, const VectorStateType &mass_fractions, VectorStateType &mu, VectorStateType &chi) const
Helper function to reduce code duplication.
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:46 for antioch-0.4.0 by  doxygen 1.8.8