3#ifndef DUNE_GEOGRID_GEOMETRY_HH
4#define DUNE_GEOGRID_GEOMETRY_HH
9#include <dune/geometry/referenceelements.hh>
10#include <dune/geometry/multilineargeometry.hh>
13#include <dune/grid/geometrygrid/cornerstorage.hh>
24 template<
class hasSingleGeometryType,
int dim,
int mydim >
25 struct InferHasSingleGeometryType
28 static const unsigned int id = hasSingleGeometryType::topologyId;
29 static const unsigned int idMask = (1u << mydim) - 1u;
32 static const bool v = hasSingleGeometryType::v && ((mydim == dim) || ((
id | 1u) == 1u) || ((
id | 1u) == idMask));
33 static const unsigned int topologyId = (v ?
id & idMask : ~0u);
36 template<
class hasSingleGeometryType,
int dim >
37 struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 1 >
39 static const bool v =
true;
40 static const unsigned int topologyId = GenericGeometry::CubeTopology< 1 >::type::id;
43 template<
class hasSingleGeometryType,
int dim >
44 struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 0 >
46 static const bool v =
true;
47 static const unsigned int topologyId = GenericGeometry::CubeTopology< 0 >::type::id;
55 template<
class Gr
id >
58 typedef typename remove_const< Grid >::type::Traits Traits;
60 typedef typename Traits::ctype ctype;
62 typedef GenericGeometry::MatrixHelper< GenericGeometry::DuneCoordTraits< ctype > > MatrixHelper;
64 static ctype tolerance () {
return 16 * std::numeric_limits< ctype >::epsilon(); }
66 template<
int mydim,
int cdim >
69 typedef GeoGrid::CornerStorage< mydim, cdim, Grid > Type;
73 struct hasSingleGeometryType
74 :
public InferHasSingleGeometryType< Capabilities::hasSingleGeometryType< Grid >, Traits::dimension, mydim >
83 template<
int mydim,
int cdim,
class Gr
id >
86 typedef Geometry< mydim, cdim, Grid > This;
88 typedef typename remove_const< Grid >::type::Traits Traits;
90 template<
int,
int,
class >
friend class Geometry;
93 typedef typename Traits::ctype ctype;
95 static const int mydimension = mydim;
96 static const int coorddimension = cdim;
97 static const int dimension = Traits::dimension;
98 static const int codimension = dimension - mydimension;
101 typedef CachedMultiLinearGeometry< ctype, mydimension, coorddimension, GeometryTraits< Grid > > BasicMapping;
104 :
public BasicMapping
106 template<
class CoordVector >
107 Mapping (
const GeometryType &type,
const CoordVector &coords )
108 : BasicMapping( type, coords ),
112 void addReference () { ++refCount_; }
113 bool removeReference () {
return (--refCount_ == 0); }
116 unsigned int refCount_;
120 typedef typename Mapping::LocalCoordinate LocalCoordinate;
121 typedef typename Mapping::GlobalCoordinate GlobalCoordinate;
123 typedef typename Mapping::JacobianTransposed JacobianTransposed;
124 typedef typename Mapping::JacobianInverseTransposed JacobianInverseTransposed;
126 Geometry (
const Grid &grid )
131 template<
class CoordVector >
132 Geometry (
const Grid &grid,
const GeometryType &type,
const CoordVector &coords )
135 assert(
int( type.dim() ) == mydimension );
136 void *mappingStorage = grid.allocateStorage(
sizeof( Mapping ) );
137 mapping_ =
new( mappingStorage ) Mapping( type, coords );
138 mapping_->addReference();
141 Geometry (
const This &other )
142 : grid_( other.grid_ ),
143 mapping_( other.mapping_ )
146 mapping_->addReference();
151 if( mapping_ && mapping_->removeReference() )
155 const This &operator= (
const This &other )
158 other.mapping_->addReference();
159 if( mapping_ && mapping_->removeReference() )
162 mapping_ = other.mapping_;
166 operator bool ()
const {
return bool( mapping_ ); }
168 bool affine ()
const {
return mapping_->affine(); }
171 int corners ()
const {
return mapping_->corners(); }
172 GlobalCoordinate corner (
const int i )
const {
return mapping_->corner( i ); }
173 GlobalCoordinate center ()
const {
return mapping_->center(); }
175 GlobalCoordinate global (
const LocalCoordinate &local )
const {
return mapping_->global( local ); }
176 LocalCoordinate local (
const GlobalCoordinate &global )
const {
return mapping_->local( global ); }
178 ctype integrationElement (
const LocalCoordinate &local )
const {
return mapping_->integrationElement( local ); }
179 ctype volume ()
const {
return mapping_->volume(); }
181 const JacobianTransposed &jacobianTransposed (
const LocalCoordinate &local )
const {
return mapping_->jacobianTransposed( local ); }
182 const JacobianInverseTransposed &jacobianInverseTransposed (
const LocalCoordinate &local )
const {
return mapping_->jacobianInverseTransposed( local ); }
184 const Grid &grid ()
const {
return *grid_; }
187 void destroyMapping ()
189 mapping_->~Mapping();
190 grid().deallocateStorage( mapping_,
sizeof( Mapping ) );
204 namespace FacadeOptions
207 template<
int mydim,
int cdim,
class Gr
id >
208 struct StoreGeometryReference< mydim, cdim, Grid, GeoGrid::Geometry >
210 static const bool v =
false;
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:14
Fallback implementation of the nullptr object in C++0x.
static const bool v
Whether to store by reference.
Definition: geometry.hh:49
Traits for type conversions and type information.