3#ifndef DUNE_GEOGRID_GEOMETRY_HH 
    4#define DUNE_GEOGRID_GEOMETRY_HH 
   11#include <dune/geometry/referenceelements.hh> 
   12#include <dune/geometry/multilineargeometry.hh> 
   15#include <dune/grid/geometrygrid/cornerstorage.hh> 
   26    template< 
class hasSingleGeometryType, 
int dim, 
int mydim >
 
   27    struct InferHasSingleGeometryType
 
   30      static const unsigned int id = hasSingleGeometryType::topologyId;
 
   31      static const unsigned int idMask = (1u << mydim) - 1u;
 
   34      static const bool v = hasSingleGeometryType::v && ((mydim == dim) || ((
id | 1u) == 1u) || ((
id | 1u) == idMask));
 
   35      static const unsigned int topologyId = (v ? 
id & idMask : ~0u);
 
   38    template< 
class hasSingleGeometryType, 
int dim >
 
   39    struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 1 >
 
   41      static const bool v = 
true;
 
   42      static const unsigned int topologyId = GenericGeometry::CubeTopology< 1 >::type::id;
 
   45    template< 
class hasSingleGeometryType, 
int dim >
 
   46    struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 0 >
 
   48      static const bool v = 
true;
 
   49      static const unsigned int topologyId = GenericGeometry::CubeTopology< 0 >::type::id;
 
   57    template< 
class Gr
id >
 
   60      typedef typename remove_const< Grid >::type::Traits Traits;
 
   62      typedef typename Traits::ctype ctype;
 
   64      typedef GenericGeometry::MatrixHelper< GenericGeometry::DuneCoordTraits< ctype > > MatrixHelper;
 
   66      static ctype tolerance () { 
return 16 * std::numeric_limits< ctype >::epsilon(); }
 
   68      template< 
int mydim, 
int cdim >
 
   71        typedef GeoGrid::CornerStorage< mydim, cdim, Grid > Type;
 
   75      struct hasSingleGeometryType
 
   76        : 
public InferHasSingleGeometryType< Capabilities::hasSingleGeometryType< Grid >, Traits::dimension, mydim >
 
   85    template< 
int mydim, 
int cdim, 
class Gr
id >
 
   88      typedef Geometry< mydim, cdim, Grid > This;
 
   90      typedef typename remove_const< Grid >::type::Traits Traits;
 
   92      template< 
int, 
int, 
class > 
friend class Geometry;
 
   95      typedef typename Traits::ctype ctype;
 
   97      static const int mydimension = mydim;
 
   98      static const int coorddimension = cdim;
 
   99      static const int dimension = Traits::dimension;
 
  100      static const int codimension = dimension - mydimension;
 
  103      typedef CachedMultiLinearGeometry< ctype, mydimension, coorddimension, GeometryTraits< Grid > > BasicMapping;
 
  106        : 
public BasicMapping
 
  108        template< 
class CoordVector >
 
  109        Mapping ( 
const GeometryType &type, 
const CoordVector &coords )
 
  110          : BasicMapping( type, coords ),
 
  114        void addReference () { ++refCount_; }
 
  115        bool removeReference () { 
return (--refCount_ == 0); }
 
  118        unsigned int refCount_;
 
  122      typedef typename Mapping::LocalCoordinate LocalCoordinate;
 
  123      typedef typename Mapping::GlobalCoordinate GlobalCoordinate;
 
  125      typedef typename Mapping::JacobianTransposed JacobianTransposed;
 
  126      typedef typename Mapping::JacobianInverseTransposed JacobianInverseTransposed;
 
  128      Geometry () : grid_( nullptr ), mapping_( nullptr ) {}
 
  130      explicit Geometry ( 
const Grid &grid ) : grid_( &grid ), mapping_( nullptr ) {}
 
  132      template< 
class CoordVector >
 
  133      Geometry ( 
const Grid &grid, 
const GeometryType &type, 
const CoordVector &coords )
 
  136        assert( 
int( type.dim() ) == mydimension );
 
  137        void *mappingStorage = grid.allocateStorage( 
sizeof( Mapping ) );
 
  138        mapping_ = 
new( mappingStorage ) Mapping( type, coords );
 
  139        mapping_->addReference();
 
  142      Geometry ( 
const This &other )
 
  143        : grid_( other.grid_ ),
 
  144          mapping_( other.mapping_ )
 
  147          mapping_->addReference();
 
  150      Geometry ( This&& other )
 
  151        : grid_( other.grid_ ),
 
  152          mapping_( other.mapping_ )
 
  154        other.grid_ = 
nullptr;
 
  155        other.mapping_ = 
nullptr;
 
  160        if( mapping_ && mapping_->removeReference() )
 
  164      const This &operator= ( 
const This &other )
 
  167          other.mapping_->addReference();
 
  168        if( mapping_ && mapping_->removeReference() )
 
  171        mapping_ = other.mapping_;
 
  175      const This &operator= ( This&& other )
 
  178        swap( grid_, other.grid_ );
 
  179        swap( mapping_, other.mapping_ );
 
  183      operator bool ()
 const { 
return bool( mapping_ ); }
 
  185      bool affine ()
 const { 
return mapping_->affine(); }
 
  188      int corners ()
 const { 
return mapping_->corners(); }
 
  189      GlobalCoordinate corner ( 
const int i )
 const { 
return mapping_->corner( i ); }
 
  190      GlobalCoordinate center ()
 const { 
return mapping_->center(); }
 
  192      GlobalCoordinate global ( 
const LocalCoordinate &local )
 const { 
return mapping_->global( local ); }
 
  193      LocalCoordinate local ( 
const GlobalCoordinate &global )
 const { 
return mapping_->local( global ); }
 
  195      ctype integrationElement ( 
const LocalCoordinate &local )
 const { 
return mapping_->integrationElement( local ); }
 
  196      ctype volume ()
 const { 
return mapping_->volume(); }
 
  198      JacobianTransposed jacobianTransposed ( 
const LocalCoordinate &local )
 const { 
return mapping_->jacobianTransposed( local ); }
 
  199      JacobianInverseTransposed jacobianInverseTransposed ( 
const LocalCoordinate &local )
 const { 
return mapping_->jacobianInverseTransposed( local ); }
 
  201      const Grid &grid ()
 const { assert( grid_ ); 
return *grid_; }
 
  204      void destroyMapping ()
 
  206        mapping_->~Mapping();
 
  207        grid().deallocateStorage( mapping_, 
sizeof( Mapping ) );
 
A set of traits classes to store static information about grid implementation.
 
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
 
Dune namespace.
Definition: alignment.hh:10
 
Fallback implementation of the nullptr object in C++0x.
 
Traits for type conversions and type information.