Interpolate.hpp

00001 
00002 //
00003 // $Id: Interpolate.hpp,v 1.5 2007/12/28 13:50:49 werner Exp $
00004 //
00006 #ifndef __FIBER_ARRAY_INTERPOLATE_HPP
00007 #define __FIBER_ARRAY_INTERPOLATE_HPP "Created 3.07.2004 21:42:21 by bzfbenge"
00008 
00009 #include <iostream>
00010 
00011 #include "VVector.hpp"
00012 #include "MultiArray.hpp"
00013 #include "IpolDelimiter.hpp"
00014 
00015 namespace Fiber
00016 {
00017 
00018         using namespace std;
00019 
00033 template <class T, class Interpol1D, bool Derive=false>
00034 class   IpolDerivative
00035 {
00036 public:
00037         template <class Storage1D, class Limiter>
00038 static  T interpolate(const Storage1D&Data, double t, index_t size, const Limiter&L)
00039         {
00040 //              printf("IpolDerivative, non ipol, at %.20lg\n", t);
00041                 return Interpol1D::interpolate(Data,t,size,L);
00042         }
00043 };
00044 
00049 template <class T, class Interpol1D>
00050 class   IpolDerivative<T, Interpol1D, true>
00051 {
00052 public:
00053         template <class Storage1D, class Limiter>
00054 static  T interpolate(const Storage1D&Data, double t, index_t size, const Limiter&L)
00055         {
00056                 return Interpol1D::derivative(Data,t,size,L);
00057         }
00058 };
00059 
00060 
00064 template <int N, class Type, class Interpol, class CoordinateType = double,
00065                  class Delimiter = NoDelimiter<Type>, int DerivativeDimension=-1 >
00066 struct Interpolate;
00067 
00076 template <class Type, class Interpol, class CoordinateType, class Delimiter, int DerivativeDimension>
00077 struct Interpolate<1, Type, Interpol, CoordinateType, Delimiter, DerivativeDimension>
00078 {
00079         enum { Dims = 1 };
00080 
00081         typedef Type value_type;
00082         typedef MultiArray<Dims, Type> MultiArray_t;
00083 
00084         typedef FixedArray<CoordinateType,Dims> Point_t;
00085 
00086 private:
00087         const MultiArray_t&M;
00088         const Point_t     &Point;
00089 
00090 public: Delimiter myDelimiter;
00091 
00092         Interpolate(const MultiArray_t&m,
00093                     const Point_t&point)
00094         : M(m), Point(point)
00095         {}
00096 
00097         Interpolate(const MultiArray_t&m,
00098                     const Point_t&point,
00099                     const Delimiter&myDeli)
00100         : M(m), Point(point), myDelimiter(myDeli)
00101         {}
00102 
00103         Type operator[](index_t i) const
00104         {
00105         //      printf("\nInterpolate<1D, DerivativeDimension=%d>: Slice %d\n", DerivativeDimension, i);
00106 #if 0
00107                 Type T = IpolDerivative<Type, Interpol, 0==DerivativeDimension>::
00108 			 interpolate(M, Point[0],  M.Extension()[0], myDelimiter ); 
00109                 cout << "Interpolate<1D> at " << Point << " yields " << T << endl;
00110                 return T;
00111 #else
00112                 return IpolDerivative<Type, Interpol, 0==DerivativeDimension>::
00113 			interpolate(M, Point[0],  M.Extension()[0], myDelimiter );
00114 #endif
00115         }
00116 
00117         index_t size() const
00118         {
00119                 return M.Extension().maxidx();
00120         }
00121 
00122 
00123         Type eval() const
00124         {
00125         //      printf("\nInterpolate<DerivativeDimension=%d> Eval\n", DerivativeDimension);
00126 
00127                 return IpolDerivative<Type, Interpol, 0==DerivativeDimension>::
00128 			interpolate(M, Point[0],  M.Extension()[0], myDelimiter );
00129         }
00130 };
00131 
00132 
00136 template <class Type, class Interpol, class CoordinateType, class Delimiter, int DerivativeDimension>
00137 struct Interpolate<2, Type, Interpol, CoordinateType, Delimiter, DerivativeDimension>
00138 {
00139         enum { Dims = 2 };
00140 
00141         typedef Type value_type;
00142         typedef MultiArray<Dims, Type> MultiArray_t;
00143         typedef FixedArray<CoordinateType, Dims> Point_t;
00144         typedef typename MultiArray_t::SliceStorage_t SliceStorage_t;
00145 
00146 private:
00147         const MultiArray_t &M;
00148         const Point_t      &Point;
00149 
00150 public: Delimiter myDelimiter;
00151 
00152         Interpolate(const MultiArray_t&m,
00153                     const Point_t     &point)
00154         : M(m), Point(point)
00155         {}
00156 
00157         Interpolate(const MultiArray_t&m,
00158                     const Point_t     &point,
00159                     const Delimiter&myDeli)
00160         : M(m), Point(point), myDelimiter(myDeli)
00161         {}
00162 
00163         Type operator[](index_t i) const
00164         {
00165         MultiArray<1, Type> Sub = M[i]; 
00166 
00167         //      printf("\nInterpolate<2D, DerivativeDimension=%d, Type=%s>: slice %d, at %lg\n", 
00168         //             DerivativeDimension, typeid(Type).name(), i, double(Point[0]) );
00169 #if 0
00170                 Type T = IpolDerivative<Type, Interpol, 0==DerivativeDimension>::
00171 			 interpolate(Sub, Point[0],  M.Size()[0], myDelimiter ); 
00172 
00173                 cout << "Interpolate2D<" << typeid(Interpol).name() << "> at " << Point << "  yields " << T << endl; 
00174                 cout << " IArray " << M << endl;
00175 
00176                 return T;
00177 #else
00178                 return IpolDerivative<Type, Interpol, 0==DerivativeDimension>::
00179 			interpolate(Sub, Point[0],  M.Size()[0], myDelimiter );
00180 #endif
00181         }
00182 
00183         index_t size() const
00184         {
00185                 return M.Size()[1];
00186         }
00187 
00188         Type eval() const
00189         {
00190 //              printf("\nInterpolate<DerivativeDimension=%d> Eval\n", DerivativeDimension);
00191 
00192                 return IpolDerivative<Type, Interpol, 1==DerivativeDimension>::
00193 			interpolate(*this, Point[1],  M.Size()[1], myDelimiter );
00194         }
00195 };
00196 
00278 template <int N, class Type, class Interpol, class CoordinateType, 
00279           class Delimiter, int DerivativeDimension>
00280 struct Interpolate
00281 {
00282         enum { Dims = N };
00283 
00284         typedef Type value_type;
00285         typedef MultiArray<N, Type> MultiArray_t;
00286         typedef typename MultiArray_t::Hyperslab_t SliceStorage_t;
00287         typedef FixedArray<CoordinateType, N> Point_t;
00288         typedef FixedArray<CoordinateType, N-1> SubPoint_t;
00289 
00290 private:
00291         const MultiArray<N, Type>&M;
00292         const Point_t&Point;
00293 
00294 public: Delimiter myDelimiter;
00295 
00296         const MultiArray<N, Type>&MArray()
00297         {
00298                 return M;
00299         }
00300 
00301 
00307         Interpolate(const MultiArray_t&m,
00308                     const Point_t&point)
00309         : M(m), Point(point)
00310         {}
00311 
00317         Interpolate(const MultiArray_t&m,
00318                     const Eagle::VVector<N , CoordinateType>&point)
00319         : M(m), Point(point.vec() )
00320         {}
00321 
00322         Interpolate(const MultiArray_t&m,
00323                     const FixedArray<CoordinateType,N>&point,
00324                     const Delimiter&myDeli)
00325         : M(m), Point(point), myDelimiter(myDeli) 
00326         {}
00327 
00328         Interpolate(const MultiArray_t&m,
00329                     const Eagle::VVector<N , CoordinateType>&point,
00330                     const Delimiter&myDeli)
00331         : M(m), Point(point.vec() ), myDelimiter(myDeli) 
00332         {}
00333 
00334 
00340         Type operator[](index_t i) const
00341         {
00342         MultiArray <N-1, Type> Slice = M[i]; 
00343 
00344         const SubPoint_t&subP = Point.get_subdim();
00345 
00346         Interpolate<N-1, Type, Interpol, CoordinateType, Delimiter, DerivativeDimension> 
00347 
00348                 LI( Slice, subP, myDelimiter ); 
00349 
00350 //              printf("\nInterpolate<%dD (rec), DerivativeDimension=%d>: Slice %d\n", N, DerivativeDimension, i);
00351 
00352                 return IpolDerivative<Type, Interpol, N-2==DerivativeDimension>::
00353 				interpolate(LI, Point[N-2],  M.Size()[N-2], this->myDelimiter );
00354         }
00355 
00356         index_t size() const
00357         {
00358                 return M.Extension()[N-1];
00359         }
00360 
00361         Type eval() const
00362         {
00363 //              printf("\nInterpolateN<DerivativeDimension=%d> Eval at %lg\n", DerivativeDimension, double(Point[N-1]) );
00364                 return IpolDerivative<Type, Interpol, N-1==DerivativeDimension>::
00365 			interpolate(*this, Point[N-1],  M.Size()[N-1], myDelimiter );
00366         }
00367 
00368         Type operator()() const
00369         {
00370                 return eval();
00371         }
00372 };
00373 
00374 
00375 } /* namespace Fiber */ 
00376 
00377 #endif /* __FIBER_ARRAY_INTERPOLATE_HPP */
00378