antioch-0.4.0
chemical_mixture.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_CHEMICAL_MIXTURE_H
33 #define ANTIOCH_CHEMICAL_MIXTURE_H
34 
35 // Antioch
36 #include "antioch_config.h" // default files
41 
42 // C++
43 #include <vector>
44 #include <map>
45 #include <string>
46 
47 namespace Antioch
48 {
49  typedef unsigned int Species;
50 
51  // Forward declarations
52  template <class NumericType>
53  class ParserBase;
54 
56 
74  template<typename CoeffType=double>
76  {
77  public:
79  ChemicalMixture( const std::string & filename = DefaultFilename::species_list(),
80  const bool verbose = true,
81  const std::string & species_data = DefaultFilename::chemical_mixture(),
82  const std::string & vibration_data = DefaultFilename::vibrational_data(),
83  const std::string & electronic_data = DefaultFilename::electronic_data());
84 
86  ChemicalMixture( const std::vector<std::string>& species_list,
87  const bool verbose = true,
88  const std::string & species_data = DefaultFilename::chemical_mixture(),
89  const std::string & vibration_data = DefaultFilename::vibrational_data(),
90  const std::string & electronic_data = DefaultFilename::electronic_data());
91 
94  const std::string & species_data = DefaultFilename::chemical_mixture(),
95  const std::string & vibration_data = DefaultFilename::vibrational_data(),
96  const std::string & electronic_data = DefaultFilename::electronic_data());
97 
99 
107 
109  void initialize_species(const std::vector<std::string> & species_list);
110 
113  const std::string & species_data,
114  const std::string & vibration_data,
115  const std::string & electronic_data);
116 
119 
122 
125 
127  unsigned int n_species() const;
128 
129  void add_species( const unsigned int index, const std::string& name,
130  CoeffType mol_wght, CoeffType h_form,
131  CoeffType n_tr_dofs, int charge );
132 
133  void add_species_vibrational_data( const unsigned int index,
134  const CoeffType theta_v,
135  const unsigned int ndg_v );
136 
137  void add_species_electronic_data( const unsigned int index,
138  const CoeffType theta_e,
139  const unsigned int ndg_e );
140 
141  const std::vector<ChemicalSpecies<CoeffType>*>& chemical_species() const;
142 
143  const std::vector<Species>& species_list() const;
144 
145  const std::map<std::string,Species>& species_name_map() const;
146 
147  const std::map<Species,std::string>& species_inverse_name_map() const;
148 
149  const std::map<std::string,Species>& active_species_name_map() const;
150 
152  CoeffType R( const unsigned int s ) const;
153 
155  template<typename VectorStateType>
156  typename enable_if_c<
159  >::type
160  R( const VectorStateType& mass_fractions ) const;
161 
163  CoeffType M( const unsigned int s ) const;
164 
166 
171  template<typename VectorStateType>
172  typename enable_if_c<
173  has_size<VectorStateType>::value,
175  >::type
176  M( const VectorStateType& mass_fractions ) const;
177 
179 
184  template<typename StateType>
185  ANTIOCH_AUTO(StateType)
186  X( const unsigned int species, const StateType& M,
187  const StateType& mass_fraction ) const
188  ANTIOCH_AUTOFUNC(StateType, mass_fraction*M/this->M(species))
189 
190 
191 
195  template<typename VectorStateType>
197  const VectorStateType& mass_fractions,
198  VectorStateType& mole_fractions ) const;
199 
201 
205  template<typename StateType>
206  ANTIOCH_AUTO(StateType)
207  molar_density( const unsigned int species,
208  const StateType& rho,
209  const StateType& mass_fraction ) const
210  ANTIOCH_AUTOFUNC(StateType, rho*mass_fraction/this->M(species))
211 
213 
217  template<typename StateType, typename VectorStateType>
218  void molar_densities( const StateType& rho,
219  const VectorStateType& mass_fractions,
220  VectorStateType& molar_densities ) const;
221 
222  protected:
223 
224  void init_species_name_map(const std::vector<std::string> & species_list);
225  void build_inverse_name_map();
226 
227  std::vector<Species> _species_list;
228  std::vector<ChemicalSpecies<CoeffType>*> _chemical_species;
229  std::map<std::string,Species> _species_name_map;
230  std::map<Species,std::string> _species_inv_name_map;
231 
232  };
233 
234 
235  /* ------------------------- Inline Functions -------------------------*/
236  template<typename CoeffType>
237  inline
238  unsigned int ChemicalMixture<CoeffType>::n_species() const
239  {
240  return _species_list.size();
241  }
242 
243  template<typename CoeffType>
244  inline
245  const std::vector<Species>& ChemicalMixture<CoeffType>::species_list() const
246  {
247  return _species_list;
248  }
249 
250  template<typename CoeffType>
251  inline
252  const std::vector<ChemicalSpecies<CoeffType>*>& ChemicalMixture<CoeffType>::chemical_species() const
253  {
254  return _chemical_species;
255  }
256 
257  template<typename CoeffType>
258  inline
259  const std::map<std::string,Species>& ChemicalMixture<CoeffType>::species_name_map() const
260  {
261  return _species_name_map;
262  }
263 
264  template<typename CoeffType>
265  inline
266  const std::map<Species,std::string>& ChemicalMixture<CoeffType>::species_inverse_name_map() const
267  {
268  return _species_inv_name_map;
269  }
270 
271  template<typename CoeffType>
272  inline
273  const std::map<std::string,Species>&
275  {
277  return _species_name_map;
278  }
279 
280  template<typename CoeffType>
281  inline
282  CoeffType ChemicalMixture<CoeffType>::R( const unsigned int s ) const
283  {
284  return (_chemical_species[s])->gas_constant();
285  }
286 
287  template<typename CoeffType>
288  inline
289  CoeffType ChemicalMixture<CoeffType>::M( const unsigned int s ) const
290  {
291  return (_chemical_species[s])->molar_mass();
292  }
293 
294  template<typename CoeffType>
295  template<typename StateType, typename VectorStateType>
296  inline
297  void ChemicalMixture<CoeffType>::molar_densities( const StateType& rho,
298  const VectorStateType& mass_fractions,
299  VectorStateType& molar_densities ) const
300  {
301  antioch_assert_equal_to( mass_fractions.size(), this->n_species() );
302  antioch_assert_equal_to( molar_densities.size(), this->n_species() );
303 
304  // !\todo Figure out how to make this assert vector-compatible
305  // antioch_assert_greater( rho, 0.0 );
306 
307  for( unsigned int s = 0; s < this->n_species(); s++ )
308  {
309  molar_densities[s] = rho*mass_fractions[s]/this->M(s);
310  }
311  return;
312  }
313 
314  template<typename CoeffType>
315  template<typename VectorStateType>
316  inline
317  typename enable_if_c<
318  has_size<VectorStateType>::value,
320  >::type
321  ChemicalMixture<CoeffType>::R( const VectorStateType& mass_fractions ) const
322  {
323  antioch_assert_equal_to( mass_fractions.size(), _chemical_species.size() );
324  antioch_assert_greater( mass_fractions.size(), 0);
325 
327  R = mass_fractions[0]*this->R(0);
328  for( unsigned int s = 1; s < mass_fractions.size(); s++ )
329  {
330  R += mass_fractions[s]*this->R(s);
331  }
332 
333  return R;
334  }
335 
336 
337  template<typename CoeffType>
338  template<typename VectorStateType>
339  inline
340  typename enable_if_c<
341  has_size<VectorStateType>::value,
343  >::type
344  ChemicalMixture<CoeffType>::M( const VectorStateType& mass_fractions ) const
345  {
346  antioch_assert_equal_to( mass_fractions.size(), _chemical_species.size() );
347 
349  M = mass_fractions[0]/this->M(0);
350  for( unsigned int s = 1; s < mass_fractions.size(); s++ )
351  {
352  M += mass_fractions[s]/(this->M(s));
353  }
354 
355  return CoeffType(1)/M;
356  }
357 
358 
359  template<typename CoeffType>
360  template<typename VectorStateType>
361  inline
363  const VectorStateType& mass_fractions,
364  VectorStateType& mole_fractions ) const
365  {
366  antioch_assert_equal_to( mass_fractions.size(), _chemical_species.size() );
367 
368  // Require output size to be correct. This is more efficient and
369  // works around the difficulty of resizing Eigen containers of
370  // types which may lack default constructors.
371  antioch_assert_equal_to( mass_fractions.size(), mole_fractions.size() );
372 
373  for( unsigned int s = 0; s < mass_fractions.size(); s++ )
374  {
375  mole_fractions[s] = this->X(s, M, mass_fractions[s]);
376  }
377 
378  return;
379  }
380 
381  template<typename CoeffType>
382  inline
384  {
386  return *this;
387  }
388 
389 } // end namespace Antioch
390 
391 #endif //ANTIOCH_CHEMICAL_MIXTURE_H
std::vector< ChemicalSpecies< CoeffType > * > _chemical_species
static const std::string & electronic_data()
unsigned int Species
std::vector< Species > _species_list
void read_species_vibrational_characteristics(ParserBase< CoeffType > *parser)
method to read vibrational characteristics
const ChemicalMixture< CoeffType > & chemical_mixture() const
method to send this back
CoeffType R(const unsigned int s) const
Gas constant for species s in [J/kg-K].
#define antioch_assert_equal_to(expr1, expr2)
const std::vector< Species > & species_list() const
#define antioch_assert_greater(expr1, expr2)
void init_species_name_map(const std::vector< std::string > &species_list)
CoeffType M(const unsigned int s) const
Molecular weight (molar mass) for species s in kg/mol.
static const std::string & chemical_mixture()
void read_species_mandatory_characteristics(ParserBase< CoeffType > *parser)
method to read mandatory characteristics
std::map< std::string, Species > _species_name_map
const std::map< std::string, Species > & species_name_map() const
Class to encapsulate data for each chemical species.
std::map< Species, std::string > _species_inv_name_map
const std::map< Species, std::string > & species_inverse_name_map() const
unsigned int n_species() const
Returns the number of species in this mixture.
#define antioch_deprecated()
static const std::string & vibrational_data()
void initialize_species(const std::vector< std::string > &species_list)
method to initialize, backward compatibility
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
void add_species(const unsigned int index, const std::string &name, CoeffType mol_wght, CoeffType h_form, CoeffType n_tr_dofs, int charge)
void read_species_characteristics(ParserBase< CoeffType > *parser, const std::string &species_data, const std::string &vibration_data, const std::string &electronic_data)
method to read characteristics, using one parser
X(const unsigned int species, const StateType &M, const StateType &mass_fraction) const template< typename VectorStateType > void X(typename Antioch VectorStateType void molar_densities(const StateType &rho, const VectorStateType &mass_fractions, VectorStateType &molar_densities) const
void add_species_vibrational_data(const unsigned int index, const CoeffType theta_v, const unsigned int ndg_v)
Class storing chemical mixture properties.
void add_species_electronic_data(const unsigned int index, const CoeffType theta_e, const unsigned int ndg_e)
The parameters are reduced parameters.
ChemicalMixture(const std::string &filename=DefaultFilename::species_list(), const bool verbose=true, const std::string &species_data=DefaultFilename::chemical_mixture(), const std::string &vibration_data=DefaultFilename::vibrational_data(), const std::string &electronic_data=DefaultFilename::electronic_data())
ascii parser by default
void read_species_electronic_characteristics(ParserBase< CoeffType > *parser)
method to read electronic characteristics
const std::map< std::string, Species > & active_species_name_map() const
A parser is an instance related to a file.
const std::vector< ChemicalSpecies< CoeffType > * > & chemical_species() const
static const std::string & species_list()
X(const unsigned int species, const StateType &M, const StateType &mass_fraction) const template< typename VectorStateType > void X(typename Antioch molar_density(const unsigned int species, const StateType &rho, const StateType &mass_fraction) const template< typename StateType
Species mole fraction.

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