interp2.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2014-2017, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file interp2.h
24  \brief File defining \ref o2scl::interp2_base
25 */
26 #ifndef O2SCL_INTERP2_H
27 #define O2SCL_INTERP2_H
28 
29 #include <boost/numeric/ublas/vector.hpp>
30 #include <boost/numeric/ublas/matrix.hpp>
31 
32 #ifndef DOXYGEN_NO_O2NS
33 namespace o2scl {
34 #endif
35 
36  /** \brief Two-dimensional interpolation base class [abstract]
37  */
38  template<class vec_t=boost::numeric::ublas::vector<double>,
39  class mat_t=boost::numeric::ublas::matrix<double> >
40  class interp2_base {
41 
42 #ifdef O2SCL_NEVER_DEFINED
43  }{
44 #endif
45 
46  public:
47 
48  interp2_base() {
49  }
50 
51  virtual ~interp2_base() {
52  }
53 
54  /** \brief Perform the 2-d interpolation
55  */
56  virtual double eval(double x, double y) const=0;
57 
58  /** \brief Perform the 2-d interpolation
59  */
60  virtual double operator()(double x, double y) const {
61  return eval(x,y);
62  }
63 
64  /** \brief Compute the partial derivative in the x-direction
65  */
66  virtual double deriv_x(double x, double y) const=0;
67 
68  /** \brief Compute the partial second derivative in the x-direction
69  */
70  virtual double deriv_xx(double x, double y) const=0;
71 
72  /** \brief Compute the integral in the x-direction between x=x0
73  and x=x1
74  */
75  virtual double integ_x(double x0, double x1, double y) const=0;
76 
77  /** \brief Compute the partial derivative in the y-direction
78  */
79  virtual double deriv_y(double x, double y) const=0;
80 
81  /** \brief Compute the partial second derivative in the y-direction
82  */
83  virtual double deriv_yy(double x, double y) const=0;
84 
85  /** \brief Compute the integral in the y-direction between y=y0
86  and y=y1
87  */
88  virtual double integ_y(double x, double y0, double y1) const=0;
89 
90  /** \brief Compute the mixed partial derivative
91  \f$ \frac{\partial^2 f}{\partial x \partial y} \f$
92  */
93  virtual double deriv_xy(double x, double y) const=0;
94 
95  /** \brief Compute a general interpolation result
96 
97  This computes
98  \f[
99  \frac{\partial^m}{\partial x^m}
100  \frac{\partial^n}{\partial y^n} f(x,y)
101  \f]
102  for \f$ m \in (-1,0,1,2) \f$ and \f$ n \in (-1,0,1,2) \f$ with
103  the notation
104  \f{eqnarray*}
105  \frac{\partial^{-1}}{\partial x^{-1}}
106  &\equiv & \int_{x_0}^{x_1} f~dx \nonumber \\
107  \frac{\partial^0}{\partial x^0} &\equiv &
108  \left.f\right|_{x=x_0} \nonumber \\
109  \frac{\partial^1}{\partial x^1} &\equiv &
110  \left(\frac{\partial f}{\partial x}\right)_{x=x_0} \nonumber \\
111  \frac{\partial^2}{\partial x^2} &\equiv &
112  \left(\frac{\partial^2 f}{\partial x^2}\right)_{x=x_0}
113  \f}
114  and the value of \f$ x_1 \f$ is ignored when \f$ m \geq 0 \f$
115  and the value of \f$ y_1 \f$ is ignored when \f$ n \geq 0 \f$.
116  */
117  virtual double eval_gen(int ix, int iy, double x0, double x1,
118  double y0, double y1) const=0;
119 
120 #ifndef DOXYGEN_INTERNAL
121 
122  protected:
123 
124  /// The number of x grid points
125  size_t nx;
126 
127  /// The number of y grid points
128  size_t ny;
129 
130  /// The x grid
131  vec_t *xfun;
132 
133  /// The y grid
134  vec_t *yfun;
135 
136  /// The data
137  mat_t *datap;
138 
139  private:
140 
143 
144 #endif
145 
146  };
147 
148 #ifndef DOXYGEN_NO_O2NS
149 }
150 #endif
151 
152 #endif
153 
154 
155 
virtual double operator()(double x, double y) const
Perform the 2-d interpolation.
Definition: interp2.h:60
virtual double eval_gen(int ix, int iy, double x0, double x1, double y0, double y1) const =0
Compute a general interpolation result.
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
size_t ny
The number of y grid points.
Definition: interp2.h:128
virtual double deriv_xy(double x, double y) const =0
Compute the mixed partial derivative .
virtual double deriv_x(double x, double y) const =0
Compute the partial derivative in the x-direction.
virtual double integ_y(double x, double y0, double y1) const =0
Compute the integral in the y-direction between y=y0 and y=y1.
virtual double deriv_yy(double x, double y) const =0
Compute the partial second derivative in the y-direction.
virtual double integ_x(double x0, double x1, double y) const =0
Compute the integral in the x-direction between x=x0 and x=x1.
mat_t * datap
The data.
Definition: interp2.h:137
virtual double deriv_y(double x, double y) const =0
Compute the partial derivative in the y-direction.
size_t nx
The number of x grid points.
Definition: interp2.h:125
virtual double deriv_xx(double x, double y) const =0
Compute the partial second derivative in the x-direction.
virtual double eval(double x, double y) const =0
Perform the 2-d interpolation.
vec_t * xfun
The x grid.
Definition: interp2.h:131
vec_t * yfun
The y grid.
Definition: interp2.h:134
Two-dimensional interpolation base class [abstract].
Definition: interp2.h:40
static const double x1[5]
Definition: inte_qng_gsl.h:48

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).