antioch-0.4.0
nasa_curve_fit_base.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_NASA_CURVE_FIT_BASE_H
28 #define ANTIOCH_NASA_CURVE_FIT_BASE_H
29 
30 // Antioch
32 #include "antioch/metaprogramming_decl.h" // Antioch::rebind
34 
35 // C++
36 #include <vector>
37 #include <sstream>
38 
39 namespace Antioch
40 {
41  template<typename CoeffType=double>
43  {
44  public:
45 
46  NASACurveFitBase( const std::vector<CoeffType>& coeffs, const std::vector<CoeffType>& temp );
47 
49 
51  unsigned int n_intervals() const;
52 
54 
58  template <typename StateType>
60  interval(const StateType& T) const;
61 
63 
66  const CoeffType* coefficients(const unsigned int interval) const;
67 
68  protected:
69 
71 
72  void check_coeff_size() const;
73 
75 
77  unsigned int _n_coeffs;
78 
80 
85  std::vector<CoeffType> _coefficients;
86 
88 
91  std::vector<CoeffType> _temp;
92 
93  };
94 
95  template<typename CoeffType>
96  inline
97  NASACurveFitBase<CoeffType>::NASACurveFitBase( const std::vector<CoeffType>& coeffs,
98  const std::vector<CoeffType>& temp )
99  : _n_coeffs(0),
100  _coefficients(coeffs),
101  _temp(temp)
102  {}
103 
104  template<typename CoeffType>
105  inline
107  { return _coefficients.size() / _n_coeffs; }
108 
109  template<typename CoeffType>
110  template<typename StateType>
111  inline
113  NASACurveFitBase<CoeffType>::interval(const StateType& T) const
114  {
115  typedef typename
117  UIntType interval;
118  Antioch::zero_clone(interval, T);
119 
120  for(unsigned int i = 1; i < _temp.size(); ++i)
121  {
122  interval = Antioch::if_else
123  (T > _temp[i-1] && T < _temp[i],
124  Antioch::constant_clone(interval, i-1),
125  interval );
126  }
127 
128  return interval;
129  }
130 
131  template<typename CoeffType>
132  inline
133  const CoeffType* NASACurveFitBase<CoeffType>::coefficients(const unsigned int interval) const
134  {
135  antioch_assert_less( interval, this->n_intervals() );
136  antioch_assert_less_equal( _n_coeffs*(interval+1), _coefficients.size() );
137 
138  return &_coefficients[_n_coeffs*interval];
139  }
140 
141  template<typename CoeffType>
142  inline
144  {
145  if( this->_coefficients.size()%this->_n_coeffs != 0 )
146  {
147  std::stringstream ncs;
148  ncs << this->_n_coeffs;
149 
150  std::stringstream css;
151  css << this->_coefficients.size()%this->_n_coeffs;
152 
153  std::string msg = "ERROR: coeffs size must be a multiple of "+ncs.str()+"\n";
154  msg += " Found "+css.str()+"\n";
155  antioch_error_msg(msg);
156  }
157  }
158 
159  template<typename CoeffType>
160  inline
162  {
163  if( this->_temp.size() != this->_coefficients.size()/this->_n_coeffs + 1 )
164  {
165  std::stringstream tss;
166  tss << this->_temp.size();
167 
168  std::stringstream css;
169  css << this->_coefficients.size();
170 
171  std::stringstream cssd;
172  cssd << this->_n_coeffs*(this->_temp.size()-1);
173 
174  std::string msg = "ERROR: Inconsistency in temp and coeff size.\n";
175  msg += " Found temp size of "+tss.str()+"\n";
176  msg += " Found coeff size of "+css.str()+"\n";
177  msg += " Expected coeff size of "+cssd.str()+"\n";
178  antioch_error_msg(msg);
179  }
180  }
181 
182 } // end namespace Antioch
183 
184 #endif // ANTIOCH_NASA_CURVE_FIT_BASE_H
const CoeffType * coefficients(const unsigned int interval) const
The ordering/packing of the coefficients will depend on the subclass.
void check_temp_coeff_size_consistency() const
#define antioch_assert_less(expr1, expr2)
std::vector< CoeffType > _temp
The temperatures.
#define antioch_assert_less_equal(expr1, expr2)
Antioch::rebind< StateType, unsigned int >::type interval(const StateType &T) const
The interval the input temperature lies in.
_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
#define antioch_error_msg(errmsg)
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
unsigned int n_intervals() const
The number of intervals for this NASA9 curve fit.
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.
std::vector< CoeffType > _coefficients
The coefficient data.

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