dune-grid  2.2.0
hostcorners.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GEOGRID_HOSTCORNERS_HH
00002 #define DUNE_GEOGRID_HOSTCORNERS_HH
00003 
00004 #include <dune/geometry/type.hh>
00005 
00006 #include <dune/grid/alugrid/3d/topology.hh>
00007 #include <dune/grid/common/entity.hh>
00008 
00009 namespace Dune
00010 {
00011 
00012   // External Forward Declarations
00013   // -----------------------------
00014 
00015   template< int, int, class >
00016   class ALU3dGridEntity;
00017 
00018   template< ALU3dGridElementType, class >
00019   struct ALU3dImplTraits;
00020 
00021 
00022 
00023   namespace GeoGrid
00024   {
00025 
00026     // HostCorners
00027     // -----------
00028 
00029     template< class HostEntity >
00030     class HostCorners
00031     {
00032       typedef typename HostEntity::Geometry HostGeometry;
00033 
00034     public:
00035       typedef typename HostGeometry::GlobalCoordinate Coordinate;
00036 
00037       explicit HostCorners ( const HostEntity &hostEntity )
00038       : hostGeometry_( hostEntity.geometry() )
00039       {}
00040 
00041       GeometryType type () const
00042       {
00043         return hostGeometry_.type();
00044       }
00045 
00046       Coordinate corner ( const int i ) const
00047       {
00048         return hostGeometry_.corner( i );
00049       }
00050 
00051       unsigned int numCorners () const
00052       {
00053         return hostGeometry_.corners();
00054       }
00055 
00056     private:
00057       HostGeometry hostGeometry_;
00058     };
00059 
00060 
00061 
00062     // HostCorners for ALU3dGrid
00063     // -------------------------
00064 
00065 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
00066     template< int dim, class Grid >
00067     class HostCorners< Dune::Entity< 0, dim, Grid, ALU3dGridEntity > >
00068     {
00069       typedef Dune::Entity< 0, dim, Grid, ALU3dGridEntity > HostEntity;
00070 
00071       typedef double ALUCoordinate[ 3 ];
00072 
00073       static const ALU3dGridElementType elementType = remove_const< Grid >::type::elementType;
00074       typedef Dune::ElementTopologyMapping< elementType > ElementTopologyMapping;
00075 
00076       typedef typename remove_const< Grid >::type::MPICommunicatorType Comm;
00077       typedef ALU3dImplTraits< elementType, Comm > ImplTraits;
00078         
00079     public:
00080       typedef FieldVector< double, 3 > Coordinate;
00081 
00082       explicit HostCorners ( const HostEntity &hostEntity )
00083       : item_( hostEntity.impl().getItem() )
00084       {}
00085 
00086       GeometryType type () const
00087       {
00088         if( elementType == tetra )
00089           return GeometryType( GenericGeometry::SimplexTopology< dim >::type::id, dim );
00090         else
00091           return GeometryType( GenericGeometry::CubeTopology< dim >::type::id, dim );
00092       }
00093 
00094       Coordinate corner ( const int i ) const
00095       {
00096         const int j = ElementTopologyMapping::dune2aluVertex( i );
00097         const ALUCoordinate &point = item_.myvertex( j )->Point();
00098 
00099         Coordinate corner;
00100         for( int k = 0; k < 3; ++k )
00101           corner[ k ] = point[ k ];
00102         return corner;
00103       }
00104 
00105       unsigned int numCorners () const
00106       {
00107         return (elementType == tetra ? dim+1 : (1 << dim));
00108       }
00109 
00110     private:
00111       const typename ImplTraits::IMPLElementType &item_;
00112     };
00113 #endif // #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
00114 
00115   } // namespace GeoGrid
00116 
00117 } // namespace Dune
00118 
00119 #endif // #ifndef DUNE_GEOGRID_HOSTCORNERS_HH