|
Isis 3.0 Developer's Reference (API) |
Home |
00001 #ifndef NumericalApproximation_h 00002 #define NumericalApproximation_h 00003 00004 #include <string> 00005 #include <vector> 00006 #include <map> 00007 #include <gsl/gsl_errno.h> 00008 #include <gsl/gsl_spline.h> 00009 #include "IException.h" 00010 00011 using namespace std; 00012 00013 namespace Isis { 00720 class NumericalApproximation { 00721 public: 00725 enum InterpType { Linear, 00726 Polynomial, 00727 PolynomialNeville, 00728 CubicNatural, 00729 CubicClamped, 00730 CubicNatPeriodic, 00731 CubicNeighborhood, 00732 CubicHermite, 00733 Akima, 00734 AkimaPeriodic 00735 }; 00736 00737 // CONSTRUCTORS 00738 NumericalApproximation(const NumericalApproximation::InterpType &itype = CubicNatural); 00739 NumericalApproximation(unsigned int n, double *x, double *y, 00740 const NumericalApproximation::InterpType &itype = CubicNatural); 00741 NumericalApproximation(const vector <double> &x, const vector <double> &y, 00742 const NumericalApproximation::InterpType &itype = CubicNatural); 00743 NumericalApproximation(const NumericalApproximation &dint); 00744 // ASSIGNMENT OPERATOR 00745 NumericalApproximation &operator=(const NumericalApproximation &numApMeth); 00746 // DESTRUCTOR 00747 virtual ~NumericalApproximation(); 00748 00749 00750 // ACCESSOR METHODS FOR OBJECT PROPERTIES 00751 string Name() const; 00775 inline InterpType InterpolationType() { 00776 return (p_itype); 00777 } 00778 int MinPoints(); 00779 int MinPoints(NumericalApproximation::InterpType itype); 00780 00781 // ADD DATA TO OBJECT 00782 void AddData(const double x, const double y); 00783 void AddData(unsigned int n, double *x, double *y); 00784 void AddData(const vector <double> &x, const vector <double> &y); 00785 void SetCubicClampedEndptDeriv(const double yp1, const double ypn); 00786 void AddCubicHermiteDeriv(unsigned int n, double *fprimeOfx); 00787 void AddCubicHermiteDeriv(const vector <double> &fprimeOfx); 00788 void AddCubicHermiteDeriv(const double fprimeOfx); 00789 00790 //ACCESSOR METHODS AFTER DATA IS ENTERED 00791 double DomainMinimum(); 00792 double DomainMaximum(); 00793 bool Contains(double x); 00799 inline unsigned int Size() { 00800 return(p_x.size()); 00801 } 00802 00807 enum ExtrapType { ThrowError, 00808 Extrapolate, 00809 00810 00811 NearestEndpoint 00812 }; 00813 // INTERPOLATION AND EXTRAPOLATION RESULTS 00814 double Evaluate(const double a, const ExtrapType &etype = ThrowError); 00815 vector <double> Evaluate(const vector <double> &a, const ExtrapType &etype = ThrowError); 00816 vector <double> PolynomialNevilleErrorEstimate(); 00817 vector <double> CubicClampedSecondDerivatives(); 00818 double EvaluateCubicHermiteFirstDeriv(const double a); 00819 double EvaluateCubicHermiteSecDeriv(const double a); 00820 00821 // DIFFERENTIATION METHODS 00822 double GslFirstDerivative(const double a); 00823 double BackwardFirstDifference(const double a, const unsigned int n = 3, 00824 const double h = 0.1); 00825 double ForwardFirstDifference(const double a, const unsigned int n = 3, 00826 const double h = 0.1); 00827 double CenterFirstDifference(const double a, const unsigned int n = 5, 00828 const double h = 0.1); 00829 00830 double GslSecondDerivative(const double a); 00831 double BackwardSecondDifference(const double a, const unsigned int n = 3, 00832 const double h = 0.1); 00833 double ForwardSecondDifference(const double a, const unsigned int n = 3, 00834 const double h = 0.1); 00835 double CenterSecondDifference(const double a, const unsigned int n = 5, 00836 const double h = 0.1); 00837 00838 // INTERGRATION METHODS 00839 double GslIntegral(const double a, const double b); 00840 double TrapezoidalRule(const double a, const double b); 00841 double Simpsons3PointRule(const double a, const double b); 00842 double Simpsons4PointRule(const double a, const double b); 00843 double BoolesRule(const double a, const double b); 00844 double RefineExtendedTrap(double a, double b, double s, unsigned int n); 00845 double RombergsMethod(double a, double b); 00846 00847 // ASSIGNMENT OPERATORS 00848 void Reset(); 00849 void Reset(NumericalApproximation::InterpType itype); 00850 void SetInterpType(NumericalApproximation::InterpType itype); 00851 00852 protected: 00853 // == CLASS VARIABLES 00854 // VARIABLES FOR ALL INTERP TYPES 00855 InterpType p_itype; 00856 vector<double> p_x; 00857 vector<double> p_y; 00858 bool p_dataValidated; 00859 // GSL INTERP VARIABLES 00860 typedef const gsl_interp_type *InterpFunctor; 00861 typedef map<InterpType, InterpFunctor> FunctorList; 00862 typedef FunctorList::const_iterator FunctorConstIter; 00863 gsl_interp_accel *p_acc; 00864 gsl_spline *p_interp; 00865 static FunctorList p_interpFunctors; 00866 // CUBIC CLAMPED VARIABLES 00867 bool p_clampedEndptsSet; 00868 bool p_clampedComputed; 00869 double p_clampedDerivFirstPt; 00870 double p_clampedDerivLastPt; 00871 vector<double> p_clampedSecondDerivs; 00872 // POLYNOMIAL NEVILLE VARIABLES 00873 vector <double> p_polyNevError; 00874 // CUBIC HERMITE VARIABLES 00875 vector<double> p_fprimeOfx; 00876 00877 00878 // == PROTECTED METHODS 00879 // CREATING, DESTROYING OBJECT 00880 void Init(NumericalApproximation::InterpType itype); 00881 bool GslInterpType(NumericalApproximation::InterpType itype) const; 00882 void GslAllocation(unsigned int npoints); 00883 void GslDeallocation(); 00884 InterpFunctor GslFunctor(NumericalApproximation::InterpType itype) const; 00885 // VERIFICATION METHODS 00886 void GslIntegrityCheck(int gsl_status, const char *src, 00887 int line); 00888 void ValidateDataSet(); 00889 bool InsideDomain(const double a); 00890 // COMPUTATION AND EVALUATION METHODS 00891 bool GslComputed() const; 00892 void ComputeGsl(); 00893 void ComputeCubicClamped(); 00894 double ValueToExtrapolate(const double a, const ExtrapType &etype); 00895 double EvaluateCubicNeighborhood(const double a); 00896 vector <double> EvaluateCubicNeighborhood(const vector <double> &a, const ExtrapType &etype); 00897 double EvaluateCubicClamped(const double a); 00898 double EvaluateCubicHermite(const double a); 00899 double EvaluatePolynomialNeville(const double a); 00900 vector <double> EvaluateForIntegration(const double a, const double b, 00901 const unsigned int n); 00902 int FindIntervalLowerIndex(const double a); 00903 // STANDARDIZE ERRORS 00904 void ReportException(IException::ErrorType type, const string &method, 00905 const string &message, const char *filesrc, 00906 int lineno) const; 00907 }; 00908 }; 00909 00910 #endif