dune-grid-dev-howto
2.1.1
|
00001 #ifndef DUNE_IDENTITYGRID_INDEXSETS_HH 00002 #define DUNE_IDENTITYGRID_INDEXSETS_HH 00003 00008 #include <dune/grid/common/indexidset.hh> 00009 00010 #include <vector> 00011 00012 namespace Dune { 00013 00015 template<class GridImp> 00016 class IdentityGridLevelIndexSet : 00017 public IndexSet<GridImp,IdentityGridLevelIndexSet<GridImp> > 00018 { 00019 public: 00020 00021 typedef typename remove_const<GridImp>::type::HostGridType HostGrid; 00022 00023 enum {dim = GridImp::dimension}; 00024 00026 template<int codim> 00027 int index (const typename GridImp::Traits::template Codim<codim>::Entity& e) const 00028 { 00029 return grid_->hostgrid_->levelIndexSet(level_).template index<codim>(*grid_->template getHostEntityPointer<codim>(e)); 00030 } 00031 00032 00034 template<int cc> 00035 int subIndex (const typename GridImp::Traits::template Codim<cc>::Entity& e, int i, int codim) const 00036 { 00037 return grid_->hostgrid_->levelIndexSet(level_).subIndex(*grid_->template getHostEntityPointer<cc>(e), i, codim); 00038 } 00039 00040 00042 int size (int codim) const { 00043 return grid_->hostgrid_->levelIndexSet(level_).size(codim); 00044 } 00045 00046 00048 int size (GeometryType type) const 00049 { 00050 return grid_->hostgrid_->levelIndexSet(level_).size(type); 00051 } 00052 00053 00055 const std::vector<GeometryType>& geomTypes (int codim) const 00056 { 00057 return grid_->hostgrid_->levelIndexSet(level_).geomTypes(codim); 00058 } 00059 00061 template<class EntityType> 00062 bool contains (const EntityType& e) const 00063 { 00064 return grid_->hostgrid_->levelIndexSet(level_).contains(*grid_->template getHostEntityPointer<EntityType::codimension>(e)); 00065 } 00066 00068 void update(const GridImp& grid, int level) 00069 { 00070 grid_ = &grid; 00071 level_ = level; 00072 } 00073 00074 00075 GridImp* grid_; 00076 00077 int level_; 00078 }; 00079 00080 00081 template<class GridImp> 00082 class IdentityGridLeafIndexSet : 00083 public IndexSet<GridImp,IdentityGridLeafIndexSet<GridImp> > 00084 { 00085 typedef typename remove_const<GridImp>::type::HostGridType HostGrid; 00086 00087 public: 00088 00089 00090 /* 00091 * We use the remove_const to extract the Type from the mutable class, 00092 * because the const class is not instantiated yet. 00093 */ 00094 enum {dim = remove_const<GridImp>::type::dimension}; 00095 00096 00098 IdentityGridLeafIndexSet (const GridImp& grid) 00099 : grid_(&grid) 00100 {} 00101 00102 00104 /* 00105 We use the RemoveConst to extract the Type from the mutable class, 00106 because the const class is not instantiated yet. 00107 */ 00108 template<int codim> 00109 int index (const typename remove_const<GridImp>::type::template Codim<codim>::Entity& e) const 00110 { 00111 return grid_->hostgrid_->leafIndexSet().template index<codim>(*grid_->template getHostEntityPointer<codim>(e)); 00112 } 00113 00114 00116 /* 00117 We use the RemoveConst to extract the Type from the mutable class, 00118 because the const class is not instantiated yet. 00119 */ 00120 template<int cc> 00121 int subIndex (const typename remove_const<GridImp>::type::Traits::template Codim<cc>::Entity& e, int i, int codim) const 00122 { 00123 return grid_->hostgrid_->leafIndexSet().subIndex(*grid_->template getHostEntityPointer<cc>(e),i, codim); 00124 } 00125 00126 00128 int size (GeometryType type) const 00129 { 00130 return grid_->hostgrid_->leafIndexSet().size(type); 00131 } 00132 00133 00135 int size (int codim) const 00136 { 00137 return grid_->hostgrid_->leafIndexSet().size(codim); 00138 } 00139 00140 00142 const std::vector<GeometryType>& geomTypes (int codim) const 00143 { 00144 return grid_->hostgrid_->leafIndexSet().geomTypes(codim); 00145 } 00146 00148 template<class EntityType> 00149 bool contains (const EntityType& e) const 00150 { 00151 return grid_->hostgrid_->leafIndexSet().contains(*grid_->template getHostEntityPointer<EntityType::codimension>(e)); 00152 } 00153 00154 00155 00157 void update(const GridImp& grid) 00158 { 00159 grid_ = &grid; 00160 } 00161 00162 00163 GridImp* grid_; 00164 }; 00165 00166 00167 00168 00169 template <class GridImp> 00170 class IdentityGridGlobalIdSet : 00171 public IdSet<GridImp,IdentityGridGlobalIdSet<GridImp>, 00172 typename remove_const<GridImp>::type::HostGridType::Traits::GlobalIdSet::IdType> 00173 { 00174 00175 typedef typename remove_const<GridImp>::type::HostGridType HostGrid; 00176 00177 00178 public: 00180 IdentityGridGlobalIdSet (const GridImp& g) : grid_(&g) {} 00181 00183 typedef typename HostGrid::Traits::GlobalIdSet::IdType IdType; 00184 00185 00187 /* 00188 We use the remove_const to extract the Type from the mutable class, 00189 because the const class is not instantiated yet. 00190 */ 00191 template<int cd> 00192 IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const 00193 { 00194 // Return id of the host entity 00195 return grid_->hostgrid_->globalIdSet().id(*grid_->getRealImplementation(e).hostEntity_); 00196 } 00197 00198 00200 /* 00201 We use the remove_const to extract the Type from the mutable class, 00202 because the const class is not instantiated yet. 00203 */ 00204 IdType subId (const typename remove_const<GridImp>::type::Traits::template Codim<0>::Entity& e, int i, int codim) const 00205 { 00206 // Return sub id of the host entity 00207 return grid_->hostgrid_->globalIdSet().subId(*grid_->getRealImplementation(e).hostEntity_,i, codim); 00208 } 00209 00210 00212 void update() {} 00213 00214 00215 const GridImp* grid_; 00216 }; 00217 00218 00219 00220 00221 template<class GridImp> 00222 class IdentityGridLocalIdSet : 00223 public IdSet<GridImp,IdentityGridLocalIdSet<GridImp>, 00224 typename remove_const<GridImp>::type::HostGridType::Traits::LocalIdSet::IdType> 00225 { 00226 private: 00227 00228 typedef typename remove_const<GridImp>::type::HostGridType HostGrid; 00229 00230 00231 public: 00233 typedef typename HostGrid::Traits::LocalIdSet::IdType IdType; 00234 00235 00237 IdentityGridLocalIdSet (const GridImp& g) : grid_(&g) {} 00238 00239 00241 /* 00242 We use the remove_const to extract the Type from the mutable class, 00243 because the const class is not instantiated yet. 00244 */ 00245 template<int cd> 00246 IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const 00247 { 00248 // Return id of the host entity 00249 return grid_->hostgrid_->localIdSet().id(*grid_->getRealImplementation(e).hostEntity_); 00250 } 00251 00252 00254 /* 00255 * We use the remove_const to extract the Type from the mutable class, 00256 * because the const class is not instantiated yet. 00257 */ 00258 IdType subId (const typename remove_const<GridImp>::type::template Codim<0>::Entity& e, int i, int codim) const 00259 { 00260 // Return sub id of the host entity 00261 return grid_->hostgrid_->localIdSet().subId(*grid_->getRealImplementation(e).hostEntity_,i,codim); 00262 } 00263 00264 00266 void update() {} 00267 00268 00269 const GridImp* grid_; 00270 }; 00271 00272 00273 } // namespace Dune 00274 00275 00276 #endif