ArrayInterpolator.hpp

00001 
00002 //
00003 // $Id: ArrayInterpolator.hpp,v 1.1 2007/08/28 22:54:18 werner Exp $
00004 //
00006 #ifndef __FIBER_ARRAYINTERPOLATOR_HPP
00007 #define __FIBER_ARRAYINTERPOLATOR_HPP
00008 
00009 #include "FieldAPI.h"
00010 #include <memcore/RefPtr.hpp>
00011 #include <memcore/Interface.hpp>
00012 
00013 #include <vector/MultiArray.hpp>
00014 
00015 #include <typeinfo>
00016 
00017 namespace Fiber
00018 {
00019         using std::type_info;
00020 
00021         using MemCore::RefPtr;
00022         using MemCore::ReferenceBase;
00023 
00028 class FIELD_API ArrayInterpolator : public MemCore::Interface<ArrayInterpolator>
00029 {
00030 public:
00031         virtual ~ArrayInterpolator();
00032 
00034         virtual int  CoordRank() const = 0;
00035 
00037         virtual int  FieldRank() const = 0;
00038 
00039         virtual bool getInterpolatedValue(double result[], int nElements, const double coords[], int nCoords) const = 0;
00040 };
00041 
00045 template <int N>
00046 class FIELD_API DimensionalInterpolator : public ArrayInterpolator
00047 {
00048 public:
00049         typedef FixedArray<double, N> IpolPoint_t;
00050 
00051         virtual bool getValue(double result[], int nElements, const IpolPoint_t&P) const = 0; 
00052         
00053         override int  CoordRank() const
00054         {
00055                 return N;
00056         }
00057 
00058         override bool getInterpolatedValue(double result[], int nElements, const double coords[], int nCoords) const 
00059         {
00060                 if (nCoords != N) 
00061                         return false; 
00062 
00063                 return getValue( result, nElements, *(IpolPoint_t*)coords );
00064         }
00065 };
00066 
00067 #if 0
00068 template <int N, class T>
00069         class CubicInterpolator : public DimensionalInterpolator
00070         {
00071         public:
00072                 MemCore::WeakPtr<MemArray> myMemArray;
00073 
00074                 typedef Interpolate<N, T, CubicIpol<T>, double> CubicIpol_t;
00075 
00076                 StorageInterpolator(const MemCore::WeakPtr<MemArrayStorage>&MA)
00077                 : myMemArray(MA)
00078                 {}
00079 
00080                 ~StorageInterpolator()
00081                 {}
00082 
00083                 override int  FieldRank() const 
00084                 {
00085                 typedef FiberInfo<T> FiberInfo_t; 
00086                         return FiberInfo_t::MULTIPLICITY;
00087 //                      return myMemArray->getFiberType()->multiplicity();
00088                 }
00089 
00090                 override bool getValue(double result[], int nElements, const IpolPoint_t&P) const
00091                 {
00092                         if (!myMemArray) 
00093                                 return false;
00094 
00095                 CubicIpol_t ccip(myMemArray->myMultiArray, P); 
00096                 const T&t = ccip.eval(); 
00097                 int     i = 0; 
00098                 typedef FiberInfo<T> FiberInfo_t; 
00099 
00100                         for(; i<FiberInfo_t::MULTIPLICITY; i++)
00101                         {
00102                                 result[i] = FiberInfo_t::getComponent(t, i);
00103                         }
00104                         return true;
00105                 }
00106         };
00107 #endif
00108 
00109 
00110 } /* namespace Fiber */ 
00111 
00112 #endif /*  __FIBER_ARRAYINTERPOLATOR_HPP */
00113