dune-grid
2.1.1
|
00001 // $Id: scsgmapper.hh 7134 2010-11-26 22:19:55Z christi $ 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 00054 SingleCodimSingleGeomTypeMapper (const typename GV::Grid& grid, const typename GV::IndexSet& indexset) DUNE_DEPRECATED; 00055 00060 SingleCodimSingleGeomTypeMapper (const GV& gridView); 00061 00067 template<class EntityType> 00068 int map (const EntityType& e) const; 00069 00077 int map (const typename GV::template Codim<0>::Entity& e, 00078 int i, unsigned int codim) const; 00079 00088 int size () const; 00089 00096 template<class EntityType> 00097 bool contains (const EntityType& e, int& result) const; 00098 00107 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const; 00108 00111 void update () 00112 { // nothing to do here 00113 } 00114 00115 private: 00116 const typename GV::IndexSet& is; 00117 }; 00118 00121 template <typename GV, int c> 00122 SingleCodimSingleGeomTypeMapper<GV,c>::SingleCodimSingleGeomTypeMapper (const typename GV::Grid& grid, const typename GV::IndexSet& indexset) 00123 : is(indexset) 00124 { 00125 // check that grid has only a single geometry type 00126 if (is.geomTypes(c).size() != 1) 00127 DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type"); 00128 } 00129 00130 template <typename GV, int c> 00131 SingleCodimSingleGeomTypeMapper<GV,c>::SingleCodimSingleGeomTypeMapper (const GV& gridView) 00132 : is(gridView.indexSet()) 00133 { 00134 // check that grid has only a single geometry type 00135 if (is.geomTypes(c).size() != 1) 00136 DUNE_THROW(GridError, "mapper treats only a single codim and a single geometry type"); 00137 } 00138 00139 template <typename GV, int c> 00140 template<class EntityType> 00141 inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const EntityType& e) const 00142 { 00143 enum { cc = EntityType::codimension }; 00144 dune_static_assert(cc == c, "Entity of wrong codim passed to SingleCodimSingleGeomTypeMapper"); 00145 return is.index(e); 00146 } 00147 00148 template <typename GV, int c> 00149 inline int SingleCodimSingleGeomTypeMapper<GV,c>::map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const 00150 { 00151 if (codim != c) 00152 DUNE_THROW(GridError, "Id of wrong codim requested from SingleCodimSingleGeomTypeMapper"); 00153 return is.subIndex(e,i,codim); 00154 } 00155 00156 template <typename GV, int c> 00157 inline int SingleCodimSingleGeomTypeMapper<GV,c>::size () const 00158 { 00159 return is.size(c); 00160 } 00161 00162 template <typename GV, int c> 00163 template<class EntityType> 00164 inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const EntityType& e, int& result) const 00165 { 00166 result = map(e); 00167 return true; 00168 } 00169 00170 template <typename GV, int c> 00171 inline bool SingleCodimSingleGeomTypeMapper<GV,c>::contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const 00172 { 00173 result = this->map(e,i,cc); 00174 return true; 00175 } 00176 00195 template <typename G, int c> 00196 class LeafSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c> { 00197 public: 00198 /* @brief The constructor 00199 @param grid A reference to a grid. 00200 */ 00201 LeafSingleCodimSingleGeomTypeMapper (const G& grid) 00202 : SingleCodimSingleGeomTypeMapper<typename G::LeafGridView,c>(grid.leafView()) 00203 {} 00204 }; 00205 00219 template <typename G, int c> 00220 class LevelSingleCodimSingleGeomTypeMapper : public SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c> { 00221 public: 00222 /* @brief The constructor 00223 @param grid A reference to a grid. 00224 @param level A valid level of the grid. 00225 */ 00226 LevelSingleCodimSingleGeomTypeMapper (const G& grid, int level) 00227 : SingleCodimSingleGeomTypeMapper<typename G::LevelGridView,c>(grid.levelView(level)) 00228 {} 00229 }; 00230 00232 } 00233 #endif