indexidset.hh
Go to the documentation of this file.00001
00002
00003 #ifndef DUNE_INDEXIDSET_HH
00004 #define DUNE_INDEXIDSET_HH
00005
00006 #include <iostream>
00007 #include <vector>
00008 #include <dune/common/exceptions.hh>
00009 #include <dune/common/helpertemplates.hh>
00010 #include <dune/common/bartonnackmanifcheck.hh>
00011
00012 #include <dune/grid/common/grid.hh>
00013
00014 #define INDEXSET_HAS_ITERATORS
00015
00016 #ifdef INDEXSET_HAS_ITERATORS
00017 #warning "You enabled iterators on index sets. This feature has been deprecated."
00018 #warning "Please use grid views instead of index sets to get a view on a grid level."
00019 #warning "To disable this warning, undefine INDEXSET_HAS_ITERATORS in indexidset.hh."
00020 #endif
00021
00027 namespace Dune
00028 {
00082 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00083 class IndexSet {
00084 public:
00085 #ifdef INDEXSET_HAS_ITERATORS
00086
00088 template <int cd>
00089 struct Codim
00090 {
00091
00093 template <PartitionIteratorType pitype>
00094 struct Partition
00095 {
00098 typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00099 };
00100 } DUNE_DEPRECATED;
00101 #endif
00102
00104 typedef unsigned int IndexType;
00105
00106
00110
00111
00118
00119
00120
00121
00122 template<int cc>
00123 IndexType index (const typename remove_const<GridImp>::type::
00124 Traits::template Codim<cc>::Entity& e) const
00125 {
00126 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00127 return asImp().template index<cc>(e);
00128 }
00129
00139 template<class EntityType>
00140 IndexType index (const EntityType& e) const
00141 {
00142 enum { cc = EntityType::codimension };
00143 CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
00144 return asImp().template index<cc>(e);
00145 }
00146
00155
00156
00157
00158
00159 template<int cc>
00160 IndexType subIndex (const typename remove_const<GridImp>::type::
00161 Traits::template Codim<0>::Entity& e, int i) const
00162 {
00163 CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex<cc>(e,i)));
00164 return asImp().template subIndex<cc>(e,i);
00165 }
00167
00168
00169
00173
00174
00182 const std::vector<GeometryType>& geomTypes (int codim) const
00183 {
00184 CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
00185 return asImp().geomTypes(codim);
00186 }
00187
00193 IndexType size (GeometryType type) const
00194 {
00195 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
00196 return asImp().size(type);
00197 }
00198
00205 IndexType size (int codim) const
00206 {
00207 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
00208 return asImp().size(codim);
00209 }
00210
00213 template<class EntityType>
00214 bool contains (const EntityType& e) const
00215 {
00216 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
00217 return asImp().contains(e);
00218 }
00219
00220 #ifdef INDEXSET_HAS_ITERATORS
00221
00224 template<int cd, PartitionIteratorType pitype>
00225 typename Codim<cd>::template Partition<pitype>::Iterator begin ()const DUNE_DEPRECATED;
00226
00230 template<int cd, PartitionIteratorType pitype>
00231 typename Codim<cd>::template Partition<pitype>::Iterator end () const DUNE_DEPRECATED;
00233 #endif
00234
00235 IndexSet() {}
00236
00237 private:
00239 IndexSet(const IndexSet&);
00241 IndexSet& operator=(const IndexSet&);
00242
00244 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00246 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00247 };
00248
00249 #ifdef INDEXSET_HAS_ITERATORS
00250 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00251 template<int cd, PartitionIteratorType pitype>
00252 DUNE_DEPRECATED
00253 typename IndexSet<GridImp,IndexSetImp,IndexSetTypes>::template Codim<cd>::template Partition<pitype>::Iterator
00254 IndexSet<GridImp,IndexSetImp,IndexSetTypes>::begin() const
00255 {
00256 CHECK_INTERFACE_IMPLEMENTATION((asImp().begin<cd,pitype>()));
00257 return asImp().begin<cd,pitype>();
00258 }
00259
00260 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00261 template<int cd, PartitionIteratorType pitype>
00262 DUNE_DEPRECATED
00263 typename IndexSet<GridImp,IndexSetImp,IndexSetTypes>::template Codim<cd>::template Partition<pitype>::Iterator
00264 IndexSet<GridImp,IndexSetImp,IndexSetTypes>::end() const
00265 {
00266 CHECK_INTERFACE_IMPLEMENTATION((asImp().begin<cd,pitype>()));
00267 return asImp().end<cd,pitype>();
00268 }
00269 #endif
00270
00271 #undef CHECK_INTERFACE_IMPLEMENTATION
00272 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00273
00277 template<class GridImp, class IndexSetImp, class IndexSetTypes>
00278 class IndexSetDefaultImplementation :
00279 public IndexSet<GridImp,IndexSetImp,IndexSetTypes>
00280 {
00281 public:
00284 template <int cd>
00285 struct Codim
00286 {
00287
00289 template <PartitionIteratorType pitype>
00290 struct Partition
00291 {
00294 typedef typename IndexSetTypes::template Codim<cd>::template Partition<pitype>::Iterator Iterator;
00295 };
00296 } DUNE_DEPRECATED;
00297
00298 typedef typename IndexSet<GridImp,IndexSetImp,IndexSetTypes>::IndexType IndexType;
00299
00312 template<int cc>
00313 IndexType subIndex (const typename remove_const<GridImp>::type::
00314 Traits::template Codim<0>::Entity& e, int i) const
00315 {
00316 return this->index( *(e.template entity<cc>(i) ));
00317 }
00318
00326 IndexType size (int codim) const
00327 {
00328 int s=0;
00329 const std::vector<GeometryType>& geomTs = asImp().geomTypes(codim);
00330 for (unsigned int i=0; i<geomTs.size(); ++i)
00331 s += asImp().size(geomTs[i]);
00332 return s;
00333 }
00334
00337 template<class EntityType>
00338 bool contains (const EntityType& e) const
00339 {
00340 enum { cd = EntityType::codimension };
00341 typedef typename Codim<cd>::template Partition<All_Partition>::Iterator IteratorType;
00342 IteratorType iend = asImp().template end<cd,All_Partition>();
00343 for (IteratorType it = asImp().template begin<cd,All_Partition>();
00344 it != iend; ++it)
00345 {
00347 if (it->level() == e.level() && this->index(*it) == this->index(e)) return true;
00348 }
00349 return false;
00350 }
00351
00352 private:
00354 IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
00356 const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
00357 };
00358
00359
00427 template<class GridImp, class IdSetImp, class IdTypeImp>
00428 class IdSet
00429 {
00430 public:
00432 typedef IdTypeImp IdType;
00433
00435 template<class EntityType>
00436 IdType id (const EntityType& e) const
00437 {
00438 enum { cc = EntityType::codimension };
00439 return asImp().template id<cc>(e);
00440 }
00441
00443
00444
00445
00446
00447 template<int cc>
00448 IdType id (const typename remove_const<GridImp>::type::
00449 Traits::template Codim<cc>::Entity& e) const
00450 {
00451 return asImp().template id<cc>(e);
00452 }
00453
00455
00456
00457
00458
00459 template<int cc>
00460 IdType subId (const typename remove_const<GridImp>::type::
00461 Traits::template Codim<0>::Entity& e, int i) const
00462 {
00463 return asImp().template subId<cc>(e,i);
00464 }
00465
00466
00467 IdSet() {}
00468
00469 private:
00471 IdSet(const IdSet&);
00473 IdSet& operator=(const IdSet&);
00474
00476 IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
00478 const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
00479 };
00480
00494 template<class GridImp, class IdSetImp, class IdTypeImp>
00495 class IdSetDefaultImplementation : public IdSet<GridImp,IdSetImp,IdTypeImp>
00496 {
00497 public:
00499 typedef IdTypeImp IdType;
00500
00502
00503
00504
00505
00506
00507
00508 template<int cc>
00509 IdType subId (const typename remove_const<GridImp>::type::
00510 Traits::template Codim<0>::Entity& e, int i) const
00511 {
00512 return this->id( *(e.template entity<cc>(i)) );
00513 }
00514 };
00515
00516
00517 }
00518 #endif