00001 #ifndef DUNE_ALU2DGRIDENTITY_HH
00002 #define DUNE_ALU2DGRIDENTITY_HH
00003
00004
00005
00006
00007 #include <dune/grid/common/entity.hh>
00008
00009
00010
00011 #include "iterator.hh"
00012
00013 namespace Dune {
00014
00015 template<int cd, int dim, class GridImp>
00016 class ALU2dGridEntity;
00017 template<int cd, PartitionIteratorType pitype, class GridImp >
00018 class ALU2dGridLevelIterator;
00019 template<int cd, class GridImp >
00020 class ALU2dGridEntityPointer;
00021 template<int mydim, int coorddim, class GridImp>
00022 class ALU2dGridGeometry;
00023 template<class GridImp>
00024 class ALU2dGridHierarchicIterator;
00025 template<class GridImp>
00026 class ALU2dGridLevelIntersectionIterator;
00027 template<class GridImp>
00028 class ALU2dGridLeafIntersectionIterator;
00029 template<class GridImp>
00030 class ALU2dGridIntersectionIterator;
00031 template<int codim, PartitionIteratorType, class GridImp>
00032 class ALU2dGridLeafIterator;
00033 template<int dim, int dimworld>
00034 class ALU2dGrid;
00035
00036
00037
00038
00039
00040
00041
00048 template<int cd, int dim, class GridImp>
00049 class ALU2dGridEntity :
00050 public EntityDefaultImplementation <cd,dim,GridImp,ALU2dGridEntity>
00051 {
00052 enum { dimworld = GridImp::dimensionworld };
00053
00054 friend class ALU2dGrid < dim , dimworld>;
00055 friend class ALU2dGridIntersectionIterator < GridImp >;
00056 friend class ALU2dGridIntersectionIterator < const GridImp >;
00057 friend class ALU2dGridLevelIntersectionIterator < GridImp >;
00058 friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
00059 friend class ALU2dGridLeafIntersectionIterator < GridImp >;
00060 friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
00061 friend class ALU2dGridHierarchicIterator < const GridImp >;
00062 friend class ALU2dGridHierarchicIterator < GridImp >;
00063 friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
00064 friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
00065 friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;
00066 friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
00067 friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
00068 friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;
00069 friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
00070
00071 friend class ALU2dGridHierarchicIndexSet<dim,dimworld>;
00072
00073 typedef typename ALU2DSPACE Hmesh_basic::helement_t HElementType ;
00074
00075 public:
00076 typedef typename Dune::ALU2dImplTraits::template Codim<cd>::InterfaceType ElementType;
00077
00079 typedef typename GridImp::template Codim<cd>::Entity Entity;
00081 typedef typename GridImp::template Codim<cd>::Geometry Geometry;
00083 typedef MakeableInterfaceObject<Geometry> GeometryObj;
00084 typedef ALU2dGridGeometry<dim-cd,dimworld,GridImp> GeometryImp;
00085
00087 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00088
00090 int level () const;
00091
00093 ALU2dGridEntity(const GridImp &grid, int level);
00094
00096 ALU2dGridEntity(const ALU2dGridEntity & org);
00097
00099 const Geometry & geometry () const;
00100
00102 GeometryType type() const ;
00103
00105 void removeElement();
00106
00110
00111 void setElement(const ElementType &element, int face=-1, int level = -1) const;
00112 void setElement(const HElementType & el, const ALU2DSPACE Vertex & vx);
00113 void setElement(const ALU2dGridEntity & org) const {
00114 setElement(*(org.item_), org.face_);
00115 }
00116
00118 bool equals ( const ALU2dGridEntity<cd,dim,GridImp> & org ) const;
00119
00122 PartitionType partitionType() const{ return InteriorEntity; }
00123
00128 int boundaryId () const;
00129
00134 EntityPointer ownersFather () const;
00135
00137 FieldVector<alu2d_ctype, dim>& positionInOwnersFather () const;
00138
00139
00140 private:
00142 int getIndex () const;
00143
00145 const GridImp &grid_;
00146
00148 mutable ElementType * item_;
00150
00151 mutable GeometryObj geoObj_;
00152 mutable GeometryImp & geoImp_;
00153
00154 mutable int level_;
00155 mutable int face_;
00156 };
00157
00171
00172
00173
00174
00175
00176
00177 template<int dim, class GridImp>
00178 class ALU2dGridEntity<0,dim,GridImp>
00179 : public EntityDefaultImplementation<0,dim,GridImp,ALU2dGridEntity>
00180 {
00181 enum { dimworld = GridImp::dimensionworld };
00182
00183 friend class ALU2dGrid < dim , dimworld>;
00184 friend class ALU2dGridIntersectionIterator < GridImp >;
00185 friend class ALU2dGridIntersectionIterator < const GridImp >;
00186 friend class ALU2dGridLevelIntersectionIterator < GridImp >;
00187 friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
00188 friend class ALU2dGridLeafIntersectionIterator < GridImp >;
00189 friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
00190 friend class ALU2dGridHierarchicIterator < const GridImp >;
00191 friend class ALU2dGridHierarchicIterator < GridImp >;
00192 friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
00193 friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
00194 friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;
00195 friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
00196 friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
00197 friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;
00198 friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
00199
00200 friend class ALU2dGridHierarchicIndexSet<dim,dimworld>;
00201
00202 typedef typename ALU2DSPACE Hmesh_basic::helement_t HElementType ;
00203
00204 public:
00206 typedef typename GridImp::template Codim<0>::Geometry Geometry;
00208 typedef MakeableInterfaceObject<Geometry> GeometryObj;
00209 typedef ALU2dGridGeometry<dim,dimworld,GridImp> GeometryImp;
00210
00212 typedef LeafIntersectionIteratorWrapper< GridImp > ALU2dGridLeafIntersectionIteratorType;
00213 typedef LevelIntersectionIteratorWrapper< GridImp > ALU2dGridLevelIntersectionIteratorType;
00214 typedef ALU2dGridLeafIntersectionIteratorType ALU2dGridIntersectionIteratorType;
00215
00217 typedef typename GridImp::template Codim<0>::Entity Entity;
00219
00220 typedef ALU2dGridEntityPointer<0,GridImp> EntityPointer;
00221
00222 template <int cd>
00223 struct Codim
00224 {
00225 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00226 };
00227
00229 ALU2dGridEntity(const GridImp &grid, int level);
00230
00232 ALU2dGridEntity(const ALU2dGridEntity & org);
00233
00235 int level () const ;
00236
00238 const Geometry & geometry () const;
00239
00241 GeometryType type() const ;
00242
00246 template<int cc>
00247 int count () const {
00248 enum {c = (cc==0)?1 : dim+1};
00249 return c;
00250 }
00251
00256 int boundaryId () const {
00257
00258 return 0;
00259 }
00260
00267
00268 ALU2dGridIntersectionIteratorType ibegin () const
00269 {
00270 return ileafbegin();
00271 }
00273 ALU2dGridIntersectionIteratorType iend () const
00274 {
00275 return ileafend();
00276 }
00277
00278 ALU2dGridLevelIntersectionIteratorType ilevelbegin () const
00279 {
00280 return ALU2dGridLevelIntersectionIteratorType(grid_, *this, this->level(),false);
00281 }
00282 ALU2dGridLevelIntersectionIteratorType ilevelend () const
00283 {
00284 return ALU2dGridLevelIntersectionIteratorType(grid_, *this, this->level(),true);
00285 }
00286 ALU2dGridLeafIntersectionIteratorType ileafbegin () const
00287 {
00288 return ALU2dGridLeafIntersectionIteratorType(grid_, *this, this->level(), false);
00289 }
00290 ALU2dGridLeafIntersectionIteratorType ileafend () const
00291 {
00292 return ALU2dGridLeafIntersectionIteratorType(grid_, *this, this->level(),true);
00293 }
00294
00296 bool isLeaf () const;
00297
00300 EntityPointer father () const;
00301
00306 ALU2dGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
00307 {
00308 return ALU2dGridHierarchicIterator<GridImp> (grid_,*item_,maxLevel,false);
00309 }
00310
00312 ALU2dGridHierarchicIterator<GridImp> hend (int maxLevel) const
00313 {
00314 return ALU2dGridHierarchicIterator<GridImp> (grid_,*item_,maxLevel,true);
00315 }
00316
00319 template <int cc>
00320 typename Codim<cc>::EntityPointer entity (int i) const;
00321
00323 PartitionType partitionType() const
00324 {
00325 #if ALU2DGRID_PARALLEL
00326 return grid_.rankManager().partitionType( item_->getIndex() );
00327 #else
00328 return InteriorEntity;
00329 #endif
00330 }
00331
00338 template <int cc>
00339 int subBoundaryId ( int i ) const;
00340
00341
00352 const Geometry & geometryInFather () const;
00353
00355 bool mightBeCoarsened () const{
00356 return ((item_->is(ALU2DSPACE Refco::crs))==1);
00357 }
00358 bool wasRefined () const {
00359 return ((item_->wasRefined())==1);
00360 }
00361
00362
00363
00364
00365
00366 public:
00370 bool mark(int refCount) const;
00371
00373 int getMark() const;
00374
00378 void setElement(const HElementType &element, int face=-1, int level = -1) const;
00379
00380 void setElement(const ALU2dGridEntity & org) const {
00381 setElement(*(org.item_));
00382 }
00383
00385 void reset ( int l );
00386
00388 void removeElement();
00389
00391 bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const;
00392
00393
00394 HElementType & getItem() const
00395 {
00396 assert( item_ );
00397 return *item_;
00398 }
00399
00400 private:
00402 int nChild () const;
00403
00405 int getIndex () const;
00406
00410 template<int cc> int getSubIndex (int i) const;
00411
00413 const GridImp & grid_;
00414
00416 mutable HElementType *item_;
00417
00419 mutable GeometryObj geoObj_;
00420 mutable GeometryImp & geoImp_;
00421
00422 mutable int walkLevel_;
00423
00424 mutable bool isLeaf_;
00425
00426 };
00427
00428
00429
00430
00431
00432
00433
00434
00438 template<int cd, class GridImp>
00439 class ALU2dGridEntityPointer :
00440 public EntityPointerDefaultImplementation <cd, GridImp, ALU2dGridEntityPointer<cd,GridImp> >
00441 {
00442
00443 typedef ALU2dGridEntityPointer <cd,GridImp> ThisType;
00444 enum { dim = GridImp::dimension };
00445 enum { dimworld = GridImp::dimensionworld };
00446 typedef typename Dune::ALU2dImplTraits::template Codim<cd>::InterfaceType ElementType;
00447
00448 public:
00450 typedef typename GridImp::template Codim<cd>::Entity Entity;
00452 typedef ALU2dGridEntity<cd,dim,GridImp> EntityImp;
00453 typedef MakeableInterfaceObject<Entity> EntityObj;
00454
00455 typedef ALU2dGridEntityPointer<cd,GridImp> Base;
00456
00458 ALU2dGridEntityPointer(const GridImp & grid,
00459 const ElementType & item,
00460 int face = -1,
00461 int level = -1
00462 );
00463
00465 ALU2dGridEntityPointer(const GridImp & grid) ;
00466
00468 ALU2dGridEntityPointer(const ThisType & org) ;
00469
00471 ~ALU2dGridEntityPointer();
00472
00474
00475 bool equals (const ThisType & i) const;
00476
00478 Entity & dereference() const ;
00479
00481 int level () const;
00482
00483 ThisType & operator = (const ThisType & org);
00484
00485 protected:
00486 EntityImp & entityImp();
00487
00488 const EntityImp & entityImp() const;
00489
00491 void done ();
00492
00494 void updateEntityPointer( ElementType * item, int face=-1, int level=-1 );
00495
00497 const GridImp & grid_;
00498
00500 mutable ElementType * item_;
00501 mutable int level_;
00502 int face_;
00504 mutable EntityObj * entity_;
00505 };
00506
00507 }
00508
00509 #include "entity_imp.cc"
00510 #endif