antioch-0.4.0
nasa7_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 
28 #ifndef ANTIOCH_NASA7_CURVE_FIT_H
29 #define ANTIOCH_NASA7_CURVE_FIT_H
30 
31 // Antioch
33 #include "antioch/temp_cache.h"
34 
35 namespace Antioch
36 {
37  template<typename CoeffType=double>
38  class NASA7CurveFit : public NASACurveFitBase<CoeffType>
39  {
40  public:
41 
42  // default: [300,1000] [1000,5000]
43  NASA7CurveFit( const std::vector<CoeffType>& coeffs);
44 
45  NASA7CurveFit( const std::vector<CoeffType>& coeffs, const std::vector<CoeffType> & temp );
47 
55  template <typename StateType>
56  const StateType cp_over_R (const TempCache<StateType> & cache) const;
57 
66  template <typename StateType>
67  StateType h_over_RT( const TempCache<StateType>& cache) const;
68 
77  template <typename StateType>
78  StateType s_over_R( const TempCache<StateType>& cache) const;
79 
89  template <typename StateType>
90  StateType h_RT_minus_s_R( const TempCache<StateType>& cache) const;
91 
101  template <typename StateType>
102  StateType dh_RT_minus_s_R_dT( const TempCache<StateType>& cache) const;
103 
104  };
105 
106 
107  /* ------------------------- Inline Functions -------------------------*/
108 
109  template<typename CoeffType>
110  inline
111  NASA7CurveFit<CoeffType>::NASA7CurveFit( const std::vector<CoeffType>& coeffs, const std::vector<CoeffType> & temp )
112  : NASACurveFitBase<CoeffType>(coeffs,temp)
113  {
114  this->_n_coeffs = 7;
115 
116  this->check_coeff_size();
118  }
119 
120  template<typename CoeffType>
121  inline
122  NASA7CurveFit<CoeffType>::NASA7CurveFit( const std::vector<CoeffType>& coeffs)
123  : NASACurveFitBase<CoeffType>(coeffs,std::vector<CoeffType>())
124  {
125  this->_n_coeffs = 7;
126 
127  this->_temp.resize(3);
128  this->_temp[0] = 300.L;
129  this->_temp[1] = 1000.L;
130  this->_temp[2] = 5000.L;
131 
132  this->check_coeff_size();
134  }
135 
136  template<typename CoeffType>
137  template <typename StateType>
138  inline
139  const StateType NASA7CurveFit<CoeffType>::cp_over_R(const TempCache<StateType>& cache) const
140  {
141  typedef typename
143  const UIntType interval = this->interval(cache.T);
144  const unsigned int begin_interval = Antioch::min(interval);
145  const unsigned int end_interval = Antioch::max(interval)+1;
146 
147  // FIXME - this needs expression templates to be faster...
148 
149  StateType returnval = Antioch::zero_clone(cache.T);
150  for (unsigned int i=begin_interval; i != end_interval; ++i)
151  {
152  const CoeffType * const a =
153  this->coefficients(i);
154  returnval = Antioch::if_else
155  (interval == i,
156  StateType(a[0] + a[1]*cache.T + a[2]*cache.T2 + a[3]*cache.T3 + a[4]*cache.T4),
157  returnval);
158  }
159 
160  return returnval;
161  }
162 
163  template<typename CoeffType>
164  template<typename StateType>
165  inline
167  {
168  typedef typename
170  const UIntType interval = this->interval(cache.T);
171  const unsigned int begin_interval = Antioch::min(interval);
172  const unsigned int end_interval = Antioch::max(interval)+1;
173 
174  StateType returnval = Antioch::zero_clone(cache.T);
175 
176  for (unsigned int i=begin_interval; i != end_interval; ++i)
177  {
178  const CoeffType *a = this->coefficients(interval);
179 
180  /* h/RT = a0 + a1*T/2 + a2*T^2/3 + a3*T^3/4 + a4*T^4/5 + a5/T */
181  returnval = Antioch::if_else
182  ( interval == i,
183  StateType( a[0] +
184  a[1]*cache.T/2.0L + a[2]*cache.T2/3.0L + a[3]*cache.T3/4.0L +
185  a[4]*cache.T4/5.0L + a[5]/cache.T),
186  returnval);
187  }
188  return returnval;
189  }
190 
191  template<typename CoeffType>
192  template<typename StateType>
193  inline
195  {
196  typedef typename
198  const UIntType interval = this->interval(cache.T);
199  const unsigned int begin_interval = Antioch::min(interval);
200  const unsigned int end_interval = Antioch::max(interval)+1;
201 
202  StateType returnval = Antioch::zero_clone(cache.T);
203 
204  for (unsigned int i=begin_interval; i != end_interval; ++i)
205  {
206  const CoeffType *a = this->coefficients(interval);
207 
208  /* s/R = a0*lnT + a1*T + a2*T^2/2 + a3*T^3/3 + a4*T^4/4 + a6 */
209  returnval = Antioch::if_else
210  ( interval == i,
211  StateType( a[0]*cache.lnT
212  + a[1]*cache.T + a[2]*cache.T2/2.0L + a[3]*cache.T3/3.0L
213  + a[4]*cache.T4/4.0L + a[6]),
214  returnval);
215  }
216  return returnval;
217  }
218 
219  template<typename CoeffType>
220  template<typename StateType>
221  inline
222  StateType
224  {
225  typedef typename
227  const UIntType interval = this->interval(cache.T);
228  const unsigned int begin_interval = Antioch::min(interval);
229  const unsigned int end_interval = Antioch::max(interval)+1;
230 
231  StateType returnval = Antioch::zero_clone(cache.T);
232 
233  for (unsigned int i=begin_interval; i != end_interval; ++i)
234  {
235  const CoeffType *a = this->coefficients(interval);
236 
237  /* h/RT = a[0] + a[1]*T/2. + a[2]*T2/3. + a[3]*T3/4. + a[4]*T4/5. + a[5]/T,
238  s/R = a[0]*lnT + a[1]*T + a[2]*T2/2. + a[3]*T3/3. + a[4]*T4/4. + a[6] */
239  returnval = Antioch::if_else
240  ( interval == i,
241  StateType(a[5]/cache.T - a[0]*cache.lnT
242  + a[0] - a[6]
243  - a[1]/2.L*cache.T - a[2]*cache.T2/6.L
244  - a[3]*cache.T3/12.L - a[4]*cache.T4/20.L),
245  returnval);
246  }
247  return returnval;
248  }
249 
250  template <typename CoeffType>
251  template <typename StateType>
252  inline
254  {
255  typedef typename
257  const UIntType interval = this->interval(cache.T);
258  const unsigned int begin_interval = Antioch::min(interval);
259  const unsigned int end_interval = Antioch::max(interval)+1;
260 
261  // FIXME - this needs expression templates to be faster...
262 
263  StateType returnval = Antioch::zero_clone(cache.T);
264 
265  /* 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[8]/T,
266  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[9] */
267  for (unsigned int i=begin_interval; i != end_interval; ++i)
268  {
269  const CoeffType * const a =
270  this->coefficients(i);
271  returnval = Antioch::if_else
272  (interval == i,
273  StateType(- a[5]/cache.T2 - a[0]/cache.T
274  - a[1]/2.L - a[2]*cache.T/3.L
275  - a[3]*cache.T2/4.L - a[4]*cache.T3/5.L),
276  returnval);
277  }
278 
279  return returnval;
280 
281  }
282 
283 } // end namespace Antioch
284 
285 #endif //ANTIOCH_NASA7_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
StateType s_over_R(const TempCache< StateType > &cache) const
const StateType & T
Definition: temp_cache.h:49
std::vector< CoeffType > _temp
The temperatures.
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_RT_minus_s_R(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 h_over_RT(const TempCache< StateType > &cache) const
const StateType cp_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.
NASA7CurveFit(const std::vector< CoeffType > &coeffs)
StateType dh_RT_minus_s_R_dT(const TempCache< StateType > &cache) const

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