dune-grid
2.1.1
|
00001 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=4 sw=2 sts=2: 00003 00004 #ifndef DUNE_MCMGMAPPER_HH 00005 #define DUNE_MCMGMAPPER_HH 00006 00007 #include <iostream> 00008 #include <map> 00009 00010 #include <dune/common/geometrytype.hh> 00011 00012 #include "mapper.hh" 00013 #include "genericreferenceelements.hh" 00014 00021 namespace Dune 00022 { 00029 00030 // 00031 // Common Layout templates 00032 // 00033 00035 00042 template<int dimgrid> struct MCMGElementLayout { 00045 bool contains (Dune::GeometryType gt) { return gt.dim()==dimgrid; } 00046 }; 00047 00049 00056 template<int dim> struct MCMGVertexLayout { 00059 bool contains (Dune::GeometryType gt) { return gt.dim()==0; } 00060 }; 00061 00063 // 00064 // MultipleCodimMultipleGeomTypeMapper 00065 // 00066 00100 template <typename GV, template<int> class Layout> 00101 class MultipleCodimMultipleGeomTypeMapper : 00102 public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV,Layout> > 00103 { 00104 public: 00105 00106 // the following lines need to be skipped for intel compilers, because they 00107 // lead to ambiguous calls to methods 00108 #ifndef __INTEL_COMPILER 00109 00110 00111 using Mapper< typename GV::Grid, MultipleCodimMultipleGeomTypeMapper >::map; 00112 using Mapper< typename GV::Grid, MultipleCodimMultipleGeomTypeMapper >::contains; 00113 #endif 00114 00123 MultipleCodimMultipleGeomTypeMapper (const GV& gridView, const Layout<GV::dimension> layout) 00124 : is(gridView.indexSet()), layout(layout) 00125 { 00126 update(); 00127 } 00128 00133 MultipleCodimMultipleGeomTypeMapper (const GV& gridView) 00134 : is(gridView.indexSet()) 00135 { 00136 update(); 00137 } 00138 00144 template<class EntityType> 00145 int map (const EntityType& e) const 00146 { 00147 return is.index(e) + offset.find(e.type())->second; 00148 } 00149 00157 int map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const 00158 { 00159 GeometryType gt=GenericReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim); 00160 return is.subIndex(e,i,codim) + offset.find(gt)->second; 00161 } 00162 00171 int size () const 00172 { 00173 return n; 00174 } 00175 00182 template<class EntityType> 00183 bool contains (const EntityType& e, int& result) const 00184 { 00185 if(!is.contains(e) || !layout.contains(e.type())) 00186 { 00187 result = 0; 00188 return false; 00189 } 00190 result = map(e); 00191 return true; 00192 } 00193 00202 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const 00203 { 00204 result = this->map(e,i,cc); 00205 return true; 00206 } 00207 00208 00211 void update () 00212 { 00213 n=0; // zero data elements 00214 for (int c=0; c<=GV::dimension; c++) 00215 offset.clear(); // clear all maps 00216 00217 // Compute offsets for the different geometry types. 00218 // Note that mapper becomes invalid when the grid is modified. 00219 for (int c=0; c<=GV::dimension; c++) 00220 for (size_t i=0; i<is.geomTypes(c).size(); i++) 00221 if (layout.contains(is.geomTypes(c)[i])) 00222 { 00223 offset[is.geomTypes(c)[i]] = n; 00224 n += is.size(is.geomTypes(c)[i]); 00225 } 00226 } 00227 00228 private: 00229 int n; // number of data elements required 00230 const typename GV::IndexSet& is; 00231 std::map<GeometryType,int> offset; // provide a map with all geometry types 00232 mutable Layout<GV::dimension> layout; // get layout object 00233 }; 00234 00236 // 00237 // Leaf and level mapper 00238 // 00239 00250 template <typename G, template<int> class Layout> 00251 class LeafMultipleCodimMultipleGeomTypeMapper 00252 : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,Layout> 00253 { 00254 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView, 00255 Layout> Base; 00256 public: 00260 LeafMultipleCodimMultipleGeomTypeMapper (const G& grid) 00261 : Base(grid.leafView()) 00262 {} 00263 00272 LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const Layout<G::dimension> layout) 00273 : Base(grid.leafView(),layout) 00274 {} 00275 00276 }; 00277 00289 template <typename G, template<int> class Layout> 00290 class LevelMultipleCodimMultipleGeomTypeMapper 00291 : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,Layout> { 00292 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView, 00293 Layout> Base; 00294 public: 00299 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level) 00300 : Base(grid.levelView(level)) 00301 {} 00302 00312 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const Layout<G::dimension> layout) 00313 : Base(grid.levelView(level),layout) 00314 {} 00315 00316 }; 00317 00319 } 00320 #endif