All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CubicInterpolation.h
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #ifndef __PLUMED_tools_CubicInterpolation_h
23 #define __PLUMED_tools_CubicInterpolation_h
24 
25 #include <vector>
26 #include "Matrix.h"
27 #include "core/Value.h"
28 
29 namespace PLMD {
30 
31 // Abstract base class for cubic interpolation
33 private:
34  unsigned bold;
36  unsigned search1( const unsigned& kk, const double& x, const unsigned& jold ) const ;
37 protected:
38  std::vector<double> lb, ub;
39  std::vector<unsigned> np, stride;
40  unsigned findBox( const std::vector<double>& pos );
41  double getPointSpacing( const unsigned dir, const unsigned k ) const ;
42  double getCrossTermDenominator( const unsigned i, const unsigned j ) const ;
43 public:
44  CInterpolation( const std::vector<unsigned>& dd, const std::vector<double>& fmin, const std::vector<double>& fmax );
45  virtual ~CInterpolation();
46  unsigned getNumberOfSplinePoints() const ;
47  void getNumbersOfPoints( std::vector<unsigned>& nspline ) const ;
48  void getSplinePoint( const unsigned nn, std::vector<double>& pp ) const ;
49  void getGridBoundaries( std::vector<double>& gmin, std::vector<double>& gmax ) const ;
50  virtual void set_table( const std::vector<Value>& ff )=0;
51  virtual double get_fdf( const std::vector<double>& pos )=0;
52 };
53 
54 inline
56  return splinepoints.nrows();
57 }
58 
59 inline
60 void CInterpolation::getSplinePoint( const unsigned nn, std::vector<double>& pp ) const {
61  plumed_dbg_assert( nn<splinepoints.nrows() && pp.size()==np.size() );
62  for(unsigned i=0;i<np.size();++i) pp[i]=splinepoints(nn,i);
63 }
64 
65 inline
66 double CInterpolation::getPointSpacing( const unsigned dir, const unsigned k ) const {
67  unsigned i=k*stride[dir];
68  return splinepoints(i+stride[dir], dir) - splinepoints(i, dir);
69 }
70 
71 inline
72 double CInterpolation::getCrossTermDenominator( const unsigned i, const unsigned j ) const {
73  plumed_dbg_assert( splinepoints.ncols()==2 );
74  unsigned iplus, iminus; iplus=(i+1)*stride[0]; iminus=(i-1)*stride[0];
75  return ( splinepoints(iplus,0) - splinepoints(iminus,0) ) * ( splinepoints(iplus+j+1,1) - splinepoints(iplus+j-1,1) );
76 }
77 
78 inline
79 void CInterpolation::getGridBoundaries( std::vector<double>& gmin, std::vector<double>& gmax ) const {
80  getSplinePoint( 0, gmin ); getSplinePoint( splinepoints.nrows()-1, gmax );
81 }
82 
84 private:
85  std::vector<double> clist;
86 public:
87  InterpolateCubic( const std::vector<unsigned>& dd, const std::vector<double>& fmin, const std::vector<double>& fmax );
88  void set_table( const std::vector<Value>& ff );
89  double get_fdf( const std::vector<double>& pos );
90 };
91 
93 private:
95  std::vector<double> t1, t2;
97  std::vector<double> clist;
98  void IBicCoeff( const std::vector<double>& y, const std::vector<double>& dy1, const std::vector<double>& dy2,
99  const std::vector<double>& d2y12, const double& d1, const double& d2, Matrix<double>& c );
100 public:
101  InterpolateBicubic( const std::vector<unsigned>& dd, const std::vector<double>& fmin, const std::vector<double>& fmax );
102  void set_table( const std::vector<Value>& ff );
103  double get_fdf( const std::vector<double>& pos );
104 };
105 
106 }
107 
108 
109 #endif
virtual void set_table(const std::vector< Value > &ff)=0
double getPointSpacing(const unsigned dir, const unsigned k) const
Matrix< double > splinepoints
unsigned ncols() const
Return the number of columns.
Definition: Matrix.h:110
double getCrossTermDenominator(const unsigned i, const unsigned j) const
InterpolateBicubic(const std::vector< unsigned > &dd, const std::vector< double > &fmin, const std::vector< double > &fmax)
std::vector< double > t2
double get_fdf(const std::vector< double > &pos)
std::vector< double > clist
void set_table(const std::vector< Value > &ff)
void getNumbersOfPoints(std::vector< unsigned > &nspline) const
std::vector< unsigned > np
unsigned findBox(const std::vector< double > &pos)
unsigned search1(const unsigned &kk, const double &x, const unsigned &jold) const
virtual double get_fdf(const std::vector< double > &pos)=0
unsigned nrows() const
Return the number of rows.
Definition: Matrix.h:108
std::vector< double > lb
std::vector< unsigned > stride
double get_fdf(const std::vector< double > &pos)
unsigned getNumberOfSplinePoints() const
std::vector< double > clist
std::vector< double > ub
std::vector< double > t1
void set_table(const std::vector< Value > &ff)
void getGridBoundaries(std::vector< double > &gmin, std::vector< double > &gmax) const
void getSplinePoint(const unsigned nn, std::vector< double > &pp) const
CInterpolation(const std::vector< unsigned > &dd, const std::vector< double > &fmin, const std::vector< double > &fmax)
void IBicCoeff(const std::vector< double > &y, const std::vector< double > &dy1, const std::vector< double > &dy2, const std::vector< double > &d2y12, const double &d1, const double &d2, Matrix< double > &c)
InterpolateCubic(const std::vector< unsigned > &dd, const std::vector< double > &fmin, const std::vector< double > &fmax)