FieldInterpolator.hpp

00001 #ifndef _FieldInterpolator_HPP
00002 #define _FieldInterpolator_HPP
00003 
00004 #include <fish/fiber/vector/Interpolate.hpp>
00005 #include <fish/fiber/vector/LinearIpol.hpp>
00006 #include <fish/fiber/vector/CubicIpol.hpp>
00007 #include <aerie/AnalyticFunction.hpp>
00008 
00009 namespace Fiber
00010 {
00011 
00012 class FieldInterpolatorBase
00013 {
00014 protected:
00015         RefPtr<Field> TheField;
00016 
00017 public:
00018         // supported interpolation types, used as template parameter in the FielInterpolator class
00019         enum InterpolType{LINEAR, CUBIC, ANALYTIC};
00020 
00021         FieldInterpolatorBase( RefPtr<Field>& TheFieldP )
00022         :TheField(TheFieldP)
00023         {}
00024 
00025         // convinience function
00026         RefPtr< MemBase > getArray( const pair<Eagle::PhysicalSpace::point, string>& localPoint, const double time )
00027         {
00028         const string&FragName = localPoint.second; 
00029                 //const Eagle::PhysicalSpace::point &float_index = localPoint.first; 
00030 
00031         RefPtr<FragmentID> FragID; 
00032 
00033                 if(FragName.compare("") != 0 )
00034                         FragID = new FragmentID( FragName ); 
00035                 
00036                 return TheField->getCreator( FragID )->create();
00037         }
00038 };
00039 
00044 template<typename FieldType,  typename CoordType, int InterpolType>
00045 class FieldInterpolator : public FieldInterpolatorBase
00046 {
00047 public:
00048         FieldInterpolator( RefPtr<Field>& TheFieldP )
00049         :FieldInterpolatorBase(TheFieldP)
00050         {}
00051 
00052         FieldType doIt( const pair<Eagle::PhysicalSpace::point, string>& localPoint, const CoordType& worldlocation, const double time )
00053         {
00054                 puts("template<FieldType>::Interpolator::doIt() no valid Interpolation type specialization"); 
00055 
00056         FieldType data; 
00057                 return data;
00058         }  
00059 };
00060 
00061 template<typename FieldType, typename CoordType>
00062 class FieldInterpolator<FieldType, CoordType, FieldInterpolatorBase::LINEAR> : public FieldInterpolatorBase
00063 {
00064         typedef Interpolate<CoordType::Dims, FieldType, LinearIpol< FieldType> > LinearInterpolator_t;
00065 public:
00066         FieldInterpolator( RefPtr<Field>& TheFieldP )
00067         :FieldInterpolatorBase(TheFieldP) {}
00068 
00071         FieldType doIt( const pair<Eagle::PhysicalSpace::point, string>& localPoint, const CoordType& worldlocation, const double time )
00072         {
00073         RefPtr<MemArray<CoordType::Dims, FieldType> > ToIntArr = getArray(localPoint, time); 
00074         assert( ToIntArr );
00075 
00076         FieldType data; 
00077         LinearInterpolator_t MyInterpolator(*ToIntArr, localPoint.first); 
00078 
00079                 data = MyInterpolator.eval(); 
00080 
00081                 return data;
00082         }
00083 };
00084 
00085 
00086 template<typename FieldType, typename CoordType>
00087 class FieldInterpolator<FieldType, CoordType, FieldInterpolatorBase::CUBIC> : public FieldInterpolatorBase
00088 {
00089         typedef Interpolate<CoordType::Dims, FieldType, CubicIpol< FieldType> > CubicInterpolator_t;
00090 public:
00091         FieldInterpolator( RefPtr<Field>& TheFieldP )
00092         :FieldInterpolatorBase(TheFieldP) {}
00093 
00096         FieldType doIt( const pair<Eagle::PhysicalSpace::point, string>& localPoint, const CoordType& worldlocation, const double time )
00097         {
00098         RefPtr<MemArray<CoordType::Dims, FieldType> > ToIntArr =getArray(localPoint, time); 
00099         assert( ToIntArr ); 
00100 
00101         FieldType data; 
00102 
00103         CubicInterpolator_t MyInterpolator(*ToIntArr, localPoint.first); 
00104                 data = MyInterpolator.eval(); 
00105 
00106                 return data;
00107         }       
00108 };
00109 
00110 template<typename FieldType, typename CoordType>
00111 class FieldInterpolator<FieldType, CoordType, FieldInterpolatorBase::ANALYTIC> : public FieldInterpolatorBase
00112 {
00113 typedef Eagle::PhysicalSpace::AnalyticFunction<FieldType> Eqn_t;
00114 
00115 public:
00116         FieldInterpolator( RefPtr<Field>& TheFieldP )
00117         :FieldInterpolatorBase(TheFieldP) {}
00118 
00121         FieldType doIt( const pair<Eagle::PhysicalSpace::point, string>& localPoint, const CoordType& worldlocation, const double time )
00122         {
00123         FieldType data; 
00124 
00125                 if ( MemCore::InterfacePtr<Eqn_t> AnalyticField = *TheField )
00126                 {
00127                 Eqn_t&AF = *AnalyticField; 
00128                         data = AF(time, worldlocation);
00129                 } 
00130                 else
00131                 {
00132                         puts("Interpolator<FieldType, Dims, InterpolatorBase::ANALYTIC>::doIt() ERROR: No analytic equation!");
00133                 } 
00134 
00135                 return data;
00136         }
00137 };
00138 
00139 } // namespace Fiber
00140 
00141 #endif //_FieldInterpolator_HPP