DeriveArray.hpp

00001 
00002 //
00003 // $Id: DeriveArray.hpp,v 1.2 2008/01/14 19:05:50 werner Exp $
00004 //
00006 #ifndef __FIBER_DERIVEARRAY_HPP
00007 #define __FIBER_DERIVEARRAY_HPP "Created 30.07.2006 22:30:21 by werner"
00008 
00009 #include "MultiArray.hpp"
00010 #include "IpolDelimiter.hpp"
00011 #include "Interpolate.hpp"
00012 
00013 namespace Fiber
00014 {
00015 
00019 template <class Interpol, int DerivativeDimension, class Delimiter = NoDelimiter<typename Interpol::value_type> >
00020 struct DeriveArray
00021 {
00022         template <int N, class Type> 
00023 static  void compute(MultiArray<N, Type>&result, const MultiArray<N, Type>&D)
00024         {
00025         MultiIndex<N>   idx;
00026         FixedArray<double, N> point; 
00027         Interpolate<N, Type, Interpol , double, Delimiter, DerivativeDimension> 
00028                 ipol(D, point); 
00029 
00030                 do
00031                 {
00032                         for(int i=0; i<N; i++)
00033                                 point[i] = idx[i];
00034 
00035                         result[ idx ] = ipol.eval();
00036                 }
00037                 while( idx.inc( D.Size() ) );
00038         }
00039 
00045         template <int N, class Type> 
00046 static  bool computeNthDerivative(MultiArray<N, Type>&result, const MultiArray<N, Type>&D, int NthDerivative)
00047         {
00048                 if (NthDerivative == DerivativeDimension)
00049                 {
00050                         compute( result, D); 
00051                         return true;
00052                 } 
00053                 return DeriveArray<Interpol, DerivativeDimension-1, Delimiter>::computeNthDerivative(result, D, NthDerivative); 
00054         }
00055 };
00056 
00057 template <class Interpol, class Delimiter>
00058 struct DeriveArray<Interpol, -1, Delimiter>
00059 {
00060         template <int N, class Type> 
00061 static  void compute(MultiArray<N, Type>&result, const MultiArray<N, Type>&D)
00062         {}
00063 
00064         template <int N, class Type> 
00065 static  bool computeNthDerivative(MultiArray<N, Type>&result, const MultiArray<N, Type>&D, int)
00066         {
00067                 return false;
00068         }
00069 };
00070 
00071 } // namespace Fiber
00072 
00073 #endif /* __Fiber_DERIVEARRAY_HPP */
00074