Isis 3 Developer Reference
NumericalApproximation.h
Go to the documentation of this file.
1 #ifndef NumericalApproximation_h
2 #define NumericalApproximation_h
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <gsl/gsl_errno.h>
8 #include <gsl/gsl_spline.h>
9 #include "IException.h"
10 
11 using namespace std;
12 
13 namespace Isis {
721  public:
734  AkimaPeriodic
735  };
736 
737  // CONSTRUCTORS
738  NumericalApproximation(const NumericalApproximation::InterpType &itype = CubicNatural);
739  NumericalApproximation(unsigned int n, double *x, double *y,
740  const NumericalApproximation::InterpType &itype = CubicNatural);
741  NumericalApproximation(const vector <double> &x, const vector <double> &y,
742  const NumericalApproximation::InterpType &itype = CubicNatural);
744  // ASSIGNMENT OPERATOR
745  NumericalApproximation &operator=(const NumericalApproximation &numApMeth);
746  // DESTRUCTOR
747  virtual ~NumericalApproximation();
748 
749 
750  // ACCESSOR METHODS FOR OBJECT PROPERTIES
751  string Name() const;
776  return (p_itype);
777  }
778  int MinPoints();
779  int MinPoints(NumericalApproximation::InterpType itype);
780 
781  // ADD DATA TO OBJECT
782  void AddData(const double x, const double y);
783  void AddData(unsigned int n, double *x, double *y);
784  void AddData(const vector <double> &x, const vector <double> &y);
785  void SetCubicClampedEndptDeriv(const double yp1, const double ypn);
786  void AddCubicHermiteDeriv(unsigned int n, double *fprimeOfx);
787  void AddCubicHermiteDeriv(const vector <double> &fprimeOfx);
788  void AddCubicHermiteDeriv(const double fprimeOfx);
789 
790  //ACCESSOR METHODS AFTER DATA IS ENTERED
791  double DomainMinimum();
792  double DomainMaximum();
793  bool Contains(double x);
799  inline unsigned int Size() {
800  return(p_x.size());
801  }
802 
808  Extrapolate,
809  NearestEndpoint
812  };
813  // INTERPOLATION AND EXTRAPOLATION RESULTS
814  double Evaluate(const double a, const ExtrapType &etype = ThrowError);
815  vector <double> Evaluate(const vector <double> &a, const ExtrapType &etype = ThrowError);
816  vector <double> PolynomialNevilleErrorEstimate();
817  vector <double> CubicClampedSecondDerivatives();
818  double EvaluateCubicHermiteFirstDeriv(const double a);
819  double EvaluateCubicHermiteSecDeriv(const double a);
820 
821  // DIFFERENTIATION METHODS
822  double GslFirstDerivative(const double a);
823  double BackwardFirstDifference(const double a, const unsigned int n = 3,
824  const double h = 0.1);
825  double ForwardFirstDifference(const double a, const unsigned int n = 3,
826  const double h = 0.1);
827  double CenterFirstDifference(const double a, const unsigned int n = 5,
828  const double h = 0.1);
829 
830  double GslSecondDerivative(const double a);
831  double BackwardSecondDifference(const double a, const unsigned int n = 3,
832  const double h = 0.1);
833  double ForwardSecondDifference(const double a, const unsigned int n = 3,
834  const double h = 0.1);
835  double CenterSecondDifference(const double a, const unsigned int n = 5,
836  const double h = 0.1);
837 
838  // INTERGRATION METHODS
839  double GslIntegral(const double a, const double b);
840  double TrapezoidalRule(const double a, const double b);
841  double Simpsons3PointRule(const double a, const double b);
842  double Simpsons4PointRule(const double a, const double b);
843  double BoolesRule(const double a, const double b);
844  double RefineExtendedTrap(double a, double b, double s, unsigned int n);
845  double RombergsMethod(double a, double b);
846 
847  // ASSIGNMENT OPERATORS
848  void Reset();
849  void Reset(NumericalApproximation::InterpType itype);
850  void SetInterpType(NumericalApproximation::InterpType itype);
851 
852  protected:
853  // == CLASS VARIABLES
854  // VARIABLES FOR ALL INTERP TYPES
856  vector<double> p_x;
857  vector<double> p_y;
859  // GSL INTERP VARIABLES
860  typedef const gsl_interp_type *InterpFunctor;
861  typedef map<InterpType, InterpFunctor> FunctorList;
862  typedef FunctorList::const_iterator FunctorConstIter;
863  gsl_interp_accel *p_acc;
864  gsl_spline *p_interp;
866  // CUBIC CLAMPED VARIABLES
871  vector<double> p_clampedSecondDerivs;
872  // POLYNOMIAL NEVILLE VARIABLES
873  vector <double> p_polyNevError;
874  // CUBIC HERMITE VARIABLES
875  vector<double> p_fprimeOfx;
876 
877 
878  // == PROTECTED METHODS
879  // CREATING, DESTROYING OBJECT
880  void Init(NumericalApproximation::InterpType itype);
881  bool GslInterpType(NumericalApproximation::InterpType itype) const;
882  void GslAllocation(unsigned int npoints);
883  void GslDeallocation();
884  InterpFunctor GslFunctor(NumericalApproximation::InterpType itype) const;
885  // VERIFICATION METHODS
886  void GslIntegrityCheck(int gsl_status, const char *src,
887  int line);
888  void ValidateDataSet();
889  bool InsideDomain(const double a);
890  // COMPUTATION AND EVALUATION METHODS
891  bool GslComputed() const;
892  void ComputeGsl();
893  void ComputeCubicClamped();
894  double ValueToExtrapolate(const double a, const ExtrapType &etype);
895  double EvaluateCubicNeighborhood(const double a);
896  vector <double> EvaluateCubicNeighborhood(const vector <double> &a, const ExtrapType &etype);
897  double EvaluateCubicClamped(const double a);
898  double EvaluateCubicHermite(const double a);
899  double EvaluatePolynomialNeville(const double a);
900  vector <double> EvaluateForIntegration(const double a, const double b,
901  const unsigned int n);
902  int FindIntervalLowerIndex(const double a);
903  // STANDARDIZE ERRORS
904  void ReportException(IException::ErrorType type, const string &method,
905  const string &message, const char *filesrc,
906  int lineno) const;
907  };
908 };
909 
910 #endif
bool p_clampedEndptsSet
Flag variable to determine whether SetCubicClampedEndptDeriv() has been called after all data was add...
Definition: NumericalApproximation.h:867
vector< double > p_x
List of X values.
Definition: NumericalApproximation.h:856
InterpType
This enum defines the types of interpolation supported in this class.
Definition: NumericalApproximation.h:725
vector< double > p_fprimeOfx
List of first derivatives corresponding to each x value in the data set (i.e. each value in p_x) ...
Definition: NumericalApproximation.h:875
double p_clampedDerivFirstPt
First derivative of first x-value, p_x[0]. This is only used for the CubicClamped interpolation type...
Definition: NumericalApproximation.h:869
Cubic Spline interpolation using 4-pt Neighborhoods with natural boundary conditions.
Definition: NumericalApproximation.h:731
Namespace for the standard library.
Polynomial interpolation.
Definition: NumericalApproximation.h:726
NumericalApproximation provides various numerical analysis methods of interpolation, extrapolation and approximation of a tabulated set of x, y data.
Definition: NumericalApproximation.h:720
Cubic Spline interpolation with natural boundary conditions.
Definition: NumericalApproximation.h:728
Cubic Spline interpolation with periodic boundary conditions.
Definition: NumericalApproximation.h:730
map< InterpType, InterpFunctor > FunctorList
Set up a std::map of GSL interpolator functors. List of function types.
Definition: NumericalApproximation.h:861
Cubic Spline interpolation using the Hermite cubic polynomial.
Definition: NumericalApproximation.h:732
vector< double > p_clampedSecondDerivs
List of second derivatives evaluated at p_x values. This is only used for the CubicClamped interpolat...
Definition: NumericalApproximation.h:871
Linear interpolation.
Definition: NumericalApproximation.h:725
ExtrapType
This enum defines the manner in which a value outside of the domain should be handled if passed to th...
Definition: NumericalApproximation.h:807
Cubic Spline interpolation with clamped boundary conditions.
Definition: NumericalApproximation.h:729
Polynomial interpolation using Neville&#39;s algorithm.
Definition: NumericalApproximation.h:727
double p_clampedDerivLastPt
First derivative of last x-value, p_x[n-1]. This is only used for the CubicClamped interpolation type...
Definition: NumericalApproximation.h:870
static FunctorList p_interpFunctors
Maintains list of interpolator options.
Definition: NumericalApproximation.h:865
const gsl_interp_type * InterpFunctor
GSL Interpolation specs.
Definition: NumericalApproximation.h:860
Non-rounded Akima Spline interpolation with natural boundary conditions.
Definition: NumericalApproximation.h:733
ErrorType
Contains a set of exception error types.
Definition: IException.h:127
bool p_dataValidated
Flag variable to determine whether ValidateDataSet() has been called.
Definition: NumericalApproximation.h:858
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
vector< double > p_y
List of Y values.
Definition: NumericalApproximation.h:857
vector< double > p_polyNevError
Estimate of error for interpolation evaluated at x. This is only used for the PolynomialNeville inter...
Definition: NumericalApproximation.h:873
InterpType p_itype
Interpolation type.
Definition: NumericalApproximation.h:855
gsl_interp_accel * p_acc
Lookup accelorator.
Definition: NumericalApproximation.h:863
FunctorList::const_iterator FunctorConstIter
GSL Iterator.
Definition: NumericalApproximation.h:862
unsigned int Size()
Returns the number of the coordinates added to the data set.
Definition: NumericalApproximation.h:799
bool p_clampedComputed
Flag variable to determine whether ComputeCubicClamped() has been called.
Definition: NumericalApproximation.h:868
Evaluate() throws an error if a is outside of the domain.
Definition: NumericalApproximation.h:807
InterpType InterpolationType()
Returns the enumerated type of interpolation chosen.
Definition: NumericalApproximation.h:775
gsl_spline * p_interp
Currently active interpolator.
Definition: NumericalApproximation.h:864