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