antioch-0.4.0
nasa9_curve_fit.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_NASA9_CURVE_FIT_H
28 #define ANTIOCH_NASA9_CURVE_FIT_H
29 
30 // Antioch
32 #include "antioch/temp_cache.h"
33 
34 namespace Antioch
35 {
69  template<typename CoeffType=double>
70  class NASA9CurveFit : public NASACurveFitBase<CoeffType>
71  {
72  public:
73 
75  NASA9CurveFit( const std::vector<CoeffType>& coeffs, const std::vector<CoeffType>& temps );
76 
78 
80  NASA9CurveFit( const std::vector<CoeffType>& coeffs );
81 
83 
91  template <typename StateType>
92  const StateType cp_over_R (const TempCache<StateType> & cache) const;
93 
103  template <typename StateType>
104  StateType h_over_RT( const TempCache<StateType>& cache) const;
105 
115  template <typename StateType>
116  StateType s_over_R( const TempCache<StateType>& cache) const;
117 
128  template <typename StateType>
129  StateType h_RT_minus_s_R( const TempCache<StateType>& cache) const;
130 
141  template <typename StateType>
142  StateType dh_RT_minus_s_R_dT( const TempCache<StateType>& cache) const;
143 
144  protected:
145 
147 
148  void init_nasa9_temps( const std::vector<CoeffType>& coeffs,
149  unsigned n_coeffs );
150 
151  };
152 
153 
154  /* ------------------------- Inline Functions -------------------------*/
155  template<typename CoeffType>
156  inline
157  NASA9CurveFit<CoeffType>::NASA9CurveFit( const std::vector<CoeffType>& coeffs,
158  const std::vector<CoeffType>& temp )
159  : NASACurveFitBase<CoeffType>(coeffs,temp)
160  {
161  this->_n_coeffs = 9;
162 
163  this->check_coeff_size();
165  }
166 
167  template<typename CoeffType>
168  inline
169  NASA9CurveFit<CoeffType>::NASA9CurveFit( const std::vector<CoeffType>& coeffs )
170  : NASACurveFitBase<CoeffType>(coeffs,std::vector<CoeffType>())
171  {
172  this->_n_coeffs = 9;
173  this->check_coeff_size();
174 
175  this->init_nasa9_temps( coeffs, this->_n_coeffs );
176 
178  }
179 
180  template<typename CoeffType>
181  inline
182  void NASA9CurveFit<CoeffType>::init_nasa9_temps( const std::vector<CoeffType>& coeffs,
183  unsigned n_coeffs )
184  {
185  // All default NASA9 curve fits should have this
186  this->_temp.resize(3);
187  this->_temp[0] = 200.L;
188  this->_temp[1] = 1000.L;
189  this->_temp[2] = 6000.L;
190 
191  // But some also have this last interval. We infer this from the size of the coeffs.
192  if( coeffs.size()/n_coeffs == 3 )
193  this->_temp.push_back(20000.L);
194  }
195 
196  template<typename CoeffType>
197  template <typename StateType>
198  inline
199  const StateType NASA9CurveFit<CoeffType>::cp_over_R(const TempCache<StateType>& cache) const
200  {
201  typedef typename
203  const UIntType interval = this->interval(cache.T);
204  const unsigned int begin_interval = Antioch::min(interval);
205  const unsigned int end_interval = Antioch::max(interval)+1;
206 
207  // FIXME - this needs expression templates to be faster...
208 
209  StateType returnval = Antioch::zero_clone(cache.T);
210 
211  for (unsigned int i=begin_interval; i != end_interval; ++i)
212  {
213  const CoeffType * const a =
214  this->coefficients(i);
215  returnval = Antioch::if_else
216  (interval == i,
217  StateType(a[0]/cache.T2 + a[1]/cache.T + a[2] + a[3]*cache.T +
218  a[4]*cache.T2 + a[5]*cache.T3 + a[6]*cache.T4),
219  returnval);
220  }
221 
222  return returnval;
223 
224  }
225 
226  template<typename CoeffType>
227  template<typename StateType>
228  inline
230  {
231  typedef typename
233  const UIntType interval = this->interval(cache.T);
234  const unsigned int begin_interval = Antioch::min(interval);
235  const unsigned int end_interval = Antioch::max(interval)+1;
236 
237  StateType returnval = Antioch::zero_clone(cache.T);
238 
239  for (unsigned int i=begin_interval; i != end_interval; ++i)
240  {
241  const CoeffType *a = this->coefficients(interval);
242 
243  /* h/RT = -a0*T^-2 + a1*T^-1*lnT + a2 + a3*T/2 + a4*T^2/3 + a5*T^3/4 + a6*T^4/5 + a7/T */
244  returnval = Antioch::if_else
245  ( interval == i,
246  StateType( -a[0]/cache.T2 + a[1]*cache.lnT/cache.T + a[2] +
247  a[3]*cache.T/2.0L + a[4]*cache.T2/3.0L + a[5]*cache.T3/4.0L +
248  a[6]*cache.T4/5.0L + a[7]/cache.T),
249  returnval);
250  }
251  return returnval;
252  }
253 
254  template<typename CoeffType>
255  template<typename StateType>
256  inline
258  {
259  typedef typename
261  const UIntType interval = this->interval(cache.T);
262  const unsigned int begin_interval = Antioch::min(interval);
263  const unsigned int end_interval = Antioch::max(interval)+1;
264 
265  StateType returnval = Antioch::zero_clone(cache.T);
266 
267  for (unsigned int i=begin_interval; i != end_interval; ++i)
268  {
269  const CoeffType *a = this->coefficients(interval);
270 
271  /* s/R = -a0*T^-2/2 - a1*T^-1 + a2*lnT + a3*T + a4*T^2/2 + a5*T^3/3 + a6*T^4/4 + a8 */
272  returnval = Antioch::if_else
273  ( interval == i,
274  StateType( -a[0]/cache.T2/2.0 - a[1]/cache.T + a[2]*cache.lnT
275  + a[3]*cache.T + a[4]*cache.T2/2.0 + a[5]*cache.T3/3.0
276  + a[6]*cache.T4/4.0 + a[8]),
277  returnval);
278  }
279  return returnval;
280  }
281 
282  template<typename CoeffType>
283  template<typename StateType>
284  inline
285  StateType
287  {
288  typedef typename
290  const UIntType interval = this->interval(cache.T);
291  const unsigned int begin_interval = Antioch::min(interval);
292  const unsigned int end_interval = Antioch::max(interval)+1;
293 
294  StateType returnval = Antioch::zero_clone(cache.T);
295 
296  for (unsigned int i=begin_interval; i != end_interval; ++i)
297  {
298  const CoeffType *a = this->coefficients(interval);
299 
300  /* h/RT = -a[0]/T2 + a[1]*lnT/T + a[2] + a[3]*T/2. + a[4]*T2/3. + a[5]*T3/4. + a[6]*T4/5. + a[7]/T,
301  s/R = -a[0]/T2/2. - a[1]/T + a[2]*lnT + a[3]*T + a[4]*T2/2. + a[5]*T3/3. + a[6]*T4/4. + a[8] */
302  returnval = Antioch::if_else
303  ( interval == i,
304  StateType(-a[0]/cache.T2/2.0 + (a[1] + a[7])/cache.T +
305  a[1]*cache.lnT/cache.T - a[2]*cache.lnT +
306  (a[2] - a[8]) - a[3]*cache.T/2.0 -
307  a[4]*cache.T2/6.0 - a[5]*cache.T3/12.0 -
308  a[6]*cache.T4/20.0),
309  returnval);
310  }
311  return returnval;
312  }
313 
314  template <typename CoeffType>
315  template <typename StateType>
316  inline
318  {
319  typedef typename
321  const UIntType interval = this->interval(cache.T);
322  const unsigned int begin_interval = Antioch::min(interval);
323  const unsigned int end_interval = Antioch::max(interval)+1;
324 
325  // FIXME - this needs expression templates to be faster...
326 
327  StateType returnval = Antioch::zero_clone(cache.T);
328 
329  /* h/RT = -a[0]/T2 + a[1]*lnT/T + a[2] + a[3]*T/2. + a[4]*T2/3. + a[5]*T3/4. + a[6]*T4/5. + a[7]/T,
330  s/R = -a[0]/T2/2. - a[1]/T + a[2]*lnT + a[3]*T + a[4]*T2/2. + a[5]*T3/3. + a[6]*T4/4. + a[8] */
331  for (unsigned int i=begin_interval; i != end_interval; ++i)
332  {
333  const CoeffType * const a =
334  this->coefficients(i);
335  returnval = Antioch::if_else
336  (interval == i,
337  StateType(a[0]/cache.T3 - a[7]/cache.T2 -
338  a[1]*cache.lnT/cache.T2 - a[2]/cache.T -
339  a[3]/2. - a[4]*cache.T/3. - a[5]*cache.T2/4. -
340  a[6]*cache.T3/5.),
341  returnval);
342  }
343 
344  return returnval;
345 
346  }
347 
348 } // end namespace Antioch
349 #endif // ANTIOCH_NASA9_CURVE_FIT_H
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
void check_temp_coeff_size_consistency() const
const StateType & T
Definition: temp_cache.h:49
const StateType cp_over_R(const TempCache< StateType > &cache) const
void init_nasa9_temps(const std::vector< CoeffType > &coeffs, unsigned n_coeffs)
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type min(const T &in)
Definition: eigen_utils.h:98
StateType h_over_RT(const TempCache< StateType > &cache) const
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
StateType dh_RT_minus_s_R_dT(const TempCache< StateType > &cache) const
StateType h_RT_minus_s_R(const TempCache< StateType > &cache) const
StateType s_over_R(const TempCache< StateType > &cache) const
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
unsigned int _n_coeffs
The number of coefficients in each interval.

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