antioch-0.4.0
nasa_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 
28 #ifndef ANTIOCH_NASA_EVALUATOR_H
29 #define ANTIOCH_NASA_EVALUATOR_H
30 
31 // Antioch
33 #include "antioch/nasa_mixture.h"
34 #include "antioch/temp_cache.h"
35 
36 namespace Antioch
37 {
38 
39  template<typename CoeffType>
40  class NASACurveFit;
41 
42  template<typename CoeffType, typename NASAFit>
43  class NASAThermoMixture;
44 
45  template<typename CoeffType=double, typename NASAFit = NASA9CurveFit<CoeffType> >
46  class NASAEvaluator
47  {
48  public:
49 
52 
54 
56  template<typename StateType>
57  StateType
58  cp( const TempCache<StateType>& cache, unsigned int species ) const;
59 
60  template<typename StateType, typename VectorStateType>
61  typename enable_if_c<
63  >::type
64  cp( const TempCache<StateType>& cache, const VectorStateType& mass_fractions ) const;
65 
66  template<typename StateType>
67  ANTIOCH_AUTO(StateType)
68  cv( const TempCache<StateType>& cache, unsigned int species ) const
69  ANTIOCH_AUTOFUNC(StateType,
70  this->cp(cache,species) -
71  this->chem_mixture().R(species))
72 
73  template<typename StateType, typename VectorStateType>
74  typename enable_if_c<
75  has_size<VectorStateType>::value, StateType
76  >::type
77  cv( const TempCache<StateType>& cache, const VectorStateType& mass_fractions ) const;
78 
79  template<typename StateType>
80  ANTIOCH_AUTO(StateType)
81  h( const TempCache<StateType>& cache, unsigned int species ) const
82  ANTIOCH_AUTOFUNC(StateType,
83  this->chem_mixture().R(species) * cache.T *
84  this->h_over_RT(cache,species))
85 
86  template<typename StateType, typename VectorStateType>
87  typename enable_if_c<
88  has_size<VectorStateType>::value, void
89  >::type
90  h( const TempCache<StateType>& cache, VectorStateType& h ) const;
91 
93  template<typename StateType>
94  StateType
95  h_RT_minus_s_R( const TempCache<StateType>& cache, unsigned int species ) const;
96 
97  template<typename StateType, typename VectorStateType>
98  typename enable_if_c<
99  has_size<VectorStateType>::value, void
100  >::type
101  h_RT_minus_s_R( const TempCache<StateType>& cache, VectorStateType& h_RT_minus_s_R ) const;
102 
103  template<typename StateType>
104  StateType
105  dh_RT_minus_s_R_dT( const TempCache<StateType>& cache, unsigned int species ) const;
106 
107  template<typename StateType, typename VectorStateType>
108  typename enable_if_c<
109  has_size<VectorStateType>::value, void
110  >::type
111  dh_RT_minus_s_R_dT( const TempCache<StateType>& cache, VectorStateType& h_RT_minus_s_R ) const;
112 
113 
115  template<typename StateType>
116  StateType cp_over_R( const TempCache<StateType>& cache, unsigned int species ) const;
117 
119  // \f[ \frac{C_v}{\mathrm{R} = \frac{C_p}{\mathrm{R}} - 1\f]
120  template<typename StateType>
121  StateType cv_over_R( const TempCache<StateType>& cache, unsigned int species ) const;
122 
124  template<typename StateType>
125  StateType h_over_RT( const TempCache<StateType>& cache, unsigned int species ) const;
126 
128  template<typename StateType>
129  StateType s_over_R( const TempCache<StateType>& cache, unsigned int species ) const;
130 
131  protected:
132 
133  const NASAThermoMixture<CoeffType,NASAFit>& _nasa_mixture;
134 
136  unsigned int n_species() const;
137 
139  const ChemicalMixture<CoeffType>& chem_mixture() const;
140 
141  private:
142 
144 
145  NASAEvaluator();
146 
147  };
148 
149  /* --------------------- Constructor/Destructor -----------------------*/
150  template<typename CoeffType, typename NASAFit>
151  NASAEvaluator<CoeffType,NASAFit>::NASAEvaluator( const NASAThermoMixture<CoeffType,NASAFit>& cea_mixture )
152  : _nasa_mixture(cea_mixture)
153  {
154  return;
155  }
156 
157  template<typename CoeffType, typename NASAFit>
159  {
160  return;
161  }
162 
163  /* ------------------------- Inline Functions -------------------------*/
164  template<typename CoeffType, typename NASAFit>
165  inline
167  {
168  return _nasa_mixture;
169  }
170 
171  template<typename CoeffType, typename NASAFit>
172  inline
174  {
175  return _nasa_mixture.chemical_mixture().n_species();
176  }
177 
178  template<typename CoeffType, typename NASAFit>
179  inline
181  {
182  return _nasa_mixture.chemical_mixture();
183  }
184 
185  template<typename CoeffType, typename NASAFit>
186  template<typename StateType>
187  inline
188  StateType
189  NASAEvaluator<CoeffType,NASAFit>::cp( const TempCache<StateType>& cache, unsigned int species ) const
190  {
191  typedef typename Antioch::value_type<StateType>::type ScalarType;
192  // T < 200.1 ? cp_at_200p1 : R * cp_over_R
193 
194  return
196  (cache.T < ScalarType(200.1),
198  (cache.T,_nasa_mixture.cp_at_200p1(species)),
199  StateType
200  (this->chem_mixture().R(species) *
201  this->cp_over_R(cache, species)));
202  }
203 
204  template<typename CoeffType, typename NASAFit>
205  template<typename StateType, typename VectorStateType>
206  inline
207  typename enable_if_c<
208  has_size<VectorStateType>::value, StateType
209  >::type
211  const VectorStateType& mass_fractions ) const
212  {
213  antioch_assert_equal_to( mass_fractions.size(), this->n_species() );
214  antioch_assert_greater( mass_fractions.size(), 0 );
215 
216  StateType cp = mass_fractions[0]*this->cp(cache,0);
217 
218  for( unsigned int s = 1; s < this->n_species(); s++ )
219  {
220  cp += mass_fractions[s]*this->cp(cache,s);
221  }
222 
223  return cp;
224  }
225 
226 
227  template<typename CoeffType, typename NASAFit>
228  template<typename StateType, typename VectorStateType>
229  inline
230  typename enable_if_c<
231  has_size<VectorStateType>::value, void
232  >::type
233  NASAEvaluator<CoeffType,NASAFit>::h( const TempCache<StateType>& cache, VectorStateType& h ) const
234  {
235  antioch_assert_equal_to( h.size(), this->n_species() );
236 
237  for( unsigned int s = 0; s < this->n_species(); s++ )
238  {
239  h[s] = this->chem_mixture().R(s)*cache.T*this->h_over_RT(cache,s);
240  }
241 
242  return;
243  }
244 
245 
246  template<typename CoeffType, typename NASAFit>
247  template<typename StateType>
248  inline
249  StateType
250  NASAEvaluator<CoeffType,NASAFit>::cp_over_R( const TempCache<StateType>& cache, unsigned int species ) const
251  {
252  antioch_assert_less( species, this->n_species() );
253  // FIXME - we need assert_less to be vectorizable
254  // antioch_assert_less( _nasa_mixture.curve_fit(species).interval(cache.T),
255  // _nasa_mixture.curve_fit(species).n_intervals() );
256 
257  return this->_nasa_mixture.curve_fit(species).cp_over_R(cache);
258  }
259 
260  template<typename CoeffType, typename NASAFit>
261  template<typename StateType>
262  inline
263  StateType
264  NASAEvaluator<CoeffType,NASAFit>::cv_over_R( const TempCache<StateType>& cache, unsigned int species ) const
265  {
266  antioch_assert_less( species, this->n_species() );
267  // FIXME - we need assert_less to be vectorizable
268  // antioch_assert_less( _nasa_mixture.curve_fit(species).interval(cache.T),
269  // _nasa_mixture.curve_fit(species).n_intervals() );
270  return this->_nasa_mixture.curve_fit(species).cp_over_R(cache) - StateType(1.L);
271  }
272 
273  template<typename CoeffType, typename NASAFit>
274  template<typename StateType>
275  inline
276  StateType NASAEvaluator<CoeffType,NASAFit>::h_over_RT( const TempCache<StateType>& cache, unsigned int species ) const
277  {
278  antioch_assert_less( species, this->n_species() );
279  antioch_assert_less( _nasa_mixture.curve_fit(species).interval(cache.T),
280  _nasa_mixture.curve_fit(species).n_intervals() );
281 
282  return this->_nasa_mixture.curve_fit(species).h_over_RT(cache);
283  }
284 
285 
286  template<typename CoeffType, typename NASAFit>
287  template<typename StateType>
288  inline
289  StateType NASAEvaluator<CoeffType,NASAFit>::s_over_R( const TempCache<StateType>& cache, unsigned int species ) const
290  {
291  antioch_assert_less( species, this->n_species() );
292  antioch_assert_less( _nasa_mixture.curve_fit(species).interval(cache.T),
293  _nasa_mixture.curve_fit(species).n_intervals() );
294 
295  return this->_nasa_mixture.curve_fit(species).s_over_R(cache);
296  }
297 
298 
299  template<typename CoeffType, typename NASAFit>
300  template<typename StateType>
301  inline
302  StateType
303  NASAEvaluator<CoeffType,NASAFit>::h_RT_minus_s_R( const TempCache<StateType>& cache, unsigned int species ) const
304  {
305  antioch_assert_less( species, this->n_species() );
306  // FIXME - we need assert_less to be vectorizable
307  // antioch_assert_less( _nasa_mixture.curve_fit(species).interval(cache.T),
308  // _nasa_mixture.curve_fit(species).n_intervals() );
309 
310  return this->_nasa_mixture.curve_fit(species).h_RT_minus_s_R(cache);
311  }
312 
313 
314  template<typename CoeffType, typename NASAFit>
315  template<typename StateType, typename VectorStateType>
316  inline
317  typename enable_if_c<
318  has_size<VectorStateType>::value, void
319  >::type
321  VectorStateType& h_RT_minus_s_R ) const
322  {
323  antioch_assert_equal_to( h_RT_minus_s_R.size(), this->n_species() );
324 
325  for( unsigned int s = 0; s < this->n_species(); s++ )
326  {
327  h_RT_minus_s_R[s] = this->h_RT_minus_s_R(cache,s);
328  }
329 
330  return;
331  }
332 
333 
334 
335  template<typename CoeffType, typename NASAFit>
336  template<typename StateType>
337  inline
338  StateType
340  {
341  antioch_assert_less( species, this->n_species() );
342  // FIXME - we need assert_less to be vectorizable
343  // antioch_assert_less( _nasa_mixture.curve_fit(species).interval(cache.T),
344  // _nasa_mixture.curve_fit(species).n_intervals() );
345 
346  return this->_nasa_mixture.curve_fit(species).dh_RT_minus_s_R_dT(cache);
347  }
348 
349 
350  template<typename CoeffType, typename NASAFit>
351  template<typename StateType, typename VectorStateType>
352  inline
353  typename enable_if_c<
354  has_size<VectorStateType>::value, void
355  >::type
357  VectorStateType& dh_RT_minus_s_R_dT ) const
358  {
359  antioch_assert_equal_to( dh_RT_minus_s_R_dT.size(), this->n_species() );
360 
361  for( unsigned int s = 0; s < this->n_species(); s++ )
362  {
363  dh_RT_minus_s_R_dT[s] = this->dh_RT_minus_s_R_dT(cache,s);
364  }
365 
366  return;
367  }
368 
369 
370  template<typename CoeffType, typename NASAFit>
371  template<typename StateType, typename VectorStateType>
372  inline
373  typename enable_if_c<
374  has_size<VectorStateType>::value, StateType
375  >::type
377  const VectorStateType& mass_fractions ) const
378  {
379  return this->cp(cache,mass_fractions) - this->chem_mixture().R(mass_fractions);
380  }
381 
382 } // end namespace Antioch
383 
384 #endif // ANTIOCH_NASA_EVALUATOR_H
StateType h_over_RT(const TempCache< StateType > &cache, unsigned int species) const
h over RT, directly from the curve fit
StateType dh_RT_minus_s_R_dT(const TempCache< StateType > &cache, unsigned int species) const
#define antioch_assert_equal_to(expr1, expr2)
#define antioch_assert_greater(expr1, expr2)
const StateType & T
Definition: temp_cache.h:49
#define antioch_assert_less(expr1, expr2)
StateType h_RT_minus_s_R(const TempCache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
StateType s_over_R(const TempCache< StateType > &cache, unsigned int species) const
s over R, directly from the curve fit
unsigned int n_species() const
Convenience function.
const NASAThermoMixture< CoeffType, NASAFit > & _nasa_mixture
_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
enable_if_c< is_eigen< T1 >::value &&is_eigen< T2 >::value, typename state_type< T1 >::type >::type if_else(const Condition &condition, const T1 &if_true, const T2 &if_false)
Definition: eigen_utils.h:250
h(const TempCache< StateType > &cache, unsigned int species) const ANTIOCH_AUTOFUNC(StateType
const NASAThermoMixture< CoeffType, NASAFit > & cea_mixture() const
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
NASAEvaluator()
Default constructor.
this chem_mixture().R(species)*cache.T *this-> h_over_RT(cache, species)) template< typename StateType, typename VectorStateType >typename enable_if_c< has_size< VectorStateType >::value, void >::typeh(const TempCache< StateType > &cache, VectorStateType &h) const
StateType cv_over_R(const TempCache< StateType > &cache, unsigned int species) const
Cv over R, from ideal gas,.
Class storing chemical mixture properties.
The parameters are reduced parameters.
cv(const TempCache< StateType > &cache, unsigned int species) const ANTIOCH_AUTOFUNC(StateType
StateType cp_over_R(const TempCache< StateType > &cache, unsigned int species) const
Cp over R, directly from the curve fit.
StateType cp(const TempCache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.

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