Dune Core Modules (2.5.0)

geometry.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_GEOGRID_GEOMETRY_HH
4#define DUNE_GEOGRID_GEOMETRY_HH
5
6#include <utility>
7
9
10#include <dune/geometry/multilineargeometry.hh>
11#include <dune/geometry/referenceelements.hh>
12#include <dune/geometry/type.hh>
13
15#include <dune/grid/geometrygrid/cornerstorage.hh>
16
17namespace Dune
18{
19
20 namespace GeoGrid
21 {
22
23 // InferHasSingleGeometryType
24 // --------------------------
25
26 template< class hasSingleGeometryType, int dim, int mydim >
27 struct InferHasSingleGeometryType
28 {
29 private:
30 static const unsigned int id = hasSingleGeometryType::topologyId;
31 static const unsigned int idMask = (1u << mydim) - 1u;
32
33 public:
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);
36 };
37
38 template< class hasSingleGeometryType, int dim >
39 struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 1 >
40 {
41 static const bool v = true;
42 static const unsigned int topologyId = Impl::CubeTopology< 1 >::type::id;
43 };
44
45 template< class hasSingleGeometryType, int dim >
46 struct InferHasSingleGeometryType< hasSingleGeometryType, dim, 0 >
47 {
48 static const bool v = true;
49 static const unsigned int topologyId = Impl::CubeTopology< 0 >::type::id;
50 };
51
52
53
54 // GeometryTraits
55 // --------------
56
57 template< class Grid >
58 struct GeometryTraits
59 {
60 typedef typename std::remove_const< Grid >::type::Traits Traits;
61
62 typedef typename Traits::ctype ctype;
63
64 typedef Impl::FieldMatrixHelper< ctype > MatrixHelper;
65
66 static ctype tolerance () { return 16 * std::numeric_limits< ctype >::epsilon(); }
67
68 template< int mydim, int cdim >
69 struct CornerStorage
70 {
71 typedef GeoGrid::CornerStorage< mydim, cdim, Grid > Type;
72 };
73
74 template< int mydim >
75 struct hasSingleGeometryType
76 : public InferHasSingleGeometryType< Capabilities::hasSingleGeometryType< Grid >, Traits::dimension, mydim >
77 {};
78 };
79
80
81
82 // Geometry
83 // --------
84
85 template< int mydim, int cdim, class Grid >
86 class Geometry
87 {
88 typedef Geometry< mydim, cdim, Grid > This;
89
90 typedef typename std::remove_const< Grid >::type::Traits Traits;
91
92 template< int, int, class > friend class Geometry;
93
94 public:
95 typedef typename Traits::ctype ctype;
96
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;
101
102 protected:
103 typedef CachedMultiLinearGeometry< ctype, mydimension, coorddimension, GeometryTraits< Grid > > BasicMapping;
104
105 struct Mapping
106 : public BasicMapping
107 {
108 template< class CoordVector >
109 Mapping ( const GeometryType &type, const CoordVector &coords )
110 : BasicMapping( type, coords ),
111 refCount_( 0 )
112 {}
113
114 void addReference () { ++refCount_; }
115 bool removeReference () { return (--refCount_ == 0); }
116
117 private:
118 unsigned int refCount_;
119 };
120
121 public:
122 typedef typename Mapping::LocalCoordinate LocalCoordinate;
123 typedef typename Mapping::GlobalCoordinate GlobalCoordinate;
124
125 typedef typename Mapping::JacobianTransposed JacobianTransposed;
126 typedef typename Mapping::JacobianInverseTransposed JacobianInverseTransposed;
127
128 Geometry () : grid_( nullptr ), mapping_( nullptr ) {}
129
130 explicit Geometry ( const Grid &grid ) : grid_( &grid ), mapping_( nullptr ) {}
131
132 template< class CoordVector >
133 Geometry ( const Grid &grid, const GeometryType &type, const CoordVector &coords )
134 : grid_( &grid )
135 {
136 assert( int( type.dim() ) == mydimension );
137 void *mappingStorage = grid.allocateStorage( sizeof( Mapping ) );
138 mapping_ = new( mappingStorage ) Mapping( type, coords );
139 mapping_->addReference();
140 }
141
142 Geometry ( const This &other )
143 : grid_( other.grid_ ),
144 mapping_( other.mapping_ )
145 {
146 if( mapping_ )
147 mapping_->addReference();
148 }
149
150 Geometry ( This&& other )
151 : grid_( other.grid_ ),
152 mapping_( other.mapping_ )
153 {
154 other.grid_ = nullptr;
155 other.mapping_ = nullptr;
156 }
157
158 ~Geometry ()
159 {
160 if( mapping_ && mapping_->removeReference() )
161 destroyMapping();
162 }
163
164 const This &operator= ( const This &other )
165 {
166 if( other.mapping_ )
167 other.mapping_->addReference();
168 if( mapping_ && mapping_->removeReference() )
169 destroyMapping();
170 grid_ = other.grid_;
171 mapping_ = other.mapping_;
172 return *this;
173 }
174
175 const This &operator= ( This&& other )
176 {
177 using std::swap;
178 swap( grid_, other.grid_ );
179 swap( mapping_, other.mapping_ );
180 return *this;
181 }
182
183 operator bool () const { return bool( mapping_ ); }
184
185 bool affine () const { return mapping_->affine(); }
186 GeometryType type () const { return mapping_->type(); }
187
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(); }
191
192 GlobalCoordinate global ( const LocalCoordinate &local ) const { return mapping_->global( local ); }
193 LocalCoordinate local ( const GlobalCoordinate &global ) const { return mapping_->local( global ); }
194
195 ctype integrationElement ( const LocalCoordinate &local ) const { return mapping_->integrationElement( local ); }
196 ctype volume () const { return mapping_->volume(); }
197
198 JacobianTransposed jacobianTransposed ( const LocalCoordinate &local ) const { return mapping_->jacobianTransposed( local ); }
199 JacobianInverseTransposed jacobianInverseTransposed ( const LocalCoordinate &local ) const { return mapping_->jacobianInverseTransposed( local ); }
200
201 const Grid &grid () const { assert( grid_ ); return *grid_; }
202
203 private:
204 void destroyMapping ()
205 {
206 mapping_->~Mapping();
207 grid().deallocateStorage( mapping_, sizeof( Mapping ) );
208 }
209
210 const Grid *grid_;
211 Mapping* mapping_;
212 };
213
214 } // namespace GeoGrid
215
216} // namespace Dune
217
218#endif // #ifndef DUNE_GEOGRID_GEOMETRY_HH
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:11
A unique label for each type of element that can occur in a grid.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)