dune-grid
2.2.0
|
00001 // $Id: scsgmapper.hh 7472 2011-02-28 15:09:13Z 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 { 00037 template <typename GV, int c> 00038 class SingleCodimSingleGeomTypeMapper : 00039 public Mapper<typename GV::Grid,SingleCodimSingleGeomTypeMapper<GV,c> > 00040 { 00041 public: 00042 00045 using Mapper< typename GV::Grid, SingleCodimSingleGeomTypeMapper >::map; 00046 using Mapper< typename GV::Grid, SingleCodimSingleGeomTypeMapper >::contains; 00047 00052 SingleCodimSingleGeomTypeMapper (const GV& gridView); 00053 00059 template<class EntityType> 00060 int map (const EntityType& e) const; 00061 00069 int map (const typename GV::template Codim<0>::Entity& e, 00070 int i, unsigned int codim) const; 00071 00080 int size () const; 00081 00088 template<class EntityType> 00089 bool contains (const EntityType& e, int& result) const; 00090 00099 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const; 00100 00103 void update () 00104 { // nothing to do here 00105 } 00106 00107 private: 00108 const typename GV::IndexSet& is; 00109 }; 00110 00113 template <typename GV, int c> 00114 SingleCodimSingleGeomTypeMapper<GV,c>::SingleCodimSingleGeomTypeMapper (const GV& gridView) 00115 : is(gridView.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 GV, int c> 00123 template<class EntityType> 00124 inline int SingleCodimSingleGeomTypeMapper<GV,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.index(e); 00129 } 00130 00131 template <typename GV, int c> 00132 inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const 00133 { 00134 if (codim != c) 00135 DUNE_THROW(GridError, "Id of wrong codim requested from SingleCodimSingleGeomTypeMapper"); 00136 return is.subIndex(e,i,codim); 00137 } 00138 00139 template <typename GV, int c> 00140 inline int SingleCodimSingleGeomTypeMapper<GV,c>::size () const 00141 { 00142 return is.size(c); 00143 } 00144 00145 template <typename GV, int c> 00146 template<class EntityType> 00147 inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const EntityType& e, int& result) const 00148 { 00149 result = map(e); 00150 return true; 00151 } 00152 00153 template <typename GV, int c> 00154 inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const 00155 { 00156 result = this->map(e,i,cc); 00157 return true; 00158 } 00159 00178 template <typename G, int c> 00179 class LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c> { 00180 public: 00181 /* @brief The constructor 00182 @param grid A reference to a grid. 00183 */ 00184 LeafSingleCodimSingleGeomTypeMapper (const G& grid) 00185 : SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c>(grid.leafView()) 00186 {} 00187 }; 00188 00202 template <typename G, int c> 00203 class LevelSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c> { 00204 public: 00205 /* @brief The constructor 00206 @param grid A reference to a grid. 00207 @param level A valid level of the grid. 00208 */ 00209 LevelSingleCodimSingleGeomTypeMapper (const G& grid, int level) 00210 : SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c>(grid.levelView(level)) 00211 {} 00212 }; 00213 00215 } 00216 #endif