antioch-0.4.0
nasa_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 
28 #ifndef ANTIOCH_NASA_MIXTURE_H
29 #define ANTIOCH_NASA_MIXTURE_H
30 
31 // Antioch
34 #include "antioch/input_utils.h"
35 #include "antioch/cea_curve_fit.h"
37 #include "antioch/temp_cache.h"
38 #include "antioch/nasa_evaluator.h"
39 
40 // C++
41 #include <iomanip>
42 #include <vector>
43 #include <cmath>
44 
45 namespace Antioch
46 {
47 
48  template<typename CoeffType, typename NASAFit>
49  class NASAEvaluator;
50 
51  template<typename CoeffType=double, typename NASAFit = NASA9CurveFit<CoeffType> >
52  class NASAThermoMixture
53  {
54  public:
55 
56  NASAThermoMixture( const ChemicalMixture<CoeffType>& chem_mixture );
57 
59 
60  virtual ~NASAThermoMixture();
61 
62  //NASA9 friendly
63  void add_curve_fit( const std::string& species_name, const std::vector<CoeffType>& coeffs );
64 
65  //NASA general
66  void add_curve_fit( const std::string& species_name, const std::vector<CoeffType>& coeffs, const std::vector<CoeffType>& temps );
67 
68  const NASAFit& curve_fit( unsigned int s ) const;
69 
70  CoeffType cp_at_200p1( unsigned int s ) const;
71 
73  bool check() const;
74 
75  const ChemicalMixture<CoeffType>& chemical_mixture() const;
76 
77  protected:
78 
80 
81  std::vector<NASAFit* > _species_curve_fits;
82 
83  std::vector<CoeffType> _cp_at_200p1;
84 
85  private:
86 
88 
90 
91  };
92 
93  /* --------------------- Constructor/Destructor -----------------------*/
94  template<typename CoeffType, typename NASAFit>
96  : _chem_mixture(chem_mixture),
97  _species_curve_fits(chem_mixture.n_species(), NULL),
98  _cp_at_200p1( _species_curve_fits.size() )
99  {
100  return;
101  }
102 
103 
104  template<typename CoeffType, typename NASAFit>
106  {
107  // Clean up all the NASAFits we created
108  for( typename std::vector<NASAFit* >::iterator it = _species_curve_fits.begin();
109  it < _species_curve_fits.end(); ++it )
110  {
111  delete (*it);
112  }
113 
114  return;
115  }
116 
117  /* ------------------------- Inline Functions -------------------------*/
118  template<typename CoeffType, typename NASAFit>
119  inline
120  void NASAThermoMixture<CoeffType,NASAFit>::add_curve_fit( const std::string& species_name,
121  const std::vector<CoeffType>& coeffs)
122  {
123  antioch_assert( _chem_mixture.species_name_map().find(species_name) !=
124  _chem_mixture.species_name_map().end() );
125 
126  unsigned int s = _chem_mixture.species_name_map().find(species_name)->second;
127 
128  antioch_assert_less_equal( s, _species_curve_fits.size() );
129  antioch_assert( !_species_curve_fits[s] );
130 
131  _species_curve_fits[s] = new NASAFit(coeffs);
132 
133  NASAEvaluator<CoeffType,NASAFit> evaluator( *this );
134  _cp_at_200p1[s] = evaluator.cp( TempCache<CoeffType>(200.1), s );
135 
136  return;
137  }
138 
139  template<typename CoeffType, typename NASAFit>
140  inline
141  void NASAThermoMixture<CoeffType,NASAFit>::add_curve_fit( const std::string& species_name,
142  const std::vector<CoeffType>& coeffs, const std::vector<CoeffType>& temps )
143  {
144  antioch_assert( _chem_mixture.species_name_map().find(species_name) !=
145  _chem_mixture.species_name_map().end() );
146 
147  unsigned int s = _chem_mixture.species_name_map().find(species_name)->second;
148 
149  antioch_assert_less_equal( s, _species_curve_fits.size() );
150  antioch_assert( !_species_curve_fits[s] );
151 
152  _species_curve_fits[s] = new NASAFit(coeffs,temps);
153 
154  NASAEvaluator<CoeffType,NASAFit> evaluator( *this );
155  _cp_at_200p1[s] = evaluator.cp( TempCache<CoeffType>(200.1), s );
156 
157  return;
158  }
159 
160 
161  template<typename CoeffType, typename NASAFit>
162  inline
164  {
165  bool valid = true;
166 
167  for( typename std::vector<NASAFit* >::const_iterator it = _species_curve_fits.begin();
168  it != _species_curve_fits.end(); ++ it )
169  {
170  if( !(*it) )
171  valid = false;
172  }
173 
174  return valid;
175  }
176 
177  template<typename CoeffType, typename NASAFit>
178  inline
179  const NASAFit& NASAThermoMixture<CoeffType,NASAFit>::curve_fit( unsigned int s ) const
180  {
181  // Did we allocate for enough species?
182  antioch_assert_less( s, _species_curve_fits.size() );
183 
184  // Did we read in enough mixture data?
185  antioch_assert( _species_curve_fits[s] );
186 
187  return *_species_curve_fits[s];
188  }
189 
190  template<typename CoeffType, typename NASAFit>
191  inline
192  CoeffType NASAThermoMixture<CoeffType,NASAFit>::cp_at_200p1( unsigned int s ) const
193  {
194  antioch_assert_less( s, _cp_at_200p1.size() );
195  return _cp_at_200p1[s];
196  }
197 
198  template<typename CoeffType, typename NASAFit>
199  inline
201  {
202  return _chem_mixture;
203  }
204 
205 } // end namespace Antioch
206 
207 #endif // ANTIOCH_NASA_MIXTURE_H
virtual ~NASAThermoMixture()
Destructor.
Definition: nasa_mixture.h:105
#define antioch_assert(asserted)
const NASAFit & curve_fit(unsigned int s) const
Definition: nasa_mixture.h:179
const ChemicalMixture< CoeffType > & _chem_mixture
Definition: nasa_mixture.h:79
NASAThermoMixture()
Default constructor.
#define antioch_assert_less(expr1, expr2)
CoeffType cp_at_200p1(unsigned int s) const
Definition: nasa_mixture.h:192
#define antioch_assert_less_equal(expr1, expr2)
void add_curve_fit(const std::string &species_name, const std::vector< CoeffType > &coeffs)
Definition: nasa_mixture.h:120
std::vector< NASAFit * > _species_curve_fits
Definition: nasa_mixture.h:81
const ChemicalMixture< CoeffType > & chemical_mixture() const
Definition: nasa_mixture.h:200
std::vector< CoeffType > _cp_at_200p1
Definition: nasa_mixture.h:83
Class storing chemical mixture properties.
The parameters are reduced parameters.
StateType cp(const TempCache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
bool check() const
Checks that curve fits have been specified for all species in the mixture.
Definition: nasa_mixture.h:163

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