Dune Core Modules (2.9.0)

geometry.hh
1#ifndef DUNE_SPGRID_GEOMETRY_HH
2#define DUNE_SPGRID_GEOMETRY_HH
3
4#include <type_traits>
5
7
9#include <dune/common/transpose.hh>
10
11#include <dune/geometry/type.hh>
12#include <dune/geometry/referenceelements.hh>
13
14#include <dune/grid/spgrid/referencecube.hh>
15#include <dune/grid/spgrid/entityinfo.hh>
16
17namespace Dune
18{
19
20 // SPBasicGeometry
21 // ---------------
22
23 template< int mydim, int cdim, class Grid, class Impl >
24 class SPBasicGeometry
25 {
26 typedef SPBasicGeometry< mydim, cdim, Grid, Impl > This;
27
28 protected:
29 typedef typename std::remove_const< Grid >::type::Traits Traits;
30
31 public:
32 typedef typename Traits::ReferenceCube::ctype ctype;
33
34 static const int mydimension = mydim;
35 static const int coorddimension = cdim;
36 static const int dimension = Traits::ReferenceCube::dimension;
37 static const int codimension = dimension - mydimension;
38
39 typedef SPReferenceCube< ctype, mydimension > ReferenceCube;
40 typedef SPGeometryCache< ctype, dimension, codimension > GeometryCache;
41
42 static const int numCorners = (1 << mydimension);
43
44 typedef typename GeometryCache::GlobalVector GlobalVector;
45 typedef typename GeometryCache::LocalVector LocalVector;
46
47 // just to make the Dune interface happy
48 typedef GlobalVector GlobalCoordinate;
49 typedef LocalVector LocalCoordinate;
50
51 typedef typename GeometryCache::JacobianTransposed JacobianTransposed;
52 typedef typename GeometryCache::JacobianInverseTransposed JacobianInverseTransposed;
53
54 using Jacobian = std::decay_t<decltype(transposedView(std::declval<const JacobianTransposed&>()))>;
55 using JacobianInverse = std::decay_t<decltype(transposedView(std::declval<const JacobianInverseTransposed&>()))>;
56
57 protected:
58 SPBasicGeometry ()
59 {}
60
61 public:
62 GeometryType type () const { return GeometryTypes::cube( mydimension ); }
63
64 int corners () const { return numCorners; }
65 GlobalVector corner ( const int i ) const { return global( ReferenceCube::corner( i ) ); }
66 GlobalVector center () const { return global( ReferenceCube::center() ); }
67
68 bool affine () const { return true; }
69
70 GlobalVector global ( const LocalVector &local ) const;
71 LocalVector local ( const GlobalVector &global ) const;
72
73 ctype volume () const { return asImpl().geometryCache().volume(); }
74 ctype integrationElement ( const LocalVector &local ) const { return volume(); }
75
76 const JacobianTransposed &jacobianTransposed ( const LocalVector &local ) const;
77 const JacobianInverseTransposed &jacobianInverseTransposed ( const LocalVector &local ) const;
78
79 auto jacobian ( const LocalVector &local ) const;
80 auto jacobianInverse ( const LocalVector &local ) const;
81
82 protected:
83 const Impl &asImpl () const { return static_cast< const Impl & >( *this ); }
84 };
85
86
87
88 // SPGeometry
89 // ----------
90
91 template< int mydim, int cdim, class Grid >
92 class SPGeometry
93 : public SPBasicGeometry< mydim, cdim, Grid, SPGeometry< mydim, cdim, Grid > >
94 {
95 typedef SPGeometry< mydim, cdim, Grid > This;
96 typedef SPBasicGeometry< mydim, cdim, Grid, This > Base;
97
98 protected:
99 typedef typename Base::Traits Traits;
100
101 public:
102 typedef typename Base::ctype ctype;
103
104 static const int mydimension = Base::mydimension;
105 static const int dimension = Base::dimension;
106 static const int codimension = Base::codimension;
107
108 typedef __SPGrid::EntityInfo< Grid, codimension > EntityInfo;
109 typedef typename EntityInfo::GridLevel GridLevel;
110
111 typedef typename Base::ReferenceCube ReferenceCube;
112 typedef typename Base::GeometryCache GeometryCache;
113
114 typedef typename Base::GlobalVector GlobalVector;
115 typedef typename Base::LocalVector LocalVector;
116
117 private:
118 typedef typename EntityInfo::MultiIndex MultiIndex;
119
120 public:
121 explicit SPGeometry ( const GridLevel &gridLevel )
122 : entityInfo_( gridLevel )
123 {}
124
125 explicit SPGeometry ( const EntityInfo &entityInfo )
126 : entityInfo_( entityInfo ),
127 origin_( computeOrigin() )
128 {}
129
130 SPGeometry ( const GridLevel &gridLevel, const MultiIndex &id )
131 : entityInfo_( gridLevel, id ),
132 origin_( computeOrigin() )
133 {}
134
135 using Base::jacobianTransposed;
136 using Base::jacobianInverseTransposed;
137
138 using Base::jacobian;
139 using Base::jacobianInverse;
140
141 GlobalVector origin () const { return origin_; }
142 const GeometryCache &geometryCache () const { return entityInfo().geometryCache(); }
143
144 const GridLevel &gridLevel () const { return entityInfo().gridLevel(); }
145
146 const EntityInfo &entityInfo () const { return entityInfo_; }
147 EntityInfo &entityInfo () { return entityInfo_; }
148
149 private:
150 GlobalVector computeOrigin () const
151 {
152 const GlobalVector &h = gridLevel().h();
153 GlobalVector origin = gridLevel().domain().cube().origin();
154 for( int i = 0; i < dimension; ++i )
155 origin[ i ] += (entityInfo().id()[ i ] / 2) * h[ i ];
156 return origin;
157 }
158
159 EntityInfo entityInfo_;
160 GlobalVector origin_;
161 };
162
163
164
165 // SPLocalGeometry
166 // ---------------
167
168 template< int mydim, int cdim, class Grid >
169 class SPLocalGeometry
170 : public SPBasicGeometry< mydim, cdim, Grid, SPLocalGeometry< mydim, cdim, Grid > >
171 {
172 typedef SPLocalGeometry< mydim, cdim, Grid > This;
173 typedef SPBasicGeometry< mydim, cdim, Grid, This > Base;
174
175 protected:
176 typedef typename Base::Traits Traits;
177
178 public:
179 typedef typename Base::ctype ctype;
180
181 static const int mydimension = Base::mydimension;
182 static const int dimension = Base::dimension;
183 static const int codimension = Base::codimension;
184
185 typedef typename Base::ReferenceCube ReferenceCube;
186 typedef typename Base::GeometryCache GeometryCache;
187
188 typedef typename Base::GlobalVector GlobalVector;
189 typedef typename Base::LocalVector LocalVector;
190
191 public:
192 SPLocalGeometry ( const GeometryCache &geometryCache,
193 const GlobalVector &origin )
194 : geometryCache_( geometryCache ),
195 origin_( origin )
196 {}
197
198 using Base::jacobianTransposed;
199 using Base::jacobianInverseTransposed;
200
201 using Base::jacobian;
202 using Base::jacobianInverse;
203
204 GlobalVector origin () const { return origin_; }
205 const GeometryCache &geometryCache () const { return geometryCache_; }
206
207 private:
208 GeometryCache geometryCache_;
209 GlobalVector origin_;
210 };
211
212
213
214 // Implementation of SPBasicGeometry
215 // ---------------------------------
216
217 template< int mydim, int cdim, class Grid, class Impl >
218 inline typename SPBasicGeometry< mydim, cdim, Grid, Impl >::GlobalVector
219 SPBasicGeometry< mydim, cdim, Grid, Impl >::global ( const LocalVector &local ) const
220 {
221 GlobalVector y( asImpl().origin() );
222 asImpl().geometryCache().jacobianTransposed().umtv( local, y );
223 return y;
224 }
225
226
227 template< int mydim, int cdim, class Grid, class Impl >
228 inline typename SPBasicGeometry< mydim, cdim, Grid, Impl >::LocalVector
229 SPBasicGeometry< mydim, cdim, Grid, Impl >::local ( const GlobalVector &global ) const
230 {
231 LocalVector x;
232 GlobalVector y = global - asImpl().origin();
233 asImpl().geometryCache().jacobianInverseTransposed().mtv( y, x );
234 return x;
235 }
236
237
238 template< int mydim, int cdim, class Grid, class Impl >
239 inline const typename SPBasicGeometry< mydim, cdim, Grid, Impl >::JacobianTransposed &
240 SPBasicGeometry< mydim, cdim, Grid, Impl >::jacobianTransposed ( const LocalVector &local ) const
241 {
242 return asImpl().geometryCache().jacobianTransposed();
243 }
244
245
246 template< int mydim, int cdim, class Grid, class Impl >
247 inline const typename SPBasicGeometry< mydim, cdim, Grid, Impl >::JacobianInverseTransposed &
248 SPBasicGeometry< mydim, cdim, Grid, Impl >::jacobianInverseTransposed ( const LocalVector &local ) const
249 {
250 return asImpl().geometryCache().jacobianInverseTransposed();
251 }
252
253 template< int mydim, int cdim, class Grid, class Impl >
254 inline auto SPBasicGeometry< mydim, cdim, Grid, Impl >::jacobian ( const LocalVector &local ) const
255 {
256 // Handing out a transposedView is OK, because jacobianTransposed
257 // returns a reference to a cached value.
258 return transposedView(jacobianTransposed(local));
259 }
260
261
262 template< int mydim, int cdim, class Grid, class Impl >
263 inline auto SPBasicGeometry< mydim, cdim, Grid, Impl >::jacobianInverse ( const LocalVector &local ) const
264 {
265 // Handing out a transposedView is OK, because jacobianInverseTransposed
266 // returns a reference to a cached value.
267 return transposedView(jacobianInverseTransposed(local));
268 }
269
270} // namespace Dune
271
272#endif // #ifndef DUNE_SPGRID_GEOMETRY_HH
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:472
Dune namespace.
Definition: alignedallocator.hh:13
auto transposedView(const Matrix &matrix)
Create a view modelling the transposed matrix.
Definition: transpose.hh:261
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 (Jul 15, 22:36, 2024)