hierarchicalshapefunctions.hh

Go to the documentation of this file.
00001 // $Id: lagrangeshapefunctions.hh 411 2006-11-20 16:46:35Z oliver $
00002 
00003 #ifndef DUNE_HIERARCHICAL_SHAPEFUNCTIONS_HH
00004 #define DUNE_HIERARCHICAL_SHAPEFUNCTIONS_HH
00005 
00006 #include<iostream>
00007 #include<dune/common/fvector.hh>
00008 #include<dune/common/exceptions.hh>
00009 #include<dune/common/misc.hh>
00010 #include<dune/common/geometrytype.hh>
00011 
00012 #include"shapefunctions.hh"
00013 #include"hierarchical/hierarchicalcubeshapefunctions.hh"
00014 #include"hierarchical/hierarchicalsimplexshapefunctions.hh"
00015 #include"hierarchical/hierarchicalprismshapefunctions.hh"
00016 
00022 namespace Dune
00023 {
00029   /***********************************************************
00030    * The interface for Lagrange shape functions of arbitrary
00031    * order and element type.
00032    ***********************************************************/
00033 
00034 
00040   template<typename C, typename T, int d>
00041   class HierarchicalShapeFunction : public ShapeFunction<C,T,d,1>
00042   {
00043   public:
00044         // compile time sizes
00045         enum { dim=d };       
00046         enum { comps=1 };
00047         typedef C CoordType; 
00048         typedef T ResultType;
00049 
00051         virtual const FieldVector<CoordType,dim>& position () const = 0;
00052   };
00053 
00054 
00055 
00061   template<typename C, typename T, int d>
00062   class HierarchicalShapeFunctionSet : public ShapeFunctionSet<C,T,d,1>
00063   {
00064   public:
00065         // compile time sizes
00066         enum { dim=d };       
00067         enum { comps=1 };
00068 
00069         // exported types
00070         typedef C CoordType; 
00071         typedef T ResultType;
00072         typedef HierarchicalShapeFunction<CoordType,ResultType,dim> value_type;
00073 
00075         virtual const value_type& operator[] (int i) const = 0;
00076   };
00077 
00078 
00079   /***********************************************************
00080    * Wrappers
00081    * 
00082    ***********************************************************/
00083 
00088   template<typename Imp>
00089   class HierarchicalShapeFunctionWrapper : 
00090         public HierarchicalShapeFunction<typename Imp::CoordType,typename Imp::ResultType,Imp::dim>,
00091         private Imp
00092   {
00093   public:
00094 
00095         // compile time sizes
00096         enum { dim=Imp::dim };
00097         enum { comps=1 };
00098 
00099         // exported types
00100         typedef typename Imp::CoordType CoordType;
00101         typedef typename Imp::ResultType ResultType;
00102         typedef Imp ImplementationType;
00103 
00105         HierarchicalShapeFunctionWrapper& operator= (const Imp& imp)
00106         {
00107           Imp::operator=(imp);
00108           return *this;
00109         }
00110 
00112         virtual ResultType evaluateFunction (int comp, const FieldVector<CoordType,dim>& x) const
00113         {
00114           return Imp::evaluateFunction(comp,x);
00115         }
00116 
00118         virtual ResultType evaluateDerivative (int comp, int dir, const FieldVector<CoordType,dim>& x) const
00119         {
00120           return Imp::evaluateDerivative(comp,dir,x);
00121         }
00122 
00124         virtual int localindex (int comp) const
00125         {
00126           return Imp::localindex(comp);
00127         }
00128 
00130         virtual int codim () const
00131         {
00132           return Imp::codim();
00133         }
00134 
00136         virtual int entity () const
00137         {
00138           return Imp::entity();
00139         }
00140 
00142         virtual int entityindex () const
00143         {
00144           return Imp::entityindex();
00145         }
00146 
00148         virtual const FieldVector<CoordType,dim>& position () const
00149         {
00150           return Imp::position();
00151         }
00152   };
00153 
00154 
00155 
00156 
00161   template<typename Imp>
00162   class HierarchicalShapeFunctionSetWrapper : 
00163         public HierarchicalShapeFunctionSet<typename Imp::CoordType,typename Imp::ResultType,Imp::dim>,
00164         private Imp
00165   {
00166   public:
00167 
00168         // compile time sizes
00169         enum { dim=Imp::dim };
00170         enum { comps=1 };     // must be available at compile time
00171 
00172         // exported types
00173         typedef typename Imp::CoordType CoordType;
00174         typedef typename Imp::ResultType ResultType;
00175         typedef Imp ImplementationType;
00176         typedef HierarchicalShapeFunction<CoordType,ResultType,dim> value_type; // Note: Imp::value_type references
00177                                                       // must be convertible to references to 
00178                                                       // this type !
00180         virtual int size () const
00181         {
00182           return Imp::size();
00183         }
00184         
00186         virtual int size (int entity, int codim) const
00187         {
00188           return Imp::size(entity,codim);
00189         }
00190 
00192         virtual const value_type& operator[] (int i) const
00193         {
00194           return Imp::operator[](i);
00195         }
00196 
00198         virtual int order () const
00199         {
00200           return Imp::order();
00201         }
00202 
00204         virtual GeometryType type () const
00205         {
00206           return Imp::type();
00207         }
00208   };
00209 
00210 
00211  
00212   /***********************************************************
00213    * The general container for Hierarchical shape functions of
00214    * any order and element type (if someone implements them
00215    * in finite time). All containers are accessible in a singleton.
00216    ***********************************************************/
00217 
00223   template<typename C, typename T, int d>
00224   class HierarchicalShapeFunctionSetContainer : public ShapeFunctionSetContainer<C,T,d,1,Power_m_p<3,d>::power > 
00225   {
00226   public:
00227         // compile time sizes
00228         enum { dim=d };       
00229         enum { comps=1 };
00230         enum { maxsize=Power_m_p<3,dim>::power };
00231 
00232         // exported types
00233         typedef C CoordType; 
00234         typedef T ResultType;
00235 
00237         typedef HierarchicalShapeFunctionSet<C,T,d> value_type;
00238 
00239         const value_type& operator() (GeometryType type, int order) const
00240         {
00241             if ( type.isCube() )
00242                 {
00243                   if (order==2) return wrappedp2cube;
00244                   DUNE_THROW(RangeError, "order not available for cubes");
00245                 }
00246 
00247             if ( type.isSimplex() )
00248                 {
00249                   if (order==2) return wrappedp2simplex;
00250                   DUNE_THROW(RangeError, "order not available for simplex");
00251                 }
00252 
00253             if ( type.isPyramid() ) 
00254                 {
00255                   DUNE_THROW(RangeError, "No pyramid for this dimension");
00256                 }
00257 
00258             if ( type.isPrism() ) 
00259                 {
00260                         DUNE_THROW(RangeError, "No prism for this dimension ");
00261                 }
00262 
00263           DUNE_THROW(RangeError, "type or order not available");
00264         }
00265 
00266   private:
00267         // the cubes
00268         typedef HierarchicalShapeFunctionWrapper<P2HierarchicalCubeShapeFunction<C,T,d> > WrappedP2HierarchicalCubeShapeFunction;
00269         typedef P2HierarchicalCubeShapeFunctionSet<C,T,d,WrappedP2HierarchicalCubeShapeFunction> P2HierarchicalCubeWrappedShapeFunctionSet;
00270         typedef HierarchicalShapeFunctionSetWrapper<P2HierarchicalCubeWrappedShapeFunctionSet> WrappedP2HierarchicalCubeShapeFunctionSet;
00271         WrappedP2HierarchicalCubeShapeFunctionSet wrappedp2cube;
00272 
00273         // the simplices
00274     typedef HierarchicalShapeFunctionWrapper<P2HierarchicalSimplexShapeFunction<C,T,d> > WrappedP2HierarchicalSimplexShapeFunction;
00275     typedef P2HierarchicalSimplexShapeFunctionSet<C,T,d,WrappedP2HierarchicalSimplexShapeFunction> P2HierarchicalSimplexWrappedShapeFunctionSet;
00276     typedef HierarchicalShapeFunctionSetWrapper<P2HierarchicalSimplexWrappedShapeFunctionSet> WrappedP2HierarchicalSimplexShapeFunctionSet;
00277     WrappedP2HierarchicalSimplexShapeFunctionSet wrappedp2simplex;
00278   };
00279 
00281   template<typename C, typename T>
00282   class HierarchicalShapeFunctionSetContainer<C,T,3> : public ShapeFunctionSetContainer<C,T,3,1,Power_m_p<3,3>::power > 
00283   {
00284   public:
00285         // compile time sizes
00286         enum { dim=3 };       
00287         enum { comps=1 };
00288         enum { maxsize=Power_m_p<3,dim>::power };
00289 
00290         // exported types
00291         typedef C CoordType; 
00292         typedef T ResultType;
00293 
00295         typedef HierarchicalShapeFunctionSet<C,T,3> value_type;
00296 
00297         const value_type& operator() (GeometryType type, int order) const
00298         {
00299             if ( type.isCube() )
00300                 {
00301                   if (order==2) return wrappedp2cube;
00302                   DUNE_THROW(RangeError, "order not available for cubes");
00303                 }
00304 
00305             if ( type.isSimplex() )
00306                 {
00307                   if (order==2) return wrappedp2simplex;
00308                   DUNE_THROW(RangeError, "order not available for simplex");
00309                 }
00310 
00311             if (type.isPyramid() ) 
00312                 {
00313                   DUNE_THROW(RangeError, "order not available for pyramid");
00314                 }
00315 
00316             if (type.isPrism()) 
00317                 {
00318                   if (order==2) return wrappedp2prism;
00319                   else
00320                         DUNE_THROW(RangeError, "order not available for prism");
00321                 }
00322 
00323           DUNE_THROW(RangeError, "type or order not available");
00324         }
00325 
00326   private:
00327         // the cubes
00328         typedef HierarchicalShapeFunctionWrapper<P2HierarchicalCubeShapeFunction<C,T,dim> > WrappedP2HierarchicalCubeShapeFunction;
00329         typedef P2HierarchicalCubeShapeFunctionSet<C,T,dim,WrappedP2HierarchicalCubeShapeFunction> P2HierarchicalCubeWrappedShapeFunctionSet;
00330         typedef HierarchicalShapeFunctionSetWrapper<P2HierarchicalCubeWrappedShapeFunctionSet> WrappedP2HierarchicalCubeShapeFunctionSet;
00331         WrappedP2HierarchicalCubeShapeFunctionSet wrappedp2cube;
00332 
00333         // the simplices
00334     typedef HierarchicalShapeFunctionWrapper<P2HierarchicalSimplexShapeFunction<C,T,dim> > WrappedP2HierarchicalSimplexShapeFunction;
00335     typedef P2HierarchicalSimplexShapeFunctionSet<C,T,dim,WrappedP2HierarchicalSimplexShapeFunction> P2HierarchicalSimplexWrappedShapeFunctionSet;
00336     typedef HierarchicalShapeFunctionSetWrapper<P2HierarchicalSimplexWrappedShapeFunctionSet> WrappedP2HierarchicalSimplexShapeFunctionSet;
00337     WrappedP2HierarchicalSimplexShapeFunctionSet wrappedp2simplex;
00338 
00339       // The prism
00340     typedef HierarchicalShapeFunctionWrapper<P2HierarchicalPrismShapeFunction<C,T> > WrappedP2HierarchicalPrismShapeFunction;
00341     typedef P2HierarchicalPrismShapeFunctionSet<C,T,WrappedP2HierarchicalPrismShapeFunction> P2HierarchicalPrismWrappedShapeFunctionSet;
00342     typedef HierarchicalShapeFunctionSetWrapper<P2HierarchicalPrismWrappedShapeFunctionSet> WrappedP2HierarchicalPrismShapeFunctionSet;
00343     WrappedP2HierarchicalPrismShapeFunctionSet wrappedp2prism;
00344   };
00345 
00346 
00347     // singleton holding several reference element containers
00348     template<typename C, typename T, int d>
00349     struct HierarchicalShapeFunctions {
00350         static P2HierarchicalCubeShapeFunctionSetContainer<C,T,d> p2cube;
00351         static P2HierarchicalSimplexShapeFunctionSetContainer<C,T,d> p2simplex;
00352         static HierarchicalShapeFunctionSetContainer<C,T,d> general;
00353     };
00354 
00356 }
00357 #endif

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