antioch-0.4.0
gsl_spliner.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 #include "antioch_config.h" //only of we have GSL
28 #ifdef ANTIOCH_HAVE_GSL
29 #ifndef ANTIOCH_GSL_SPLINER_H
30 #define ANTIOCH_GSL_SPLINER_H
31 
32 // Antioch
37 
38 namespace Antioch
39 {
41 
46  class GSLSpliner
47  {
48  public:
49 
51  GSLSpliner(){};
52 
54  template <typename VectorCoeffType>
55  GSLSpliner(const VectorCoeffType & data_x_point, const VectorCoeffType & data_y_point);
56 
58 
62  ~GSLSpliner(){};
63 
65 
69  template <typename VectorCoeffType>
70  void spline_init(const VectorCoeffType & data_x_point, const VectorCoeffType & data_y_point);
71 
73  void spline_delete();
74 
76 
80  template <typename StateType>
81  StateType interpolated_value(const StateType & x) const;
82 
84 
88  template <typename StateType>
89  StateType dinterp_dx(const StateType & x) const;
90 
91  private:
92 
94 
98  AntiochPrivate::GSLSplinerShim _gsl_shim;
99 
100  };
101 
102  template <typename VectorCoeffType>
103  inline
104  GSLSpliner::GSLSpliner(const VectorCoeffType & data_x_point, const VectorCoeffType & data_y_point)
105  {
106  this->spline_init(data_x_point, data_y_point);
107  }
108 
109  inline
110  void GSLSpliner::spline_delete()
111  {
112  _gsl_shim.spline_clear();
113  }
114 
115  template <typename VectorCoeffType>
116  inline
117  void GSLSpliner::spline_init(const VectorCoeffType & data_x_point, const VectorCoeffType & data_y_point)
118  {
119  antioch_assert_equal_to(data_x_point.size(), data_y_point.size());
120 
121  // GSL only accepts doubles, so need to cast
122  typedef typename rebind<VectorCoeffType,double>::type VectorGSLType;
123  VectorGSLType gsl_x_point(data_x_point.size(),0);
124  VectorGSLType gsl_y_point(data_y_point.size(),0);
125  for(unsigned int i = 0; i < data_x_point.size(); i++)
126  {
127  gsl_x_point[i] = (const double)data_x_point[i];
128  gsl_y_point[i] = (const double)data_y_point[i];
129  }
130 
131  const double * x = &gsl_x_point[0];
132  const double * y = &gsl_y_point[0];
133 
134  _gsl_shim.spline_init(x, y, data_x_point.size());
135  }
136 
137  template <typename StateType>
138  inline
139  StateType GSLSpliner::interpolated_value(const StateType & x) const
140  {
141  return AntiochPrivate::GSLSplinerPolicy<has_size<StateType>::value>().interpolation(x, _gsl_shim);
142  }
143 
144  template <typename StateType>
145  inline
146  StateType GSLSpliner::dinterp_dx(const StateType & x) const
147  {
148  return AntiochPrivate::GSLSplinerPolicy<has_size<StateType>::value>().dinterpolation(x, _gsl_shim);
149  }
150 
151 }
152 
153 #endif // ANTIOCH_GSL_SPLINE
154 
155 #endif// if ANTIOCH_HAVE_GSL
#define antioch_assert_equal_to(expr1, expr2)
The parameters are reduced parameters.

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