DUNE PDELab (2.8)

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_ALBERTA_GEOMETRY_HH
4#define DUNE_ALBERTA_GEOMETRY_HH
5
7#include <dune/grid/albertagrid/misc.hh>
9
10#if HAVE_ALBERTA
11
12namespace Dune
13{
14
15 // Forward Declarations
16 // --------------------
17
18 template< int dim, int dimworld >
19 class AlbertaGrid;
20
21
22
23 // AlbertaGridCoordinateReader
24 // ---------------------------
25
26 template< int codim, class GridImp >
27 struct AlbertaGridCoordinateReader
28 {
29 typedef typename std::remove_const< GridImp >::type Grid;
30
31 static const int dimension = Grid::dimension;
32 static const int codimension = codim;
33 static const int mydimension = dimension - codimension;
34 static const int coorddimension = Grid::dimensionworld;
35
36 typedef Alberta::Real ctype;
37
38 typedef Alberta::ElementInfo< dimension > ElementInfo;
39 typedef FieldVector< ctype, coorddimension > Coordinate;
40
41 AlbertaGridCoordinateReader ( const GridImp &grid,
42 const ElementInfo &elementInfo,
43 int subEntity )
44 : grid_( grid ),
45 elementInfo_( elementInfo ),
46 subEntity_( subEntity )
47 {}
48
49 const ElementInfo &elementInfo () const
50 {
51 return elementInfo_;
52 }
53
54 void coordinate ( int i, Coordinate &x ) const
55 {
56 assert( !elementInfo_ == false );
57 assert( (i >= 0) && (i <= mydimension) );
58
59 const int k = mapVertices( subEntity_, i );
60 const Alberta::GlobalVector &coord = grid_.getCoord( elementInfo_, k );
61 for( int j = 0; j < coorddimension; ++j )
62 x[ j ] = coord[ j ];
63 }
64
65 bool hasDeterminant () const
66 {
67 return false;
68 }
69
70 ctype determinant () const
71 {
72 assert( hasDeterminant() );
73 return ctype( 0 );
74 }
75
76 private:
77 static int mapVertices ( int subEntity, int i )
78 {
79 return Alberta::MapVertices< dimension, codimension >::apply( subEntity, i );
80 }
81
82 const Grid &grid_;
83 const ElementInfo &elementInfo_;
84 const int subEntity_;
85 };
86
87
88
89 // AlbertaGridGeometry
90 // -------------------
91
104 template< int mydim, int cdim, class GridImp >
106 {
108
109 // remember type of the grid
110 typedef GridImp Grid;
111
112 // dimension of barycentric coordinates
113 static const int dimbary = mydim + 1;
114
115 public:
117 typedef Alberta::Real ctype;
118
119 static const int dimension = Grid :: dimension;
120 static const int mydimension = mydim;
121 static const int codimension = dimension - mydimension;
122 static const int coorddimension = cdim;
123
126
129
130 private:
131 static const int numCorners = mydimension + 1;
132
134
135 public:
137 {
138 invalidate();
139 }
140
141 template< class CoordReader >
142 AlbertaGridGeometry ( const CoordReader &coordReader )
143 {
144 build( coordReader );
145 }
146
149 {
150 return GeometryTypes::simplex( mydimension );
151 }
152
154 bool affine () const { return true; }
155
157 int corners () const
158 {
159 return numCorners;
160 }
161
163 GlobalCoordinate corner ( const int i ) const
164 {
165 assert( (i >= 0) && (i < corners()) );
166 return coord_[ i ];
167 }
168
171 {
172 return centroid_;
173 }
174
176 GlobalCoordinate global ( const LocalCoordinate &local ) const;
177
180
187 {
188 assert( calcedDet_ );
189 return elDet_;
190 }
191
193 ctype integrationElement ( [[maybe_unused]] const LocalCoordinate &local ) const
194 {
195 return integrationElement();
196 }
197
199 ctype volume () const
200 {
202 }
203
209 const JacobianTransposed &jacobianTransposed () const;
210
212 const JacobianTransposed &
213 jacobianTransposed ( [[maybe_unused]] const LocalCoordinate &local ) const
214 {
215 return jacobianTransposed();
216 }
217
223 const JacobianInverseTransposed &jacobianInverseTransposed () const;
224
226 const JacobianInverseTransposed &
227 jacobianInverseTransposed ( [[maybe_unused]] const LocalCoordinate &local ) const
228 {
230 }
231
232 //***********************************************************************
233 // Methods that not belong to the Interface, but have to be public
234 //***********************************************************************
235
238 {
239 builtJT_ = false;
240 builtJTInv_ = false;
241 calcedDet_ = false;
242 }
243
245 template< class CoordReader >
246 void build ( const CoordReader &coordReader );
247
248 void print ( std::ostream &out ) const;
249
250 private:
251 // calculates the volume of the element
252 ctype elDeterminant () const
253 {
254 return std::abs( Alberta::determinant( jacobianTransposed() ) );
255 }
256
258 CoordMatrix coord_;
259
261 GlobalCoordinate centroid_;
262
263 // storage for the transposed of the jacobian
264 mutable JacobianTransposed jT_;
265
266 // storage for the transposed inverse of the jacboian
267 mutable JacobianInverseTransposed jTInv_;
268
269 // has jT_ been computed, yet?
270 mutable bool builtJT_;
271 // has jTInv_ been computed, yet?
272 mutable bool builtJTInv_;
273
274 mutable bool calcedDet_;
275 mutable ctype elDet_;
276 };
277
278
279
280 // AlbertaGridGlobalGeometry
281 // -------------------------
282
283 template< int mydim, int cdim, class GridImp >
284 class AlbertaGridGlobalGeometry
285 : public AlbertaGridGeometry< mydim, cdim, GridImp >
286 {
287 typedef AlbertaGridGlobalGeometry< mydim, cdim, GridImp > This;
288 typedef AlbertaGridGeometry< mydim, cdim, GridImp > Base;
289
290 public:
291 AlbertaGridGlobalGeometry ()
292 : Base()
293 {}
294
295 template< class CoordReader >
296 AlbertaGridGlobalGeometry ( const CoordReader &coordReader )
297 : Base( coordReader )
298 {}
299 };
300
301
302#if !DUNE_ALBERTA_CACHE_COORDINATES
303 template< int dim, int cdim >
304 class AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > >
305 {
306 typedef AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > > This;
307
308 // remember type of the grid
309 typedef AlbertaGrid< dim, cdim > Grid;
310
311 // dimension of barycentric coordinates
312 static const int dimbary = dim + 1;
313
314 typedef Alberta::ElementInfo< dim > ElementInfo;
315
316 public:
318 typedef Alberta::Real ctype;
319
320 static const int dimension = Grid::dimension;
321 static const int mydimension = dimension;
322 static const int codimension = dimension - mydimension;
323 static const int coorddimension = cdim;
324
325 typedef FieldVector< ctype, mydimension > LocalCoordinate;
326 typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
327
328 typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
329 typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
330
331 private:
332 static const int numCorners = mydimension + 1;
333
335
336 public:
337 AlbertaGridGlobalGeometry ()
338 {
339 invalidate();
340 }
341
342 template< class CoordReader >
343 AlbertaGridGlobalGeometry ( const CoordReader &coordReader )
344 {
345 build( coordReader );
346 }
347
349 GeometryType type () const
350 {
351 return GeometryTypes::simplex( mydimension );
352 }
353
355 int corners () const
356 {
357 return numCorners;
358 }
359
361 GlobalCoordinate corner ( const int i ) const
362 {
363 assert( (i >= 0) && (i < corners()) );
364 const Alberta::GlobalCoordinate &x = elementInfo_.coordinate( i );
365 GlobalCoordinate y;
366 for( int j = 0; j < coorddimension; ++j )
367 y[ j ] = x[ j ];
368 return y;
369 }
370
372 GlobalCoordinate center () const
373 {
374 GlobalCoordinate centroid_ = corner( 0 );
375 for( int i = 1; i < numCorners; ++i )
376 centroid_ += corner( i );
377 centroid_ *= ctype( 1 ) / ctype( numCorners );
378 return centroid_;
379 }
380
382 GlobalCoordinate global ( const LocalCoordinate &local ) const;
383
385 LocalCoordinate local ( const GlobalCoordinate &global ) const;
386
392 ctype integrationElement () const
393 {
394 return elementInfo_.geometryCache().integrationElement();
395 }
396
398 ctype integrationElement ( const LocalCoordinate &local ) const
399 {
400 return integrationElement();
401 }
402
404 ctype volume () const
405 {
406 return integrationElement() / ctype( Factorial< mydimension >::factorial );
407 }
408
414 const JacobianTransposed &jacobianTransposed () const
415 {
416 return elementInfo_.geometryCache().jacobianTransposed();
417 }
418
420 const JacobianTransposed &
421 jacobianTransposed ( const LocalCoordinate &local ) const
422 {
423 return jacobianTransposed();
424 }
425
431 const JacobianInverseTransposed &jacobianInverseTransposed () const
432 {
433 return elementInfo_.geometryCache().jacobianInverseTransposed();
434 }
435
437 const JacobianInverseTransposed &
438 jacobianInverseTransposed ( const LocalCoordinate &local ) const
439 {
441 }
442
443 //***********************************************************************
444 // Methods that not belong to the Interface, but have to be public
445 //***********************************************************************
446
448 void invalidate ()
449 {
450 elementInfo_ = ElementInfo();
451 }
452
454 template< class CoordReader >
455 void build ( const CoordReader &coordReader )
456 {
457 elementInfo_ = coordReader.elementInfo();
458 }
459
460 private:
461 ElementInfo elementInfo_;
462 };
463#endif // #if !DUNE_ALBERTA_CACHE_COORDINATES
464
465
466
467 // AlbertaGridLocalGeometryProvider
468 // --------------------------------
469
470 template< class Grid >
471 class AlbertaGridLocalGeometryProvider
472 {
473 typedef AlbertaGridLocalGeometryProvider< Grid > This;
474
475 public:
476 typedef typename Grid::ctype ctype;
477
478 static const int dimension = Grid::dimension;
479
480 template< int codim >
481 struct Codim
482 {
483 typedef AlbertaGridGeometry< dimension-codim, dimension, Grid > LocalGeometry;
484 };
485
486 typedef typename Codim< 0 >::LocalGeometry LocalElementGeometry;
487 typedef typename Codim< 1 >::LocalGeometry LocalFaceGeometry;
488
489 static const int numChildren = 2;
490 static const int numFaces = dimension + 1;
491
492 static const int minFaceTwist = Alberta::Twist< dimension, dimension-1 >::minTwist;
493 static const int maxFaceTwist = Alberta::Twist< dimension, dimension-1 >::maxTwist;
494 static const int numFaceTwists = maxFaceTwist - minFaceTwist + 1;
495
496 private:
497 struct GeoInFatherCoordReader;
498 struct FaceCoordReader;
499
500 AlbertaGridLocalGeometryProvider ()
501 {
502 buildGeometryInFather();
503 buildFaceGeometry();
504 }
505
506 ~AlbertaGridLocalGeometryProvider ()
507 {
508 for( int child = 0; child < numChildren; ++child )
509 {
510 delete geometryInFather_[ child ][ 0 ];
511 delete geometryInFather_[ child ][ 1 ];
512 }
513
514 for( int i = 0; i < numFaces; ++i )
515 {
516 for( int j = 0; j < numFaceTwists; ++j )
517 delete faceGeometry_[ i ][ j ];
518 }
519 }
520
521 void buildGeometryInFather();
522 void buildFaceGeometry();
523
524 public:
525 const LocalElementGeometry &
526 geometryInFather ( int child, const int orientation = 1 ) const
527 {
528 assert( (child >= 0) && (child < numChildren) );
529 assert( (orientation == 1) || (orientation == -1) );
530 return *geometryInFather_[ child ][ (orientation + 1) / 2 ];
531 }
532
533 const LocalFaceGeometry &
534 faceGeometry ( int face, int twist = 0 ) const
535 {
536 assert( (face >= 0) && (face < numFaces) );
537 assert( (twist >= minFaceTwist) && (twist <= maxFaceTwist) );
538 return *faceGeometry_[ face ][ twist - minFaceTwist ];
539 }
540
541 static const This &instance ()
542 {
543 static This theInstance;
544 return theInstance;
545 }
546
547 private:
548 template< int codim >
549 static int mapVertices ( int subEntity, int i )
550 {
551 return Alberta::MapVertices< dimension, codim >::apply( subEntity, i );
552 }
553
554 const LocalElementGeometry *geometryInFather_[ numChildren ][ 2 ];
555 const LocalFaceGeometry *faceGeometry_[ numFaces ][ numFaceTwists ];
556 };
557
558} // namespace Dune
559
560#endif // #if HAVE_ALBERTA
561
562#endif // #ifndef DUNE_ALBERTA_GEOMETRY_HH
geometry implementation for AlbertaGrid
Definition: geometry.hh:106
GeometryType type() const
obtain the type of reference element
Definition: geometry.hh:148
GlobalCoordinate center() const
return center of geometry
Definition: geometry.hh:170
const JacobianTransposed & jacobianTransposed(const LocalCoordinate &local) const
transposed of the geometry mapping's Jacobian
Definition: geometry.hh:213
const JacobianTransposed & jacobianTransposed() const
transposed of the geometry mapping's Jacobian
Definition: geometry.cc:53
int corners() const
number of corner the geometry
Definition: geometry.hh:157
const JacobianInverseTransposed & jacobianInverseTransposed() const
transposed inverse of the geometry mapping's Jacobian
Definition: geometry.cc:71
GlobalCoordinate corner(const int i) const
obtain the i-th corner of this geometry
Definition: geometry.hh:163
ctype integrationElement() const
integration element of the geometry mapping
Definition: geometry.hh:186
ctype integrationElement(const LocalCoordinate &local) const
integration element of the geometry mapping
Definition: geometry.hh:193
GlobalCoordinate global(const LocalCoordinate &local) const
map a point from the refence element to the geometry
Definition: geometry.cc:32
Alberta::Real ctype
type of coordinates
Definition: geometry.hh:117
ctype volume() const
volume of geometry
Definition: geometry.hh:199
const JacobianInverseTransposed & jacobianInverseTransposed(const LocalCoordinate &local) const
transposed inverse of the geometry mapping's Jacobian
Definition: geometry.hh:227
void invalidate()
invalidate the geometry
Definition: geometry.hh:237
bool affine() const
returns always true since we only have simplices
Definition: geometry.hh:154
void build(const CoordReader &coordReader)
build the geometry from a coordinate reader
Definition: geometry.cc:88
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
@ dimensionworld
The dimension of the world the grid lives in.
Definition: grid.hh:392
@ dimension
The dimension of the grid.
Definition: grid.hh:386
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:521
Wrapper and interface classes for element geometries.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
provides a wrapper for ALBERTA's el_info structure
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:461
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:126
Dune namespace.
Definition: alignedallocator.hh:11
Calculates the factorial of m at compile time.
Definition: math.hh:91
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)