dune-grid
2.2beta1
|
00001 #ifndef DUNE_ALU2DGRID_INTERSECTION_HH 00002 #define DUNE_ALU2DGRID_INTERSECTION_HH 00003 00004 // System includes 00005 #include <stack> 00006 #include <utility> 00007 00008 // Dune includes 00009 #include <dune/grid/common/grid.hh> 00010 00011 #include <dune/grid/alugrid/common/intersectioniteratorwrapper.hh> 00012 #include <dune/grid/alugrid/2d/alu2dinclude.hh> 00013 #include <dune/grid/alugrid/2d/entity.hh> 00014 00015 namespace Dune 00016 { 00017 00018 // Forward declarations 00019 template<int cd, int dim, class GridImp> 00020 class ALU2dGridEntity; 00021 template<int cd, PartitionIteratorType pitype, class GridImp > 00022 class ALU2dGridLevelIterator; 00023 template<int cd, class GridImp > 00024 class ALU2dGridEntityPointer; 00025 template<int mydim, int coorddim, class GridImp> 00026 class ALU2dGridGeometry; 00027 template<class GridImp> 00028 class ALU2dGridHierarchicIterator; 00029 template<class GridImp> 00030 class ALU2dGridIntersectionBase; 00031 template<class GridImp> 00032 class ALU2dGridLeafIntersectionIterator; 00033 template<class GridImp> 00034 class ALU2dGridLevelIntersectionIterator; 00035 template<int codim, PartitionIteratorType pitype, class GridImp> 00036 class ALU2dGridLeafIterator; 00037 template< int dim, int dimworld, ALU2DSPACE ElementType eltype > 00038 class ALU2dGrid; 00039 00040 00041 00042 // ALU2DIntersectionGeometryStorage 00043 // -------------------------------- 00044 00045 template< class LocalGeometryImpl > 00046 class ALU2DIntersectionGeometryStorage 00047 { 00048 typedef ALU2DIntersectionGeometryStorage< LocalGeometryImpl > ThisType; 00049 00050 // one geometry for each face and twist 0 and 1 00051 LocalGeometryImpl geoms_[ 2 ][ 4 ][ 2 ]; 00052 //std::vector< LocalGeometryImpl > geoms_[ 2 ][ 4 ]; 00053 00054 private: 00055 ALU2DIntersectionGeometryStorage (); 00056 00057 public: 00058 // return reference to local geometry 00059 const LocalGeometryImpl &localGeom ( const int aluFace, const int twist, const int corners ) const 00060 { 00061 assert( corners == 3 || corners == 4 ); 00062 assert( 0 <= aluFace && aluFace < corners ); 00063 assert( twist == 0 || twist == 1 ); 00064 return geoms_[ corners-3 ][ aluFace ][ twist ]; 00065 } 00066 00067 // return static instance 00068 static const ThisType &instance () 00069 { 00070 static const ThisType geomStorage; 00071 return geomStorage; 00072 } 00073 }; 00074 00075 00076 00077 //********************************************************************** 00078 // 00079 // --ALU2dGridIntersectionBase 00080 // --IntersectionBase 00081 //********************************************************************** 00090 template<class GridImp> 00091 class ALU2dGridIntersectionBase 00092 { 00093 static const int dim = GridImp::dimension; 00094 static const int dimworld = GridImp::dimensionworld; 00095 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00096 00097 typedef typename GridImp::Traits::template Codim< 1 >::GeometryImpl GeometryImpl; 00098 typedef typename GridImp::Traits::template Codim< 1 >::LocalGeometryImpl LocalGeometryImpl; 00099 00100 public: 00101 typedef typename GridImp :: GridObjectFactoryType FactoryType; 00102 00103 typedef ALU2dGridIntersectionBase< GridImp > ImplementationType; 00105 typedef Dune::Intersection< GridImp, Dune::ALU2dGridIntersectionBase > Intersection; 00106 00107 enum { dimension = GridImp::dimension }; 00108 enum { dimensionworld = GridImp::dimensionworld }; 00109 00110 typedef typename GridImp::template Codim<0>::Entity Entity; 00111 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00112 00113 typedef typename GridImp::template Codim<1>::Geometry Geometry; 00114 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry; 00115 typedef ALU2dGridEntity<0,dim,GridImp> EntityImp; 00116 typedef FieldVector< alu2d_ctype, dimworld > NormalType; 00117 typedef FieldVector< alu2d_ctype, dim-1 > LocalCoordinate; 00118 00119 typedef ALU2dGridEntityPointer<0,GridImp> EntityPointerImp; 00120 00121 typedef typename ALU2dImplTraits< dimworld, eltype >::ThinelementType ThinelementType; 00122 typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType; 00123 typedef typename ALU2dImplTraits< dimworld, eltype >::HBndElType HBndElType; 00124 00125 // type of local geometry storage 00126 typedef ALU2DIntersectionGeometryStorage< LocalGeometryImpl > LocalGeometryStorageType; 00127 00128 typedef ALU2dGridIntersectionBase<GridImp> ThisType; 00129 friend class LevelIntersectionIteratorWrapper<GridImp>; 00130 friend class LeafIntersectionIteratorWrapper<GridImp>; 00131 00132 friend class IntersectionIteratorWrapper<GridImp,ThisType>; 00133 00134 protected: 00135 struct impl 00136 { 00137 explicit impl( HElementType *inside = 0 ) 00138 : index_(0), useOutside_(false) 00139 { 00140 setInside( inside ); 00141 setOutside( 0, -1 ); 00142 } 00143 00144 HElementType *inside () const 00145 { 00146 return inside_; 00147 } 00148 00149 int nFaces () const 00150 { 00151 return nFaces_; 00152 } 00153 00154 bool isBoundary () const 00155 { 00156 assert( inside() && (index_ < nFaces()) && inside()->neighbour( index_ ) ); 00157 return inside()->neighbour( index_ )->thinis( ThinelementType::bndel_like ); 00158 } 00159 00160 HBndElType *boundary () const 00161 { 00162 assert( isBoundary() ); 00163 return (HBndElType *)inside()->neighbour( index_ ); 00164 } 00165 00166 HElementType *outside () const 00167 { 00168 return outside_; 00169 } 00170 00171 int opposite () const 00172 { 00173 return opposite_; 00174 } 00175 00176 void setInside ( HElementType *inside ) 00177 { 00178 inside_ = inside; 00179 nFaces_ = (inside != 0 ? inside->numfaces() : 0); 00180 } 00181 00182 void setOutside ( HElementType *outside, int opposite ) 00183 { 00184 outside_ = outside; 00185 opposite_ = opposite; 00186 } 00187 00188 private: 00189 // current element from which we started the intersection iterator 00190 HElementType *inside_; 00191 HElementType *outside_; 00192 int nFaces_; 00193 int opposite_; 00194 00195 public: 00196 mutable int index_; 00197 mutable bool useOutside_; 00198 } current; 00199 00200 public: 00202 ALU2dGridIntersectionBase(const FactoryType& factory, int wLevel); 00203 00205 ALU2dGridIntersectionBase(const ThisType & org); 00206 00207 virtual ~ALU2dGridIntersectionBase() {} 00208 00210 void assign (const ThisType & org); 00211 00212 const Intersection &dereference () const 00213 { 00214 return reinterpret_cast< const Intersection & >( *this ); 00215 } 00216 00218 bool equals (const ThisType & i) const; 00219 00221 int level () const; 00222 00224 bool boundary() const; 00225 00227 int boundaryId () const; 00228 00230 size_t boundarySegmentIndex() const; 00231 00233 bool neighbor () const; 00234 00236 EntityPointer inside() const; 00237 00239 EntityPointer outside() const; 00240 00242 int indexInInside () const; 00243 00245 int indexInOutside () const; 00246 00247 int twistInInside () const; 00248 int twistInOutside () const; 00249 00250 // deprecated methods 00251 int twistInSelf () const { return twistInInside(); } 00252 // deprecated methods 00253 int twistInNeighbor () const { return twistInOutside(); } 00254 00255 NormalType outerNormal ( const LocalCoordinate &local ) const; 00256 NormalType integrationOuterNormal ( const LocalCoordinate &local ) const; 00257 NormalType unitOuterNormal ( const LocalCoordinate &local ) const; 00258 00259 LocalGeometry geometryInInside () const; 00260 LocalGeometry geometryInOutside () const; 00261 Geometry geometry () const; 00262 00264 GeometryType type () const; 00265 00266 protected: 00267 const GridImp& grid() const { return factory_.grid(); } 00268 00269 virtual bool conforming() const = 0; 00270 00272 void checkValid () ; 00273 00274 // set interator to end iterator 00275 void done ( const HElementType *inside ); 00276 void done ( const EntityImp &en ) { done( &en.getItem() ); } 00277 00278 // invalidate status of internal objects 00279 void unsetUp2Date() ; 00280 00281 // reset IntersectionIterator to first neighbour 00282 void first ( const EntityImp &en, int wLevel ); 00283 00284 // reset IntersectionIterator to first neighbour 00285 virtual void setFirstItem ( const HElementType &elem, int wLevel ) = 0; 00286 00287 // the local geometries 00288 mutable GeometryImpl intersectionGlobal_; 00289 mutable LocalGeometryImpl intersectionSelfLocal_; 00290 mutable LocalGeometryImpl intersectionNeighborLocal_; 00291 00292 // reference to factory 00293 const FactoryType& factory_; 00294 const LocalGeometryStorageType &localGeomStorage_; 00295 00296 mutable int walkLevel_; 00297 }; // end ALU2dGridIntersectionBase 00298 00299 00300 00301 00302 //********************************************************************** 00303 // 00304 // --ALU2dGridLevelIntersectionIterator 00305 // --IntersectionLevelIterator 00306 //********************************************************************** 00307 00308 template< class GridImp > 00309 class ALU2dGridLevelIntersectionIterator 00310 : public ALU2dGridIntersectionBase< GridImp > 00311 { 00312 typedef ALU2dGridLevelIntersectionIterator< GridImp > ThisType; 00313 typedef ALU2dGridIntersectionBase< GridImp > BaseType; 00314 00315 static const int dim = GridImp::dimension; 00316 static const int dimworld = GridImp::dimensionworld; 00317 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00318 00319 typedef typename ALU2dImplTraits< dimworld, eltype >::ThinelementType ThinelementType; 00320 typedef typename BaseType::HElementType HElementType; 00321 typedef typename ALU2dImplTraits< dimworld, eltype >::HBndElType HBndElType; 00322 typedef typename ALU2dImplTraits< dimworld, eltype >::PeriodicBndElType PeriodicBndElType; 00323 00324 friend class LevelIntersectionIteratorWrapper<GridImp>; 00325 00326 friend class IntersectionIteratorWrapper<GridImp,ThisType>; 00327 00328 typedef std::pair< HElementType *, int > IntersectionInfo; 00329 00330 public: 00331 typedef typename GridImp :: GridObjectFactoryType FactoryType; 00332 typedef ALUMemoryProvider< ThisType > StorageType; 00333 00334 enum { dimension = GridImp::dimension }; 00335 enum { dimensionworld = GridImp::dimensionworld }; 00336 00337 typedef typename GridImp::template Codim<0>::Entity Entity; 00338 00339 typedef typename GridImp::template Codim<1>::Geometry Geometry; 00340 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry; 00341 typedef ALU2dGridEntity<0,dim,GridImp> EntityImp; 00342 typedef ALU2dGridGeometry<dim-1,dimworld,GridImp> GeometryImp; 00343 typedef ALU2dGridGeometry<dim-1,dim,GridImp> LocalGeometryImp; 00344 typedef FieldVector<alu2d_ctype, dimworld> NormalType; 00345 typedef ALU2dGridEntityPointer<0,GridImp> EntityPointer; 00346 00347 typedef MakeableInterfaceObject< Geometry > GeometryObject; 00348 00350 ALU2dGridLevelIntersectionIterator(const FactoryType& factory, int wLevel); 00351 00353 ALU2dGridLevelIntersectionIterator(const FactoryType& factory, const HElementType* el, int wLevel, bool end=true); 00354 00356 ALU2dGridLevelIntersectionIterator(const ALU2dGridLevelIntersectionIterator<GridImp> & org); 00357 00358 void assign (const ALU2dGridLevelIntersectionIterator<GridImp> & org); 00359 00361 void increment (); 00362 00363 public: 00366 bool conforming () const 00367 { 00368 return (this->grid().nonConform() || isConform()); 00369 } 00370 00371 protected: 00372 bool isConform() const 00373 { 00374 return (!current.outside() || (current.outside() == current.inside()->neighbour( current.index_ ))); 00375 } 00376 00377 private: 00378 void doIncrement (); 00379 00380 // reset IntersectionIterator to first neighbour 00381 void setFirstItem(const HElementType & elem, int wLevel); 00382 00383 // reset IntersectionIterator to first neighbour 00384 template <class EntityType> 00385 void first(const EntityType & en, int wLevel); 00386 00387 void addNeighboursToStack(); 00388 00389 static int getOppositeInFather ( int nrInChild, int nrOfChild ); 00390 static int getOppositeInChild ( int nrInFather, int nrOfChild ); 00391 00392 void setupIntersection (); 00393 00394 protected: 00395 using BaseType::done; 00396 00397 using BaseType::current; 00398 using BaseType::walkLevel_; 00399 00400 private: 00401 mutable std::stack<IntersectionInfo> nbStack_; 00402 }; // end ALU2dGridLevelIntersectionIterator 00403 00404 00405 00406 //******************************************************************** 00407 // 00408 // --ALU2dGridLeafIntersectionIterator 00409 // 00410 // 00411 //******************************************************************** 00412 00413 template< class GridImp > 00414 class ALU2dGridLeafIntersectionIterator 00415 : public ALU2dGridIntersectionBase< GridImp > 00416 { 00417 typedef ALU2dGridLeafIntersectionIterator< GridImp > ThisType; 00418 typedef ALU2dGridIntersectionBase< GridImp > BaseType; 00419 00420 friend class LeafIntersectionIteratorWrapper<GridImp>; 00421 friend class IntersectionIteratorWrapper<GridImp,ThisType>; 00422 00423 static const int dim = GridImp::dimension; 00424 static const int dimworld = GridImp::dimensionworld; 00425 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00426 00427 public: 00428 typedef typename GridImp :: GridObjectFactoryType FactoryType; 00429 typedef ALUMemoryProvider< ThisType > StorageType; 00430 00431 enum { dimension = GridImp::dimension }; 00432 enum { dimensionworld = GridImp::dimensionworld }; 00433 00434 private: 00435 typedef typename ALU2dImplTraits< dimworld, eltype >::ThinelementType ThinelementType; 00436 typedef typename BaseType::HElementType HElementType; 00437 typedef typename ALU2dImplTraits< dimworld, eltype >::HBndElType HBndElType; 00438 typedef typename ALU2dImplTraits< dimworld, eltype >::PeriodicBndElType PeriodicBndElType; 00439 00440 typedef std::pair< HElementType *, int > IntersectionInfo; 00441 00442 public: 00443 typedef typename GridImp::template Codim<0>::Entity Entity; 00444 typedef typename GridImp::template Codim<1>::Geometry Geometry; 00445 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry; 00446 typedef ALU2dGridEntity<0,dim,GridImp> EntityImp; 00447 typedef ALU2dGridGeometry<dim-1,dimworld,GridImp> GeometryImp; 00448 typedef ALU2dGridGeometry<dim-1,dim,GridImp> LocalGeometryImp; 00449 typedef FieldVector<alu2d_ctype, dimworld> NormalType; 00450 typedef ALU2dGridEntityPointer<0,GridImp> EntityPointer; 00451 00452 typedef MakeableInterfaceObject< Geometry > GeometryObject; 00453 00455 ALU2dGridLeafIntersectionIterator(const FactoryType& factory, int wLevel); 00456 00458 ALU2dGridLeafIntersectionIterator(const FactoryType& factory, const HElementType* el, int wLevel, bool end=true); 00459 00461 ALU2dGridLeafIntersectionIterator(const ALU2dGridLeafIntersectionIterator<GridImp> & org); 00462 00463 void assign (const ALU2dGridLeafIntersectionIterator<GridImp> & org); 00464 00466 void increment (); 00467 00468 public: 00470 bool conforming () const 00471 { 00472 return (!this->grid().nonConform() || isConform()); 00473 } 00474 00475 protected: 00476 bool isConform() const 00477 { 00478 return (!current.outside() || (current.outside()->level() == current.inside()->level()) ); 00479 } 00480 00481 private: 00482 void doIncrement (); 00483 // reset IntersectionIterator to first neighbour 00484 void setFirstItem(const HElementType & elem, int wLevel); 00485 00486 // reset IntersectionIterator to first neighbour 00487 template <class EntityType> 00488 void first(const EntityType & en, int wLevel); 00489 00490 void setupIntersection (); 00491 00492 protected: 00493 using BaseType::done; 00494 00495 using BaseType::current; 00496 using BaseType::walkLevel_; 00497 00498 private: 00499 std::stack<IntersectionInfo> nbStack_; 00500 00501 }; // end ALU2dGridLeafIntersectionIterator 00502 00503 } // end namespace Dune 00504 00505 #include "intersection_imp.cc" 00506 #if COMPILE_ALU2DGRID_INLINE 00507 #include "intersection.cc" 00508 #endif 00509 00510 #endif // #ifndef DUNE_ALU2DGRID_INTERSECTION_HH