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