dune-grid  2.2.0
cornerstorage.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH
00002 #define DUNE_GEOGRID_CORNERSTORAGE_HH
00003 
00004 #include <dune/grid/geometrygrid/coordfunctioncaller.hh>
00005 
00006 namespace Dune
00007 {
00008 
00009   namespace GeoGrid
00010   {
00011 
00012     // CoordVector
00013     // -----------
00014 
00015     template< int mydim, class Grid, bool fake >
00016     class CoordVector;
00017 
00018 
00019     template< int mydim, class Grid >
00020     class CoordVector< mydim, Grid, false >
00021     {
00022       typedef typename remove_const< Grid >::type::Traits Traits;
00023 
00024       typedef typename Traits::ctype ctype;
00025 
00026       static const int dimension = Traits::dimension;
00027       static const int mydimension = mydim;
00028       static const int codimension = dimension - mydimension;
00029       static const int dimensionworld = Traits::dimensionworld;
00030 
00031       typedef FieldVector< ctype, dimensionworld > Coordinate;
00032 
00033       typedef typename Traits::HostGrid HostGrid;
00034       typedef typename Traits::CoordFunction CoordFunction;
00035 
00036       typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
00037 
00038       typedef GeoGrid :: CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
00039         CoordFunctionCaller;
00040 
00041     public:
00042       CoordVector ( const HostEntity &hostEntity,
00043                     const CoordFunction &coordFunction )
00044       : coordFunctionCaller_( hostEntity, coordFunction )
00045       {}
00046 
00047       template< unsigned int numCorners >
00048       void calculate ( Coordinate (&corners)[ numCorners ] ) const
00049       {
00050         assert( numCorners == coordFunctionCaller_.numCorners() );
00051         for( unsigned int i = 0; i < numCorners; ++i )
00052           coordFunctionCaller_.evaluate( i, corners[ i ] );
00053       }
00054 
00055     private:
00056       const CoordFunctionCaller coordFunctionCaller_;
00057     };
00058 
00059 
00060     template< int mydim, class Grid >
00061     class CoordVector< mydim, Grid, true >
00062     {
00063       typedef typename remove_const< Grid > :: type :: Traits Traits;
00064 
00065       typedef typename Traits::ctype ctype;
00066 
00067       static const int dimension = Traits::dimension;
00068       static const int mydimension = mydim;
00069       static const int codimension = dimension - mydimension;
00070       static const int dimensionworld = Traits::dimensionworld;
00071 
00072       typedef FieldVector< ctype, dimensionworld > Coordinate;
00073 
00074       typedef typename Traits::HostGrid HostGrid;
00075       typedef typename Traits::CoordFunction CoordFunction;
00076 
00077       typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
00078 
00079       typedef GeoGrid::CoordFunctionCaller< HostElement, typename CoordFunction::Interface >
00080         CoordFunctionCaller;
00081 
00082     public:
00083       CoordVector ( const HostElement &hostElement,
00084                     const unsigned int subEntity,
00085                     const CoordFunction &coordFunction )
00086       : coordFunctionCaller_( hostElement, coordFunction ),
00087         subEntity_( subEntity )
00088       {}
00089 
00090       template< unsigned int numCorners >
00091       void calculate ( Coordinate (&corners)[ numCorners ] ) const
00092       {
00093         const GeometryType type = coordFunctionCaller_.type();
00094         const GenericReferenceElement< ctype, dimension > &refElement
00095           = GenericReferenceElements< ctype, dimension >::general( type );
00096         assert( numCorners == refElement.size( subEntity_, codimension, dimension ) );
00097 
00098         for( unsigned int i = 0; i < numCorners; ++i )
00099         {
00100           const unsigned int j = refElement.subEntity( subEntity_, codimension, i, dimension );
00101           coordFunctionCaller_.evaluate( j, corners[ i ] );
00102         }
00103       }
00104 
00105     private:
00106       const CoordFunctionCaller coordFunctionCaller_;
00107       const unsigned int subEntity_;
00108     };
00109 
00110 
00111 
00112     // IntersectionCoordVector
00113     // -----------------------
00114 
00115     template< class Grid >
00116     class IntersectionCoordVector
00117     {
00118       typedef typename remove_const< Grid >::type::Traits Traits;
00119 
00120       typedef typename Traits::ctype ctype;
00121 
00122       static const int dimension = Traits::dimension;
00123       static const int codimension = 1;
00124       static const int mydimension = dimension-codimension;
00125       static const int dimensionworld = Traits::dimensionworld;
00126 
00127       typedef FieldVector< ctype, dimensionworld > Coordinate;
00128 
00129       typedef typename Traits::HostGrid HostGrid;
00130 
00131       typedef typename Traits::template Codim< 0 >::GeometryImpl ElementGeometryImpl;
00132       typedef typename Traits::template Codim< codimension >::LocalGeometry HostLocalGeometry;
00133 
00134     public:
00135       IntersectionCoordVector ( const ElementGeometryImpl &elementGeometry,
00136                                 const HostLocalGeometry &hostLocalGeometry )
00137       : elementGeometry_( elementGeometry ),
00138         hostLocalGeometry_( hostLocalGeometry )
00139       {}
00140 
00141       template< unsigned int numCorners >
00142       void calculate ( Coordinate (&corners)[ numCorners ] ) const
00143       {
00144         assert( numCorners == hostLocalGeometry_.corners() );
00145         for( unsigned int i = 0; i < numCorners; ++i )
00146           corners[ i ] = elementGeometry_.global( hostLocalGeometry_.corner( i ) );
00147       }
00148 
00149     private:
00150       const ElementGeometryImpl &elementGeometry_;
00151       HostLocalGeometry hostLocalGeometry_;
00152     };
00153 
00154 
00155 
00156 
00157     // CornerStorage
00158     // -------------
00159 
00160     template< class Topology, class Grid >
00161     class CornerStorage
00162     {
00163       typedef typename remove_const< Grid >::type::Traits Traits;
00164 
00165       typedef typename Traits::ctype ctype;
00166 
00167       static const int dimension = Traits::dimension;
00168       static const int mydimension = Topology::dimension;
00169       static const int codimension = dimension - mydimension;
00170       static const int dimensionworld = Traits::dimensionworld;
00171 
00172       typedef FieldVector< ctype, dimensionworld > Coordinate;
00173 
00174     public:
00175       static const unsigned int size = Topology::numCorners;
00176 
00177       template< class SubTopology >
00178       struct SubStorage
00179       {
00180         typedef CornerStorage< SubTopology, Grid > type;
00181       };
00182 
00183       template< bool fake >
00184       explicit
00185       CornerStorage ( const CoordVector< mydimension, Grid, fake > &coords )
00186       {
00187         coords.calculate( coords_ );
00188       }
00189 
00190       explicit CornerStorage ( const IntersectionCoordVector< Grid > &coords )
00191       {
00192         coords.calculate( coords_ );
00193       }
00194 
00195       template< class Mapping, unsigned int codim >
00196       explicit
00197       CornerStorage ( const GenericGeometry::SubMappingCoords< Mapping, codim > &coords )
00198       {
00199         for( unsigned int i = 0; i < size; ++i )
00200           coords_[ i ] = coords[ i ];
00201       }
00202 
00203       const Coordinate &operator[] ( unsigned int i ) const
00204       {
00205         return coords_[ i ];
00206       }
00207 
00208     private:
00209       Coordinate coords_[ size ];
00210     };
00211 
00212   } // namespace GeoGrid
00213 
00214 } // namespace Dune
00215 
00216 #endif // #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH