scsgmapper.hh

Go to the documentation of this file.
00001 // $Id: scsgmapper.hh 4374 2008-09-08 14:10:22Z mnolte $
00002 
00003 #ifndef DUNE_SCSGMAPPER_HH
00004 #define DUNE_SCSGMAPPER_HH
00005 
00006 #include<iostream>
00007 #include "mapper.hh"
00008 
00009 #include <dune/grid/common/grid.hh>
00010 
00017 namespace Dune
00018 {
00042   template <typename G, typename IS, int c>
00043   class SingleCodimSingleGeomTypeMapper : Mapper<G,SingleCodimSingleGeomTypeMapper<G,IS,c> > {
00044   public:
00045 
00052         SingleCodimSingleGeomTypeMapper (const G& grid, const IS& indexset);
00053 
00059         template<class EntityType>
00060         int map (const EntityType& e) const;
00061   
00068         template<int cc>
00069         int map (const typename G::Traits::template Codim<0>::Entity& e, int i) const; 
00070 
00079         int size () const;
00080 
00087         template<class EntityType>
00088         bool contains (const EntityType& e, int& result) const;
00089 
00097         template<int cc> // this is now the subentity's codim
00098         bool contains (const typename G::Traits::template Codim<0>::Entity& e, int i, int& result) const;
00099 
00102         void update ()
00103         { // nothing to do here
00104         }
00105  
00106   private:
00107         const G& g;
00108         const IS& is;
00109   };
00110 
00113   template <typename G, typename IS, int c>
00114   SingleCodimSingleGeomTypeMapper<G,IS,c>::SingleCodimSingleGeomTypeMapper (const G& grid, const IS& indexset) 
00115         : g(grid), is(indexset)
00116   {
00117         // check that grid has only a single geometry type
00118         if (is.geomTypes(c).size() != 1)
00119                 DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type");
00120   }
00121 
00122   template <typename G, typename IS, int c>
00123   template<class EntityType>
00124   int SingleCodimSingleGeomTypeMapper<G,IS,c>::map (const EntityType& e) const
00125   {
00126         enum { cc = EntityType::codimension };
00127         dune_static_assert(cc == c, "Entity of wrong codim passed to SingleCodimSingleGeomTypeMapper");
00128         return is.template index<cc>(e);
00129   }
00130 
00131   template <typename G, typename IS, int c>
00132   template<int cc>
00133   int SingleCodimSingleGeomTypeMapper<G,IS,c>::map (const typename G::Traits::template Codim<0>::Entity& e, int i) const
00134   {
00135         dune_static_assert(cc == c, "Id of wrong codim requested from SingleCodimSingleGeomTypeMapper");
00136         return is.template subIndex<cc>(e,i);
00137   }
00138 
00139   template <typename G, typename IS, int c>
00140   int SingleCodimSingleGeomTypeMapper<G,IS,c>::size () const
00141   {
00142         return is.size(c,is.geomTypes(c)[0]);
00143   }
00144 
00145   template <typename G, typename IS, int c>
00146   template<class EntityType>
00147   bool SingleCodimSingleGeomTypeMapper<G,IS,c>::contains (const EntityType& e, int& result) const
00148   {
00149         result = map(e);
00150         return true;
00151   }
00152 
00153   template <typename G, typename IS, int c>
00154   template<int cc>
00155   bool SingleCodimSingleGeomTypeMapper<G,IS,c>::contains (const typename G::Traits::template Codim<0>::Entity& e, int i, int& result) const
00156   {
00157         result = this->template map<cc>(e,i);
00158         return true;
00159   }
00160 
00179   template <typename G, int c>
00180   class LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<G,typename G::Traits::LeafIndexSet,c> {
00181   public:
00182         /* @brief The constructor
00183            @param grid A reference to a grid.
00184          */
00185         LeafSingleCodimSingleGeomTypeMapper (const G& grid) 
00186           : SingleCodimSingleGeomTypeMapper<G,typename G::Traits::LeafIndexSet,c>(grid,grid.leafIndexSet())
00187         {}
00188   };
00189 
00203   template <typename G, int c>
00204   class LevelSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<G,typename G::Traits::LevelIndexSet,c> {
00205   public:
00206         /* @brief The constructor
00207            @param grid A reference to a grid.
00208            @param level A valid level of the grid.
00209          */
00210         LevelSingleCodimSingleGeomTypeMapper (const G& grid, int level) 
00211           : SingleCodimSingleGeomTypeMapper<G,typename G::Traits::LevelIndexSet,c>(grid,grid.levelIndexSet(level))
00212         {}
00213   };
00214 
00216 }
00217 #endif

Generated on Thu Apr 2 10:40:43 2009 for dune-grid by  doxygen 1.5.6