5#ifndef DUNE_GEOGRID_GEOMETRY_HH
6#define DUNE_GEOGRID_GEOMETRY_HH
12#include <dune/geometry/multilineargeometry.hh>
13#include <dune/geometry/referenceelements.hh>
17#include <dune/grid/geometrygrid/cornerstorage.hh>
28 template<
class hasSingleGeometryType,
int dim,
int mydim >
29 struct InferHasSingleGeometryType
32 static const unsigned int id = hasSingleGeometryType::topologyId;
33 static const unsigned int idMask = (1u << mydim) - 1u;
36 static const bool v = hasSingleGeometryType::v && ((mydim == dim) || ((
id | 1u) == 1u) || ((
id | 1u) == idMask));
37 static const unsigned int topologyId = (v ?
id & idMask : ~0u);
40 template<
class hasSingleGeometryType,
int dim >
41 struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 1 >
43 static const bool v =
true;
47 template<
class hasSingleGeometryType,
int dim >
48 struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 0 >
50 static const bool v =
true;
59 template<
class Gr
id >
62 typedef typename std::remove_const< Grid >::type::Traits Traits;
64 typedef typename Traits::ctype ctype;
66 typedef Impl::FieldMatrixHelper< ctype > MatrixHelper;
68 static ctype tolerance () {
return 16 * std::numeric_limits< ctype >::epsilon(); }
70 template<
int mydim,
int cdim >
73 typedef GeoGrid::CornerStorage< mydim, cdim, Grid > Type;
77 struct hasSingleGeometryType
78 :
public InferHasSingleGeometryType< Capabilities::hasSingleGeometryType< Grid >, Traits::dimension, mydim >
87 template<
int mydim,
int cdim,
class Gr
id >
90 typedef Geometry< mydim, cdim, Grid > This;
92 typedef typename std::remove_const< Grid >::type::Traits Traits;
94 template<
int,
int,
class >
friend class Geometry;
97 typedef typename Traits::ctype ctype;
99 static const int mydimension = mydim;
100 static const int coorddimension = cdim;
101 static const int dimension = Traits::dimension;
102 static const int codimension = dimension - mydimension;
105 typedef CachedMultiLinearGeometry< ctype, mydimension, coorddimension, GeometryTraits< Grid > > BasicMapping;
108 :
public BasicMapping
110 template<
class CoordVector >
111 Mapping (
const GeometryType &type,
const CoordVector &coords )
112 : BasicMapping( type, coords ),
116 void addReference () { ++refCount_; }
117 bool removeReference () {
return (--refCount_ == 0); }
120 unsigned int refCount_;
124 typedef typename Mapping::LocalCoordinate LocalCoordinate;
125 typedef typename Mapping::GlobalCoordinate GlobalCoordinate;
127 typedef typename Mapping::JacobianTransposed JacobianTransposed;
128 typedef typename Mapping::JacobianInverseTransposed JacobianInverseTransposed;
129 typedef typename Mapping::Jacobian Jacobian;
130 typedef typename Mapping::JacobianInverse JacobianInverse;
133 Geometry () : grid_( nullptr ), mapping_( nullptr ) {}
135 explicit Geometry (
const Grid &grid ) : grid_( &grid ), mapping_( nullptr ) {}
137 template<
class CoordVector >
138 Geometry (
const Grid &grid,
const GeometryType &type,
const CoordVector &coords )
141 assert(
int( type.dim() ) == mydimension );
142 void *mappingStorage = grid.allocateStorage(
sizeof( Mapping ) );
143 mapping_ =
new( mappingStorage ) Mapping( type, coords );
144 mapping_->addReference();
147 Geometry (
const This &other )
148 : grid_( other.grid_ ),
149 mapping_( other.mapping_ )
152 mapping_->addReference();
155 Geometry ( This&& other )
156 : grid_( other.grid_ ),
157 mapping_( other.mapping_ )
159 other.grid_ =
nullptr;
160 other.mapping_ =
nullptr;
165 if( mapping_ && mapping_->removeReference() )
169 const This &operator= (
const This &other )
172 other.mapping_->addReference();
173 if( mapping_ && mapping_->removeReference() )
176 mapping_ = other.mapping_;
180 const This &operator= ( This&& other )
183 swap( grid_, other.grid_ );
184 swap( mapping_, other.mapping_ );
188 explicit operator bool ()
const {
return bool( mapping_ ); }
190 bool affine ()
const {
return mapping_->affine(); }
193 int corners ()
const {
return mapping_->corners(); }
194 GlobalCoordinate corner (
const int i )
const {
return mapping_->corner( i ); }
195 GlobalCoordinate center ()
const {
return mapping_->center(); }
197 GlobalCoordinate global (
const LocalCoordinate &local )
const {
return mapping_->global( local ); }
198 LocalCoordinate local (
const GlobalCoordinate &global )
const {
return mapping_->local( global ); }
200 ctype integrationElement (
const LocalCoordinate &local )
const {
return mapping_->integrationElement( local ); }
201 ctype volume ()
const {
return mapping_->volume(); }
203 JacobianTransposed jacobianTransposed (
const LocalCoordinate &local )
const {
return mapping_->jacobianTransposed( local ); }
204 JacobianInverseTransposed jacobianInverseTransposed (
const LocalCoordinate &local )
const {
return mapping_->jacobianInverseTransposed( local ); }
206 Jacobian jacobian (
const LocalCoordinate &local )
const {
return mapping_->jacobian( local ); }
207 JacobianInverse jacobianInverse (
const LocalCoordinate &local )
const {
return mapping_->jacobianInverse( local ); }
209 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
212 void destroyMapping ()
214 mapping_->~Mapping();
215 grid().deallocateStorage( mapping_,
sizeof( Mapping ) );
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:365
A set of traits classes to store static information about grid implementation.
Traits for type conversions and type information.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:462
Dune namespace.
Definition: alignedallocator.hh:13
A unique label for each type of element that can occur in a grid.