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

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].