cubeshapefunctions.hh

Go to the documentation of this file.
00001 // $Id: cubeshapefunctions.hh 336 2006-05-03 13:09:05Z oliver $
00002 
00003 #ifndef DUNE_CUBESHAPEFUNCTIONS_HH
00004 #define DUNE_CUBESHAPEFUNCTIONS_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 #include<dune/grid/common/referenceelements.hh>
00012 
00018 namespace Dune
00019 {
00030   /***********************************************************
00031    * P0 shape functions for the cube
00032    ***********************************************************/
00033 
00034 
00039   template<typename C, typename T, int d>
00040   class P0CubeShapeFunction
00041   {
00042   public:
00043 
00044         // compile time sizes
00045         enum { dim=d };    // maps from R^d
00046         enum { comps=1 };      // to R^1
00047 
00048         enum { m=1 }; // total number of basis functions
00049 
00050         // export types
00051         typedef C CoordType;
00052         typedef T ResultType;
00053         typedef P0CubeShapeFunction ImplementationType;
00054 
00056         P0CubeShapeFunction ()
00057         {
00058           for (int j=0; j<dim; j++)
00059                 pos[j] = 0.5;
00060         }
00061 
00063         ResultType evaluateFunction (int comp, const FieldVector<CoordType,d>& x) const
00064         {
00065           return 1;
00066         }
00067 
00069         ResultType evaluateDerivative (int comp, int dir, const FieldVector<CoordType,d>& x) const
00070         {
00071           return 0;
00072         }
00073 
00075         int localindex (int comp) const
00076         {
00077           return 0;
00078         }
00079 
00081         int codim () const
00082         {
00083           return 0;
00084         }
00085 
00087         int entity () const
00088         {
00089           return 0;
00090         }
00091 
00093         int entityindex () const
00094         {
00095           return 0;
00096         }
00097 
00099         const FieldVector<CoordType,dim>& position () const
00100         {
00101           return pos;
00102         }
00103         
00104   private:
00105         FieldVector<CoordType,d> pos;
00106   };
00107 
00108 
00113   template<typename C, typename T, int d, typename S>
00114   class P0CubeShapeFunctionSet
00115   {
00116   public:
00117 
00118         // compile time sizes
00119         enum { dim=d };    // maps from R^d
00120         enum { comps=1 };      // to R^1
00121 
00122         enum { m=1 }; // total number of basis functions
00123 
00124         // export types
00125         typedef C CoordType;
00126         typedef T ResultType;
00127         typedef S value_type;
00128         typedef typename S::ImplementationType Imp; // Imp is either S or derived from S
00129 
00131         P0CubeShapeFunctionSet ()
00132         {
00133           sf = Imp(); // assignment of derived class objects defined in wrapper
00134         }
00135 
00137         int size () const
00138         {
00139           return 1;
00140         }
00141 
00143         int size (int entity, int codim) const
00144         {
00145           if (codim==0) return 1; else return 0;
00146         }
00147         
00149         const value_type& operator[] (int i) const
00150         {
00151           return sf; // ok derived class reference goes for base class reference
00152         }
00153 
00155         int order () const
00156         {
00157           return 0;
00158         }
00159 
00161         GeometryType type () const
00162         {
00163       static GeometryType cube(GeometryType::cube, dim);
00164           return cube;
00165         }
00166 
00167   private:
00168         S sf;
00169   };
00170 
00171 
00172 
00174   template<typename C, typename T, int d>
00175   class P0CubeShapeFunctionSetContainer
00176   {
00177   public:
00178         // compile time sizes
00179         enum { dim=d };       
00180         enum { comps=1 };
00181         enum { maxsize=1 };
00182 
00183         // exported types
00184         typedef C CoordType; 
00185         typedef T ResultType;
00186         typedef P0CubeShapeFunctionSet<C,T,d,P0CubeShapeFunction<C,T,d> > value_type;
00187 
00188         const value_type& operator() (GeometryType type, int order) const
00189         {
00190       if (type.isCube()) return p0cube;
00191           DUNE_THROW(NotImplemented, "type not implemented yet");
00192         }
00193   private:
00194         value_type p0cube;
00195   };
00196  
00197 
00198 
00199   /***********************************************************
00200    * P1 shape functions for the cube of any dimension
00201    * The basic classes implement the interface of a 
00202    * LagrangeShapeFunction(Set) but are NOT derived from
00203    * it. They can be used in simple cases (fixed element type and
00204    * order) to avoid virtual function calls. The generally usable
00205    * classes are then wrapped up with the Wrappers to supply
00206    * the virtual functions of the abstract interface.
00207    ***********************************************************/
00208 
00226   template<typename C, typename T, int d>
00227   class P1CubeShapeFunction
00228   {
00229   public:
00230 
00231         // compile time sizes
00232         enum { dim=d };    // maps from R^d
00233         enum { comps=1 };      // to R^1
00234 
00235         enum { m=1<<dim }; // total number of basis functions
00236 
00237         // export types
00238         typedef C CoordType;
00239         typedef T ResultType;
00240         typedef P1CubeShapeFunction ImplementationType;
00241 
00243         P1CubeShapeFunction (int i) // make it the i'th shape function
00244         {
00245           number = i;
00246           //std::cout<<"number="<<number;
00247           for (int j=0; j<dim; j++)
00248                 {
00249                   a[j] = 1 - ((i>>j)&1);
00250                   b[j] = 2*((i>>j)&1) - 1;
00251                   pos[j] = (i>>j)&1;
00252                 }
00253         }
00254 
00256         P1CubeShapeFunction ()
00257     {}
00258 
00260         ResultType evaluateFunction (int comp, const FieldVector<CoordType,d>& x) const
00261         {
00262           ResultType phi = a[0]+x[0]*b[0];
00263           for (int j=1; j<dim; j++) phi *= a[j]+x[j]*b[j];
00264           return phi;
00265         }
00266 
00268         ResultType evaluateDerivative (int comp, int dir, const FieldVector<CoordType,d>& x) const
00269         {
00270           ResultType deriv = b[dir];
00271           for (int j=0; j<dim; j++)
00272                 if (j!=dir) deriv *= a[j]+x[j]*b[j];
00273           return deriv;
00274         }
00275 
00277         int localindex (int comp) const
00278         {
00279           return number;
00280         }
00281 
00283         int codim () const
00284         {
00285           return dim;
00286         }
00287 
00289         int entity () const
00290         {
00291           return number;
00292         }
00293 
00295         int entityindex () const
00296         {
00297           return 0;
00298         }
00299 
00301         const FieldVector<CoordType,dim>& position () const
00302         {
00303           return pos;
00304         }
00305         
00306   private:
00307         int number;
00308         ResultType a[dim], b[dim]; // store coefficients for this shape function
00309         FieldVector<CoordType,d> pos;
00310   };
00311 
00312 
00317   template<typename C, typename T, int d, typename S>
00318   class P1CubeShapeFunctionSet
00319   {
00320   public:
00321 
00322         // compile time sizes
00323         enum { dim=d };    // maps from R^d
00324         enum { comps=1 };      // to R^1
00325 
00326         enum { m=1<<dim }; // total number of basis functions
00327 
00328         // export types
00329         typedef C CoordType;
00330         typedef T ResultType;
00331         typedef S value_type;
00332         typedef typename S::ImplementationType Imp; // Imp is either S or derived from S
00333 
00335         P1CubeShapeFunctionSet ()
00336         {
00337           for (int i=0; i<m; i++)
00338                 sf[i] = Imp(i); // assignment of derived class objects defined in wrapper
00339         }
00340 
00342         int size () const
00343         {
00344           return m;
00345         }
00346 
00348         int size (int entity, int codim) const
00349         {
00350           if (codim==dim) return 1; else return 0;
00351         }
00352         
00354         const value_type& operator[] (int i) const
00355         {
00356           return sf[i]; // ok derived class reference goes for base class reference
00357         }
00358 
00360         int order () const
00361         {
00362           return 1;
00363         }
00364 
00366         GeometryType type () const
00367         {
00368       static GeometryType cube(GeometryType::cube, dim);
00369           return cube;
00370         }
00371 
00372   private:
00373         S sf[m];
00374   };
00375 
00376 
00377 
00379   template<typename C, typename T, int d>
00380   class P1CubeShapeFunctionSetContainer
00381   {
00382   public:
00383         // compile time sizes
00384         enum { dim=d };       
00385         enum { comps=1 };
00386         enum { maxsize=1<<dim };
00387 
00388         // exported types
00389         typedef C CoordType; 
00390         typedef T ResultType;
00391         typedef P1CubeShapeFunctionSet<C,T,d,P1CubeShapeFunction<C,T,d> > value_type;
00392 
00393         const value_type& operator() (GeometryType type, int order) const
00394         {
00395       if (type.isCube()) return p1cube;
00396           DUNE_THROW(NotImplemented, "type not implemented yet");
00397         }
00398   private:
00399         value_type p1cube;
00400   };
00401  
00402 
00403 
00404 
00405   /***********************************************************
00406    * P2 shape functions for the cube of any dimension
00407    ***********************************************************/
00408 
00419   template<typename C, typename T, int d>
00420   class P2CubeShapeFunction
00421   {
00422   public:
00423 
00424         // compile time sizes
00425         enum { dim=d };    // maps from R^d
00426         enum { comps=1 };      // to R^1
00427 
00428         enum { m=Power_m_p<3,d>::power }; // total number of basis functions
00429 
00430         // export types
00431         typedef C CoordType;
00432         typedef T ResultType;
00433         typedef P2CubeShapeFunction ImplementationType;
00434 
00436         P2CubeShapeFunction (int no, int en, int co, const FieldVector<int,dim>& ipos) // make it the i'th shape function
00437         {
00438           num = no;
00439           ent = en;
00440           cod = co;
00441           for (int j=0; j<dim; j++)
00442                 {
00443                   if (ipos[j]==0)
00444                         {
00445                           a[j] = 1.0; 
00446                           b[j] = -3.0;
00447                           c[j] = 2.0;
00448                           pos[j] = 0;
00449                         }
00450                   if (ipos[j]==1)
00451                         {
00452                           a[j] = 0.0; 
00453                           b[j] = 4.0;
00454                           c[j] = -4.0;
00455                           pos[j] = 0.5;
00456                         }
00457                   if (ipos[j]==2)
00458                         {
00459                           a[j] = 0.0; 
00460                           b[j] = -1.0;
00461                           c[j] = 2.0;
00462                           pos[j] = 1.0;
00463                         }
00464                 }
00465         }
00466 
00468         P2CubeShapeFunction ()
00469         {       }
00470 
00472         ResultType evaluateFunction (int comp, const FieldVector<CoordType,d>& x) const
00473         {
00474           ResultType phi = a[0]+x[0]*b[0] +x[0]*x[0]*c[0];
00475           for (int j=1; j<dim; j++) phi *= a[j]+x[j]*b[j]+x[j]*x[j]*c[j];
00476           return phi;
00477         }
00478 
00480         ResultType evaluateDerivative (int comp, int dir, const FieldVector<CoordType,d>& x) const
00481         {
00482           ResultType deriv = b[dir]+2*c[dir]*x[dir];
00483           for (int j=0; j<dim; j++)
00484                 if (j!=dir) deriv *= a[j]+x[j]*b[j]+x[j]*x[j]*c[j];
00485           return deriv;
00486         }
00487 
00489         int localindex (int comp) const
00490         {
00491           return num;
00492         }
00493 
00495         int codim () const
00496         {
00497           return cod;
00498         }
00499 
00501         int entity () const
00502         {
00503           return ent;
00504         }
00505 
00507         int entityindex () const
00508         {
00509           return 0;
00510         }
00511 
00513         const FieldVector<CoordType,dim>& position () const
00514         {
00515           return pos;
00516         }
00517         
00518   private:
00519         int num;
00520         int ent;
00521         int cod;
00522         ResultType a[dim], b[dim], c[dim]; // store coefficients for this shape function
00523         FieldVector<CoordType,d> pos;
00524   };
00525 
00526 
00531   template<typename C, typename T, int d, typename S>
00532   class P2CubeShapeFunctionSet
00533   {
00534   public:
00535 
00536         // compile time sizes
00537         enum { dim=d };    // maps from R^d
00538         enum { comps=1 };      // to R^1
00539 
00540         enum { m=Power_m_p<3,d>::power }; // total number of basis functions
00541 
00542         // export types
00543         typedef C CoordType;
00544         typedef T ResultType;
00545         typedef S value_type;
00546         typedef typename S::ImplementationType Imp; // Imp is either S or derived from S
00547 
00549         P2CubeShapeFunctionSet ()
00550         {
00551           ReferenceCube<C,d> cube;
00552           int i=0;
00553           for (int c=0; c<=dim; c++)
00554                 for (int e=0; e<cube.size(c); e++)
00555                   {
00556                         sf[i] = Imp(i,e,c,cube.iposition(e,c));
00557                         i++;
00558                   }
00559         }
00560 
00562         int size () const
00563         {
00564           return m;
00565         }
00566 
00568         int size (int entity, int codim) const
00569         {
00570           return 1;
00571         }
00572         
00574         const value_type& operator[] (int i) const
00575         {
00576           return sf[i]; // ok derived class reference goes for base class reference
00577         }
00578 
00580         int order () const
00581         {
00582           return 2;
00583         }
00584 
00586         GeometryType type () const
00587         {
00588       static GeometryType cube(GeometryType::cube, dim);
00589           return cube;
00590         }
00591 
00592   private:
00593         S sf[m];
00594   };
00595 
00596 
00598   template<typename C, typename T, int d>
00599   class P2CubeShapeFunctionSetContainer
00600   {
00601   public:
00602         // compile time sizes
00603         enum { dim=d };       
00604         enum { comps=1 };
00605         enum { maxsize=Power_m_p<3,d>::power };
00606 
00607         // exported types
00608         typedef C CoordType; 
00609         typedef T ResultType;
00610         typedef P2CubeShapeFunctionSet<C,T,d,P2CubeShapeFunction<C,T,d> > value_type;
00611 
00612         const value_type& operator() (GeometryType type, int order) const
00613         {
00614       if (type.isCube()) return p2cube;
00615           DUNE_THROW(NotImplemented, "type not implemented yet");
00616         }
00617   private:
00618         value_type p2cube;
00619   };
00620  
00621 
00622 
00624 }
00625 #endif

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