antioch-0.4.0
mixture_diffusion.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 #ifndef ANTIOCH_MIXTURE_DIFFUSION_H
28 #define ANTIOCH_MIXTURE_DIFFUSION_H
29 
34 
35 namespace Antioch
36 {
37 
39 
54  template<typename Diffusion, class CoeffType>
55  class MixtureDiffusion : public MixtureTransportBase<CoeffType>
56  {
57  public:
58 
60 
61  virtual ~MixtureDiffusion();
62 
64 
67  template<typename StateType, typename MatrixStateType>
68  void compute_binary_diffusion_matrix( const StateType& T,
69  const StateType& molar_density,
70  MatrixStateType& D ) const;
71 
73  template<typename StateType>
74  void compute_species_diffusivity( unsigned int s, const StateType& rho,
75  const StateType& cp, const StateType& k,
76  StateType& D ) const;
77 
79  /*
80  * Methods for building species diffusion models call this.
81  */
82  void add_species_diffusion( unsigned int s, const std::vector<CoeffType>& coeffs );
83 
85 
94  template <typename StateType>
95  void extrapolate_max_temp(const StateType& Tmax);
96 
97  protected:
98 
100 
106  std::vector<SpeciesDiffusionBase<Diffusion,CoeffType>*> _species_diffusivities;
107 
109 
114  std::vector<std::vector<BinaryDiffusionBase<Diffusion,CoeffType>*> > _binary_diffusivities;
115 
116  private:
117 
119 
121  {
123  "This shouldn't happen!" );
124 
125  _species_diffusivities.resize( this->_transport_mixture.n_species(), NULL );
126  }
127 
129 
131  {
133  "This shouldn't happen!" );
134 
135  // Build up binary diffusion species models
136  _binary_diffusivities.resize( this->_transport_mixture.n_species() );
137  for( unsigned int i = 0; i < this->_transport_mixture.n_species(); i++ )
138  {
139  _binary_diffusivities[i].resize( this->_transport_mixture.n_species(), NULL );
140 
141  for (unsigned int j = 0; j < this->_transport_mixture.n_species(); j++)
142  {
143  const TransportSpecies<CoeffType>& s_i = this->_transport_mixture.transport_species(i);
144  const TransportSpecies<CoeffType>& s_j = this->_transport_mixture.transport_species(j);
145 
146  _binary_diffusivities[i][j] = new Diffusion( s_i, s_j );
147  }
148  }
149  }
150 
152 
153  template<typename StateType, typename MatrixStateType>
154  void private_diff_matrix_impl( const StateType& T,
155  const StateType& molar_density,
156  MatrixStateType& D,
158  {
159  for(unsigned int i = 0; i < D.size(); i++)
160  {
161  for(unsigned int j = 0; j < D.size(); j++)
162  {
163  antioch_assert(_binary_diffusivities[i][j]);
164 
165  D[i][j] = (*_binary_diffusivities[i][j])(T,molar_density);
166  }
167  }
168  }
169 
171  template<typename StateType, typename MatrixStateType>
172  void private_diff_matrix_impl( const StateType& /*T*/,
173  const StateType& /*molar_density*/,
174  MatrixStateType& /*D*/,
176  {
177  antioch_error();
178  }
179 
181 
182  template<typename StateType>
183  void private_species_diff_impl( unsigned int s,
184  const StateType& rho,
185  const StateType& cp,
186  const StateType& k,
187  StateType& D,
189  {
190  D = (*_species_diffusivities[s]).D(rho,cp,k);
191  }
192 
194  template<typename StateType>
195  void private_species_diff_impl( unsigned int /*s*/,
196  const StateType& /*rho*/,
197  const StateType& /*cp*/,
198  const StateType& /*k*/,
199  StateType& /*D*/,
201  {
202  antioch_error();
203  }
204 
206 
207  };
208 
209  template<typename Diffusion, class CoeffType>
211  : MixtureTransportBase<CoeffType>(transport_mixture)
212 
213  {
214  // This class currenltly only supports species or binary diffusion models
217  {
220  "Can only instantiate MixtureDiffusion with a species or binary diffusion model!" );
221 
222  std::string error = "ERROR: You're trying to construct an object\n";
223  error += " with an unknown diffusion model!\n";
224  error += " Does your compiler not support static_assert?";
225  antioch_error_msg(error);
226  }
227 
228  // Build tag so we defer to the right initialization function
230  this->private_init_impl( tag );
231 
232  }
233 
234  template<typename Diffusion, class CoeffType>
236  {
237  // Clean up species diffusion models
239  {
240  for( typename std::vector<SpeciesDiffusionBase<Diffusion,CoeffType>*>::iterator it = _species_diffusivities.begin();
241  it != _species_diffusivities.end(); ++it )
242  delete *it;
243  }
244 
245  // Clean up binary diffusion models
247  {
248  for( typename std::vector<std::vector<BinaryDiffusionBase<Diffusion,CoeffType>*> >::iterator it_outer = _binary_diffusivities.begin();
249  it_outer != _binary_diffusivities.end(); ++it_outer )
250  for( typename std::vector<BinaryDiffusionBase<Diffusion,CoeffType>*>::iterator it_inner = it_outer->begin();
251  it_inner != it_outer->end(); ++it_inner )
252  delete *it_inner;
253  }
254  }
255 
256  template<typename Diffusion, class CoeffType>
257  template<typename StateType, typename MatrixStateType>
258  inline
260  const StateType& molar_density,
261  MatrixStateType& D ) const
262  {
263  const unsigned int n_cols = D.size();
264  antioch_assert_greater(n_cols,0);
265 
266  // Make sure it's a square matrix
267 #ifndef NDEBUG
268  for( unsigned int r = 0; r < n_cols; r++ )
269  antioch_assert_equal_to(D[r].size(),n_cols);
270 #endif
271 
272  // Build tag so we defer to the right binary diffusion matrix function
274  this->private_diff_matrix_impl(T,molar_density,D,tag);
275  }
276 
277  template<typename Diffusion, class CoeffType>
278  template<typename StateType>
279  inline
281  const StateType& rho,
282  const StateType& cp,
283  const StateType& k,
284  StateType& D ) const
285  {
286  antioch_assert_less( s, _species_diffusivities.size());
287  antioch_assert(_species_diffusivities[s]);
288 
289  // Build tag so we defer to the right species diffusivity function
291  this->private_species_diff_impl(s,rho,cp,k,D,tag);
292  }
293 
294  template<typename Diffusion, class CoeffType>
295  template<typename StateType>
296  inline
298  {
300  "Invalid to extrapolate temperature with a non-binary diffusion model!" );
301 
302  for( typename std::vector<std::vector<BinaryDiffusionBase<Diffusion,CoeffType>*> >::iterator it_outer = _binary_diffusivities.begin();
303  it_outer != _binary_diffusivities.end(); ++it_outer )
304  {
305  for( typename std::vector<BinaryDiffusionBase<Diffusion,CoeffType>*>::iterator it_inner = it_outer->begin();
306  it_inner != it_outer->end(); ++it_inner )
307  {
308  (*it_inner)->extrapolate_max_temp(Tmax);
309  }
310  }
311  }
312 
313  template<typename Diffusion, class CoeffType>
315  const std::vector<CoeffType>& coeffs )
316  {
318  "Invalid to add species diffusion model with Diffusion model is not a species diffusion model!" );
319  antioch_assert_less( s, _species_diffusivities.size() );
320 
321  _species_diffusivities[s] = new Diffusion( coeffs );
322  }
323 
324 } // end namespace Antioch
325 
326 #endif // ANTIOCH_MIXTURE_DIFFUSION_H
void add_species_diffusion(unsigned int s, const std::vector< CoeffType > &coeffs)
Add species diffusion model for species s.
#define antioch_assert(asserted)
void private_species_diff_impl(unsigned int s, const StateType &rho, const StateType &cp, const StateType &k, StateType &D, AntiochPrivate::diffusion_tag< SpeciesDiffusionBase< Diffusion, CoeffType > > &) const
Compute species diffusivities.
std::vector< std::vector< BinaryDiffusionBase< Diffusion, CoeffType > * > > _binary_diffusivities
Stores binary diffusion model for all species pairs.
std::vector< SpeciesDiffusionBase< Diffusion, CoeffType > * > _species_diffusivities
Stores species diffusivity models.
#define antioch_assert_equal_to(expr1, expr2)
#define antioch_assert_greater(expr1, expr2)
#define antioch_assert_less(expr1, expr2)
const TransportMixture< CoeffType > & _transport_mixture
Base class for species diffusion models.
void private_species_diff_impl(unsigned int, const StateType &, const StateType &, const StateType &, StateType &, AntiochPrivate::diffusion_tag< BinaryDiffusionBase< Diffusion, CoeffType > > &) const
Invalid to call species diffusivity calculation with BinaryDiffusionBase model.
Class to encapsulate data relevant for transport for each chemical species.
#define antioch_error()
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)
void private_diff_matrix_impl(const StateType &, const StateType &, MatrixStateType &, AntiochPrivate::diffusion_tag< SpeciesDiffusionBase< Diffusion, CoeffType > > &) const
Invalid to call binary diffusion matrix with SpeciesDiffusionBase model.
#define antioch_error_msg(errmsg)
Base class for MixtureViscosity, MixtureConductivity, etc.
Class storing chemical mixture properties.
Definition: ascii_parser.h:55
#define antioch_static_assert(cond, errmsg)
void compute_species_diffusivity(unsigned int s, const StateType &rho, const StateType &cp, const StateType &k, StateType &D) const
Computes species diffusivity for species s.
Base class for binary diffusion models.
void compute_binary_diffusion_matrix(const StateType &T, const StateType &molar_density, MatrixStateType &D) const
Computes the binary diffusion matrix.
Characteristics of various diffusion models.
#define antioch_static_assert_runtime_fallback(cond, errmsg)
void private_init_impl(AntiochPrivate::diffusion_tag< BinaryDiffusionBase< Diffusion, CoeffType > > &)
Initialize binary diffusion models.
void extrapolate_max_temp(const StateType &Tmax)
Extrapolate to input maximum temperature, given in [K].
void private_init_impl(AntiochPrivate::diffusion_tag< SpeciesDiffusionBase< Diffusion, CoeffType > > &)
Initialize species diffusion models.
The parameters are reduced parameters.
void private_diff_matrix_impl(const StateType &T, const StateType &molar_density, MatrixStateType &D, AntiochPrivate::diffusion_tag< BinaryDiffusionBase< Diffusion, CoeffType > > &) const
Compute binary diffusion matrix.
const TransportMixture< CoeffType > & transport_mixture() const
We use these tags to force operator overloading based on Diffusion type.

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