adapter.hh

00001 // $Id: adapter.hh 524 2008-11-23 19:11:42Z christi $
00002 
00003 #ifndef DUNE_FUNCTION_ADAPTER_HH
00004 #define DUNE_FUNCTION_ADAPTER_HH
00005 
00006 #include"functions.hh"
00007 
00008 namespace Dune
00009 {
00010   
00014   template<class G, class RT, int m=1>
00015   class GridFunctionAdapter :
00016     virtual public GridFunction<G,RT,m>,
00017     virtual public GridFunctionDefault<G,RT,m>,
00018     virtual public FunctionDefault<typename G::ctype,RT,G::dimension,m>
00019   {
00021         typedef typename G::ctype DT;
00022 
00024         typedef typename G::template Codim<0>::Entity Entity;
00025 
00027         enum {n=G::dimension};
00028 
00030         enum {dimw=G::dimensionworld};
00031 
00033         GridFunctionAdapter (const GridFunctionAdapter&);
00034   public:
00036     GridFunctionAdapter(const FunctionBase<DT,RT,n,m>& f) : _fnkt(f) {};
00037 
00038     // forward the evaluation to _fnkt
00039         virtual RT eval (int comp, const Dune::FieldVector<DT,n>& x) const
00040         {
00041       return _fnkt.eval(comp, x);
00042         }
00043 
00045     template<class IS>
00046     typename VTKWriter<IS>::VTKFunction *
00047     vtkFunction (VTKWriter<IS>& vtkwriter, std::string s) const
00048         {
00049           return new VTKGridFunctionWrapper<IS,RT,m>(*this,s);
00050         }
00051         
00052   private:
00053     const FunctionBase<DT,RT,n,m>& _fnkt;
00054   };
00055 
00059   template<class G, class RT, int m=1>
00060   class DifferentiableGridFunctionAdapter :
00061     virtual public GridFunction<G,RT,m>,
00062     virtual public DifferentiableGridFunction<G,RT,m>,
00063     virtual public GridFunctionDefault<G,RT,m>,
00064     virtual public DifferentiableGridFunctionDefault<G,RT,m>,
00065     virtual public FunctionDefault<typename G::ctype,RT,G::dimension,m>
00066   {
00068         typedef typename G::ctype DT;
00069 
00071         typedef typename G::template Codim<0>::Entity Entity;
00072 
00074         enum {n=G::dimension};
00075 
00077         enum {dimw=G::dimensionworld};
00078 
00080         DifferentiableGridFunctionAdapter (const DifferentiableGridFunctionAdapter&);
00081   public:
00083     DifferentiableGridFunctionAdapter(const DifferentiableFunction<DT,RT,n,m>& f) : _fnkt(f) {};
00084 
00085     // forward the evaluation to _fnkt
00086         virtual RT eval (int comp, const Dune::FieldVector<DT,n>& x) const
00087         {
00088       return _fnkt.eval(comp, x);
00089         }
00090 
00091     // forward the derivative to _fnkt
00092         virtual RT derivative (int comp, const Dune::FieldVector<int,n>& d, const Dune::FieldVector<DT,n>& x) const
00093         {
00094       return _fnkt.derivative(comp, d, x);
00095         }
00096 
00097     // forward to _fnkt
00098         virtual int order () const
00099         {
00100       return _fnkt.order();
00101         }
00102     
00104     template<class IS>
00105     typename VTKWriter<IS>::VTKFunction *
00106     vtkFunction (VTKWriter<IS>& vtkwriter, std::string s) const
00107         {
00108           return new VTKGridFunctionWrapper<IS,RT,m>(*this,s);
00109         }
00110         
00111   private:
00112     const DifferentiableFunction<DT,RT,n,m>& _fnkt;
00113   };
00114 
00118   template<class G, class RT, int m=1>
00119   class GridLevelLeafFunctionAdapter :
00120     virtual public GridFunction<G,RT,m>,
00121     virtual public GridFunctionDefault<G,RT,m>,
00122     virtual public FunctionDefault<typename G::ctype,RT,G::dimension,m>
00123   {
00125         typedef typename G::ctype DT;
00126 
00128         typedef typename G::template Codim<0>::Entity Entity;
00129 
00131         typedef typename G::template Codim<0>::EntityPointer EntityPointer;
00132 
00134         enum {n=G::dimension};
00135 
00137         enum {dimw=G::dimensionworld};
00138 
00140         GridLevelLeafFunctionAdapter (const GridLevelLeafFunctionAdapter&);
00141   public:
00143     GridLevelLeafFunctionAdapter(const GridFunction<G,RT,m>& f, int l) : _fnkt(f), _level(l) {};
00144 
00146     // forward the evaluation to _fnkt
00147         virtual RT eval (int comp, const Dune::FieldVector<DT,n>& x) const
00148         {
00149       return _fnkt.eval(comp, x);
00150         }
00151 
00153         RT evallocal (int comp, const Entity& e, const Dune::FieldVector<DT,n>& xi) const
00154         {
00155       assert(e.level() >= _level);
00156       if (e.level() > _level)
00157       {
00158         return evallocal(comp, *(e.father()), e.geometryInFather().global(xi));
00159       }
00160       return _fnkt.evallocal(comp, e, xi);
00161         }
00162 
00164     template<class IS>
00165     typename VTKWriter<IS>::VTKFunction *
00166     vtkFunction (VTKWriter<IS>& vtkwriter, std::string s) const
00167         {
00168           return new VTKGridFunctionWrapper<IS,RT,m>(*this,s);
00169         }
00170         
00171   private:
00172     const GridFunction<G,RT,m>& _fnkt;
00173     int _level;
00174   };
00175 
00179   template<class G, class IS, class RT, int m=1>
00180   class GridLeafFunctionAdapter :
00181     virtual public GridFunction<G,RT,m>,
00182     virtual public GridFunctionDefault<G,RT,m>,
00183     virtual public FunctionDefault<typename G::ctype,RT,G::dimension,m>
00184   {
00186         typedef typename G::ctype DT;
00187 
00189         typedef typename G::template Codim<0>::LeafIndexSet ISX;
00190 
00192         typedef typename G::template Codim<0>::Entity Entity;
00193 
00195         typedef typename G::template Codim<0>::EntityPointer EntityPointer;
00196 
00198         enum {n=G::dimension};
00199 
00201         enum {dimw=G::dimensionworld};
00202 
00204         GridLeafFunctionAdapter (const GridLeafFunctionAdapter&);
00205   public:
00207     GridLeafFunctionAdapter(const GridFunction<G,RT,m>& f, const IS & is) : _fnkt(f), _is(is) {};
00208 
00210     // forward the evaluation to _fnkt
00211         virtual RT eval (int comp, const Dune::FieldVector<DT,n>& x) const
00212         {
00213       return _fnkt.eval(comp, x);
00214         }
00215 
00217         RT evallocal (int comp, const Entity& e, const Dune::FieldVector<DT,n>& xi) const
00218         {
00219       if (! _is.contains(e))
00220       {
00221         return evallocal(comp, *(e.father()), e.geometryInFather().global(xi));
00222       }
00223       return _fnkt.evallocal(comp, e, xi);
00224         }
00225 
00227     template<class GV>
00228     typename VTKWriter<GV>::VTKFunction *
00229     vtkFunction (VTKWriter<GV>& vtkwriter, std::string s) const
00230         {
00231           return new VTKGridFunctionWrapper<GV,RT,m>(*this,s);
00232         }
00233         
00234   private:
00235     const GridFunction<G,RT,m>& _fnkt;
00236     const IS & _is;
00237   };
00238 
00242   template<class G, class RT>
00243   class GridFunctionGradient :
00244     virtual public GridFunction<G,RT,G::dimension>,
00245     virtual public GridFunctionDefault<G,RT,G::dimension>,
00246     virtual public FunctionDefault<typename G::ctype,RT,G::dimension,G::dimension>
00247   {
00249         typedef typename G::ctype DT;
00250 
00252         typedef typename G::template Codim<0>::Entity Entity;
00253 
00255         enum {n=G::dimension};
00256 
00258         enum {m=G::dimension};
00259 
00261         enum {dimw=G::dimensionworld};
00262 
00264         GridFunctionGradient (const GridFunctionGradient&);
00265   public:
00267     GridFunctionGradient(const DifferentiableGridFunction<G,RT,1>& f) : _fnkt(f) {};
00268 
00269     // forward the evaluation to _fnkt
00270         virtual RT evallocal (int comp, const Entity& e, const Dune::FieldVector<DT,n>& xi) const
00271         {
00272       Dune::FieldVector<int,n> d(0);
00273       d[comp] = 1;
00274       return _fnkt.derivativelocal(0, d, e, xi);
00275         }
00276 
00277     // forward the evaluation to _fnkt
00278         virtual RT eval (int comp, const Dune::FieldVector<DT,n>& x) const
00279         {
00280       Dune::FieldVector<int,n> d(0);
00281       d[comp] = 1;
00282       return _fnkt.derivative(0, d, x);
00283         }
00284 
00285   private:
00286     const DifferentiableGridFunction<G,RT,1>& _fnkt;
00287   };  
00288   
00292   template<class G, class RT, int m>
00293   class GridFunctionMinus :
00294     virtual public GridFunction<G,RT,m>,
00295     virtual public GridFunctionDefault<G,RT,m>,
00296     virtual public FunctionDefault<typename G::ctype,RT,G::dimension,m>
00297   {
00299         typedef typename G::ctype DT;
00300 
00302         typedef typename G::template Codim<0>::Entity Entity;
00303 
00305         enum {n=G::dimension};
00306 
00308         enum {dimw=G::dimensionworld};
00309 
00311         GridFunctionMinus (const GridFunctionMinus&);
00312   public:
00314     GridFunctionMinus(const GridFunction<G,RT,m>& f) : _fnkt(f) {};
00315 
00316     // forward the evaluation to _fnkt
00317         virtual RT evallocal (int comp, const Entity& e, const Dune::FieldVector<DT,n>& xi) const
00318         {
00319       return - _fnkt.evallocal(comp, e, xi);
00320         }
00321 
00322     // forward the evaluation to _fnkt
00323         virtual RT eval (int comp, const Dune::FieldVector<DT,n>& x) const
00324         {
00325       return - _fnkt.eval(comp, x);
00326         }
00327 
00328   private:
00329     const GridFunction<G,RT,m>& _fnkt;
00330   };  
00331   
00332 } // end namespace Dune
00333 
00334 #endif // DUNE_FUNCTION_ADAPTER_HH

Generated on 6 Jan 2009 with Doxygen (ver 1.5.1) [logfile].