00001 #ifndef DUNE_GRID_ENTITY_HH
00002 #define DUNE_GRID_ENTITY_HH
00003
00004 #include <dune/common/typetraits.hh>
00005 #include "grid.hh"
00006
00007 namespace Dune
00008 {
00009
00079 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
00080 class Entity {
00081 enum { dimworld = GridImp::dimensionworld };
00082 typedef typename GridImp::ctype ct;
00083 protected:
00084 EntityImp<cd,dim,GridImp> realEntity;
00085 public:
00086
00087
00091
00092 protected:
00093
00094 typedef EntityImp<cd,dim,GridImp> ImplementationType;
00095
00096 public:
00098 typedef typename GridImp::template Codim<cd>::Geometry Geometry;
00099
00100 enum {
00102 codimension=cd
00103 };
00104 enum {
00106 dimension=dim
00107 };
00108 enum {
00110 mydimension=dim-cd
00111 };
00112 enum {
00114 dimensionworld=dimworld
00115 };
00116
00118 typedef ct ctype;
00120
00121
00122
00123
00127
00128
00130 int level () const { return realEntity.level(); }
00131
00133 PartitionType partitionType () const { return realEntity.partitionType(); }
00134
00144 const Geometry& geometry () const { return realEntity.geometry(); }
00146
00150 GeometryType type () const { return realEntity.type(); };
00151
00152
00156
00157
00159 explicit Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {};
00160
00161
00162
00163
00164
00165
00166
00168
00169 typedef typename RemoveConst<GridImp>::Type mutableGridImp;
00170
00171 protected:
00172
00176
00177
00178
00179 friend class GridDefaultImplementation<
00180 GridImp::dimension, GridImp::dimensionworld,
00181 typename GridImp::ctype,
00182 typename GridImp::GridFamily> ;
00183
00185 EntityImp<cd,dim,GridImp> & getRealImp() { return realEntity; }
00187 const EntityImp<cd,dim,GridImp> & getRealImp() const { return realEntity; }
00188
00189 protected:
00191 Entity(const Entity& rhs) : realEntity(rhs.realEntity) {};
00193 Entity & operator = (const Entity& rhs) {
00194 realEntity = rhs.realEntity;
00195 return *this;
00196 }
00198 };
00199
00208 template<int dim, class GridImp, template<int,int,class> class EntityImp>
00209 class Entity <0,dim,GridImp,EntityImp>
00210 {
00211 enum { dimworld = GridImp::dimensionworld };
00212 typedef typename GridImp::ctype ct;
00213
00214 typedef typename RemoveConst<GridImp>::Type mutableGridImp;
00215
00216 protected:
00217 EntityImp<0,dim,GridImp> realEntity;
00218
00219
00220 typedef EntityImp<0,dim,GridImp> ImplementationType;
00221 public:
00222
00223
00227
00228
00230 typedef typename GridImp::template Codim<0>::Geometry Geometry;
00231
00235 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
00236
00238 template <int cd>
00239 struct Codim
00240 {
00241 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00242 };
00243
00245 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00246
00248 typedef typename GridImp::template Codim<0>::LeafIntersectionIterator LeafIntersectionIterator;
00249
00251 typedef typename GridImp::template Codim<0>::LevelIntersectionIterator LevelIntersectionIterator;
00252
00254 typedef typename GridImp::template Codim<0>::HierarchicIterator HierarchicIterator;
00255
00256 enum {
00258 codimension=0
00259 };
00260 enum {
00262 dimension=dim
00263 };
00264 enum {
00266 mydimension=dim
00267 };
00268 enum {
00270 dimensionworld=dimworld
00271 };
00273 typedef ct ctype;
00275
00276
00277
00281
00282
00284 int level () const { return realEntity.level(); }
00285
00287 PartitionType partitionType () const { return realEntity.partitionType(); }
00288
00290 const Geometry& geometry () const { return realEntity.geometry(); }
00292
00296 GeometryType type () const { return realEntity.type(); };
00297
00298
00302
00303
00309 template<int cc> int count () const { return realEntity.count<cc>(); }
00310
00313 template<int cc> typename Codim<cc>::EntityPointer entity (int i) const
00314 {
00315 return realEntity.entity<cc>(i);
00316 }
00317
00324 LeafIntersectionIterator ileafbegin () const
00325 {
00326 return realEntity.ileafbegin();
00327 }
00328
00331 LeafIntersectionIterator ileafend () const
00332 {
00333 return realEntity.ileafend();
00334 }
00335
00342 LevelIntersectionIterator ilevelbegin () const
00343 {
00344 return realEntity.ilevelbegin();
00345 }
00346
00349 LevelIntersectionIterator ilevelend () const
00350 {
00351 return realEntity.ilevelend();
00352 }
00353
00358 EntityPointer father () const
00359 {
00360 return realEntity.father();
00361 }
00362
00364 bool isLeaf () const
00365 {
00366 return realEntity.isLeaf();
00367 }
00368
00372 bool isRegular() const { return realEntity.isRegular(); }
00373
00387 const LocalGeometry& geometryInFather () const
00388 {
00389 return realEntity.geometryInFather();
00390 }
00391
00398 HierarchicIterator hbegin (int maxlevel) const
00399 {
00400 return realEntity.hbegin(maxlevel);
00401 }
00402
00405 HierarchicIterator hend (int maxlevel) const
00406 {
00407 return realEntity.hend(maxlevel);
00408 }
00409
00412 bool wasRefined () const { return realEntity.wasRefined(); }
00413
00416 bool mightBeCoarsened () const { return realEntity.mightBeCoarsened (); }
00417
00418
00422
00426 bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); }
00427
00429 explicit Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {};
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00449
00450
00451 protected:
00452
00456
00457
00458
00459 friend class GridDefaultImplementation<
00460 GridImp::dimension, GridImp::dimensionworld,
00461 typename GridImp::ctype,
00462 typename GridImp::GridFamily> ;
00463
00465 EntityImp<0,dim,GridImp> & getRealImp() { return realEntity; }
00467 const EntityImp<0,dim,GridImp> & getRealImp() const { return realEntity; }
00468
00469 protected:
00471 Entity(const Entity& rhs) : realEntity(rhs.realEntity) {};
00473 Entity & operator = (const Entity& rhs) {
00474 realEntity = rhs.realEntity;
00475 return *this;
00476 };
00478 };
00479
00480
00481
00492 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
00493 class EntityDefaultImplementation
00494 {
00495 enum { dimworld = GridImp::dimensionworld };
00496 typedef typename GridImp::ctype ct;
00497 public:
00499 enum { codimension=cd };
00500
00502 enum { dimension=dim };
00503
00505 enum { mydimension=dim-cd };
00506
00508 enum { dimensionworld=dimworld };
00509
00511 typedef ct ctype;
00512
00516 GeometryType type () const { return asImp().geometry().type(); };
00517
00518 private:
00520 EntityImp<cd,dim,GridImp>& asImp ()
00521 {
00522 return static_cast<EntityImp<cd,dim,GridImp>&>(*this);
00523 }
00524 const EntityImp<cd,dim,GridImp>& asImp () const
00525 {
00526 return static_cast<const EntityImp<cd,dim,GridImp>&>(*this);
00527 }
00528 };
00529
00530
00542 template<int dim, class GridImp, template<int,int,class> class EntityImp>
00543 class EntityDefaultImplementation <0,dim,GridImp,EntityImp>
00544 {
00545 enum { dimworld = GridImp::dimensionworld };
00546 typedef typename GridImp::ctype ct;
00547
00548 public:
00550 enum { codimension=0 };
00551
00553 enum { dimension=dim };
00554
00556 enum { mydimension=dim };
00557
00559 enum { dimensionworld=dimworld };
00560
00562 typedef ct ctype;
00563
00567 bool isRegular() const { return true; }
00568
00572 GeometryType type () const { return asImp().geometry().type(); };
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00590 bool wasRefined () const { return false; }
00591
00594 bool mightBeCoarsened () const { return false; }
00595
00600 bool hasBoundaryIntersections () const
00601 {
00602 {
00603 typedef typename GridImp :: template Codim<0> :: LevelIntersectionIterator
00604 IntersectionIterator;
00605 IntersectionIterator end = asImp().ilevelend();
00606 for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it)
00607 {
00608 if( it.boundary() ) return true;
00609 }
00610 }
00611
00612 {
00613 typedef typename GridImp :: template Codim<0> :: LeafIntersectionIterator
00614 IntersectionIterator;
00615 IntersectionIterator end = asImp().ileafend();
00616 for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it)
00617 {
00618 if( it.boundary() ) return true;
00619 }
00620 }
00621
00622 return false;
00623 }
00624
00625 private:
00626
00627 EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); }
00628 const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); }
00629 };
00630
00631 }
00632
00633 #endif // DUNE_GRID_ENTITY_HH