DUNE PDELab (git)

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