dune-grid  2.2.0
geometrygrid/intersection.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GEOGRID_INTERSECTION_HH
00002 #define DUNE_GEOGRID_INTERSECTION_HH
00003 
00004 #include <dune/grid/geometrygrid/declaration.hh>
00005 #include <dune/grid/geometrygrid/entitypointer.hh>
00006 #include <dune/grid/geometrygrid/cornerstorage.hh>
00007 
00008 namespace Dune
00009 {
00010 
00011   namespace GeoGrid
00012   {
00013   
00014     // Internal Forward Declarations
00015     // -----------------------------
00016     
00017     template< class Grid >
00018     class LeafIntersection;
00019     
00020     template< class Grid >
00021     class LevelIntersection;
00022     
00023 
00024 
00025     // Intersection
00026     // ------------
00027 
00028     template< class Grid, class HostIntersection >
00029     class Intersection
00030     {
00031       typedef typename HostIntersection::Geometry HostGeometry;
00032       typedef typename HostIntersection::LocalGeometry HostLocalGeometry;
00033 
00034       typedef typename remove_const< Grid >::type::Traits Traits;
00035 
00036     public:
00037       typedef typename Traits::ctype ctype;
00038       
00039       static const int dimension = Traits::dimension;
00040       static const int dimensionworld = Traits::dimensionworld;
00041 
00042       typedef typename Traits::template Codim< 0 >::Entity Entity;
00043       typedef typename Traits::template Codim< 0 >::EntityPointer EntityPointer;
00044       typedef typename Traits::template Codim< 1 >::Geometry Geometry;
00045       typedef typename Traits::template Codim< 1 >::LocalGeometry LocalGeometry;
00046 
00047       typedef typename Traits::template Codim< 0 >::Geometry ElementGeometry;
00048 
00049     private:
00050       typedef GeoGrid::IntersectionCoordVector< Grid > CoordVector;
00051 
00052       typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
00053 
00054       typedef typename Traits::template Codim< 1 >::GeometryImpl GeometryImpl;
00055       typedef typename Traits::template Codim< 0 >::GeometryImpl ElementGeometryImpl;
00056 
00057     public:
00058       explicit Intersection ( const ElementGeometry &insideGeo )
00059       : insideGeo_( Grid::getRealImplementation( insideGeo ) ),
00060         hostIntersection_( 0 ),
00061         geo_( grid() )
00062       {}
00063 
00064       Intersection ( const Intersection &other )
00065       : insideGeo_( other.insideGeo_ ),
00066         hostIntersection_( 0 ),
00067         geo_( grid() )
00068       {}
00069 
00070       const Intersection &operator= ( const Intersection &other )
00071       {
00072         insideGeo_ = other.insideGeo_;
00073         invalidate();
00074         return *this;
00075       }
00076 
00077       operator bool () const { return bool( hostIntersection_ ); }
00078 
00079       EntityPointer inside () const
00080       {
00081         return EntityPointerImpl( insideGeo_, hostIntersection().inside() );
00082       }
00083       
00084       EntityPointer outside () const
00085       {
00086         return EntityPointerImpl( grid(), hostIntersection().outside() );
00087       }
00088 
00089       bool boundary () const { return hostIntersection().boundary(); }
00090 
00091       bool conforming () const { return hostIntersection().conforming(); }
00092           
00093       bool neighbor () const { return hostIntersection().neighbor(); }
00094           
00095       int boundaryId () const { return hostIntersection().boundaryId(); }
00096           
00097       size_t boundarySegmentIndex () const
00098       {
00099         return hostIntersection().boundarySegmentIndex();
00100       }
00101           
00102       LocalGeometry geometryInInside () const
00103       {
00104         return hostIntersection().geometryInInside();
00105       }
00106       
00107       LocalGeometry geometryInOutside () const
00108       {
00109         return hostIntersection().geometryInOutside();
00110       }
00111      
00112       Geometry geometry () const
00113       {
00114         if( !geo_ )
00115         {
00116           CoordVector coords( insideGeo_, geometryInInside() );
00117           geo_ = GeometryImpl( grid(), type(), coords );
00118         }
00119         return Geometry( geo_ );
00120       }
00121 
00122       GeometryType type () const { return hostIntersection().type(); }
00123 
00124       unsigned int topologyId () const DUNE_DEPRECATED
00125       {
00126         return type().id();
00127       }
00128           
00129       int indexInInside () const
00130       {
00131         return hostIntersection().indexInInside();
00132       }
00133       
00134       int indexInOutside () const
00135       {
00136         return hostIntersection().indexInOutside();
00137       }
00138       
00139       FieldVector< ctype, dimensionworld >
00140       integrationOuterNormal ( const FieldVector< ctype, dimension-1 > &local ) const
00141       {
00142         const GenericReferenceElement< ctype, dimension > &refElement
00143           = GenericReferenceElements< ctype, dimension>::general( insideGeo_.type() );
00144 
00145         FieldVector< ctype, dimension > x( geometryInInside().global( local ) );
00146         const typename ElementGeometryImpl::JacobianInverseTransposed &jit = insideGeo_.jacobianInverseTransposed( x );
00147         const FieldVector< ctype, dimension > &refNormal = refElement.volumeOuterNormal( indexInInside() );
00148 
00149         FieldVector< ctype, dimensionworld > normal;
00150         jit.mv( refNormal, normal );
00151         normal *= ctype( 1 ) / jit.det();
00152         //normal *= insideGeo_.integrationElement( x );
00153         return normal;
00154       }
00155       
00156       FieldVector< ctype, dimensionworld >
00157       outerNormal ( const FieldVector< ctype, dimension-1 > &local ) const
00158       {
00159         const GenericReferenceElement< ctype, dimension > &refElement
00160           = GenericReferenceElements< ctype, dimension>::general( insideGeo_.type() );
00161 
00162         FieldVector< ctype, dimension > x( geometryInInside().global( local ) );
00163         const typename ElementGeometryImpl::JacobianInverseTransposed &jit = insideGeo_.jacobianInverseTransposed( x );
00164         const FieldVector< ctype, dimension > &refNormal = refElement.volumeOuterNormal( indexInInside() );
00165 
00166         FieldVector< ctype, dimensionworld > normal;
00167         jit.mv( refNormal, normal );
00168         return normal;
00169       }
00170 
00171       FieldVector< ctype, dimensionworld >
00172       unitOuterNormal ( const FieldVector< ctype, dimension-1 > &local ) const
00173       {
00174         FieldVector< ctype, dimensionworld > normal = outerNormal( local );
00175         normal *= (ctype( 1 ) / normal.two_norm());
00176         return normal;
00177       }
00178 
00179       FieldVector< ctype, dimensionworld > centerUnitOuterNormal () const
00180       {
00181         const GenericReferenceElement< ctype, dimension-1 > &refFace
00182           = GenericReferenceElements< ctype, dimension-1 >::general( type() );
00183         return unitOuterNormal( refFace.position( 0, 0 ) );
00184       }
00185 
00186       const HostIntersection &hostIntersection () const
00187       {
00188         assert( *this );
00189         return *hostIntersection_;
00190       }
00191 
00192       const Grid &grid () const { return insideGeo_.grid(); }
00193 
00194       void invalidate ()
00195       {
00196         hostIntersection_ = 0;
00197         geo_ = GeometryImpl( grid() );
00198       }
00199 
00200       void initialize ( const HostIntersection &hostIntersection )
00201       {
00202         assert( !(*this) );
00203         hostIntersection_ = &hostIntersection;
00204       }
00205 
00206     private:
00207       ElementGeometryImpl insideGeo_;
00208       const HostIntersection *hostIntersection_;
00209       mutable GeometryImpl geo_;
00210     };
00211 
00212 
00213 
00214     // LeafIntersection
00215     // ----------------
00216 
00217     template< class HostGrid, class CoordFunction, class Allocator >
00218     class LeafIntersection< const GeometryGrid< HostGrid, CoordFunction, Allocator > >
00219     : public Intersection
00220        < const GeometryGrid< HostGrid, CoordFunction, Allocator >,
00221          typename HostGrid::Traits::LeafIntersection >
00222     {
00223       typedef GeometryGrid< HostGrid, CoordFunction, Allocator > Grid;
00224       typedef typename HostGrid::Traits::LeafIntersection HostIntersection;
00225 
00226       typedef Intersection< const Grid, HostIntersection > Base;
00227 
00228     public:
00229       typedef typename Base::ElementGeometry ElementGeometry;
00230 
00231       explicit LeafIntersection ( const ElementGeometry &insideGeo )
00232       : Base( insideGeo )
00233       {}
00234     };
00235 
00236 
00237     
00238     // LevelIntersection
00239     // -----------------
00240 
00241     template< class HostGrid, class CoordFunction, class Allocator >
00242     class LevelIntersection< const GeometryGrid< HostGrid, CoordFunction, Allocator > >
00243     : public Intersection
00244       < const GeometryGrid< HostGrid, CoordFunction, Allocator >,
00245         typename HostGrid::Traits::LevelIntersection >
00246     {
00247       typedef GeometryGrid< HostGrid, CoordFunction, Allocator > Grid;
00248       typedef typename HostGrid::Traits::LevelIntersection HostIntersection;
00249 
00250       typedef Intersection< const Grid, HostIntersection > Base;
00251 
00252     public:
00253       typedef typename Base::ElementGeometry ElementGeometry;
00254 
00255       explicit LevelIntersection ( const ElementGeometry &insideGeo )
00256       : Base( insideGeo )
00257       {}
00258     };
00259 
00260   } // namespace GeoGrid
00261 
00262 } // namespace Dune
00263 
00264 #endif // #ifndef DUNE_GEOGRID_INTERSECTION_HH