dune-grid  2.11
albertagrid/geometry.hh
Go to the documentation of this file.
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_ALBERTA_GEOMETRY_HH
6 #define DUNE_ALBERTA_GEOMETRY_HH
7 
11 
12 #if HAVE_ALBERTA
13 
14 namespace Dune
15 {
16 
17  // Forward Declarations
18  // --------------------
19 
20  template< int dim, int dimworld >
21  class AlbertaGrid;
22 
23 
24 
25  // AlbertaGridCoordinateReader
26  // ---------------------------
27 
28  template< int codim, class GridImp >
30  {
31  typedef typename std::remove_const< GridImp >::type Grid;
32 
33  static constexpr int dimension = Grid::dimension;
34  static constexpr int codimension = codim;
35  static constexpr int mydimension = dimension - codimension;
36  static constexpr int coorddimension = Grid::dimensionworld;
37 
39 
41  typedef FieldVector< ctype, coorddimension > Coordinate;
42 
43  AlbertaGridCoordinateReader ( const GridImp &grid,
44  const ElementInfo &elementInfo,
45  int subEntity )
46  : grid_( grid ),
47  elementInfo_( elementInfo ),
48  subEntity_( subEntity )
49  {}
50 
51  const ElementInfo &elementInfo () const
52  {
53  return elementInfo_;
54  }
55 
56  void coordinate ( int i, Coordinate &x ) const
57  {
58  assert( !elementInfo_ == false );
59  assert( (i >= 0) && (i <= mydimension) );
60 
61  const int k = mapVertices( subEntity_, i );
62  const Alberta::GlobalVector &coord = grid_.getCoord( elementInfo_, k );
63  for( int j = 0; j < coorddimension; ++j )
64  x[ j ] = coord[ j ];
65  }
66 
67  bool hasDeterminant () const
68  {
69  return false;
70  }
71 
72  ctype determinant () const
73  {
74  assert( hasDeterminant() );
75  return ctype( 0 );
76  }
77 
78  private:
79  static int mapVertices ( int subEntity, int i )
80  {
82  }
83 
84  const Grid &grid_;
85  const ElementInfo &elementInfo_;
86  const int subEntity_;
87  };
88 
89 
90 
91  // AlbertaGridGeometry
92  // -------------------
93 
106  template< int mydim, int cdim, class GridImp >
108  {
110 
111  // remember type of the grid
112  typedef GridImp Grid;
113 
114  // dimension of barycentric coordinates
115  static constexpr int dimbary = mydim + 1;
116 
117  public:
120 
121  static constexpr int dimension = Grid :: dimension;
122  static constexpr int mydimension = mydim;
123  static constexpr int codimension = dimension - mydimension;
124  static constexpr int coorddimension = cdim;
125 
126  typedef FieldVector< ctype, mydimension > LocalCoordinate;
127  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
128 
129  typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
130  typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
131 
132  typedef FieldMatrix< ctype, coorddimension, mydimension > Jacobian;
133  typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianInverse;
134 
135  private:
136  static constexpr int numCorners = mydimension + 1;
137 
138  typedef FieldMatrix< ctype, numCorners, coorddimension > CoordMatrix;
139 
140  public:
142  {
143  invalidate();
144  }
145 
146  template< class CoordReader >
147  AlbertaGridGeometry ( const CoordReader &coordReader )
148  {
149  build( coordReader );
150  }
151 
154  {
155  return GeometryTypes::simplex( mydimension );
156  }
157 
159  bool affine () const { return true; }
160 
162  int corners () const
163  {
164  return numCorners;
165  }
166 
168  GlobalCoordinate corner ( const int i ) const
169  {
170  assert( (i >= 0) && (i < corners()) );
171  return coord_[ i ];
172  }
173 
176  {
177  return centroid_;
178  }
179 
181  GlobalCoordinate global ( const LocalCoordinate &local ) const;
182 
184  LocalCoordinate local ( const GlobalCoordinate &global ) const;
185 
192  {
193  assert( calcedDet_ );
194  return elDet_;
195  }
196 
198  ctype integrationElement ( [[maybe_unused]] const LocalCoordinate &local ) const
199  {
200  return integrationElement();
201  }
202 
204  ctype volume () const
205  {
206  return integrationElement() / ctype( factorial(mydimension) );
207  }
208 
214  const JacobianTransposed &jacobianTransposed () const;
215 
217  const JacobianTransposed &
218  jacobianTransposed ( [[maybe_unused]] const LocalCoordinate &local ) const
219  {
220  return jacobianTransposed();
221  }
222 
229 
232  jacobianInverseTransposed ( [[maybe_unused]] const LocalCoordinate &local ) const
233  {
234  return jacobianInverseTransposed();
235  }
236 
239  {
240  return jacobianTransposed(local).transposed();
241  }
242 
245  {
246  return jacobianInverseTransposed(local).transposed();
247  }
248 
249  //***********************************************************************
250  // Methods that not belong to the Interface, but have to be public
251  //***********************************************************************
252 
254  void invalidate ()
255  {
256  builtJT_ = false;
257  builtJTInv_ = false;
258  calcedDet_ = false;
259  }
260 
262  template< class CoordReader >
263  void build ( const CoordReader &coordReader );
264 
265  void print ( std::ostream &out ) const;
266 
267  private:
268  // calculates the volume of the element
269  ctype elDeterminant () const
270  {
272  }
273 
275  CoordMatrix coord_;
276 
278  GlobalCoordinate centroid_;
279 
280  // storage for the transposed of the jacobian
281  mutable JacobianTransposed jT_;
282 
283  // storage for the transposed inverse of the jacboian
284  mutable JacobianInverseTransposed jTInv_;
285 
286  // has jT_ been computed, yet?
287  mutable bool builtJT_;
288  // has jTInv_ been computed, yet?
289  mutable bool builtJTInv_;
290 
291  mutable bool calcedDet_;
292  mutable ctype elDet_;
293  };
294 
295 
296 
297  // AlbertaGridGlobalGeometry
298  // -------------------------
299 
300  template< int mydim, int cdim, class GridImp >
302  : public AlbertaGridGeometry< mydim, cdim, GridImp >
303  {
306 
307  public:
309  : Base()
310  {}
311 
312  template< class CoordReader >
313  AlbertaGridGlobalGeometry ( const CoordReader &coordReader )
314  : Base( coordReader )
315  {}
316  };
317 
318 
319 #if !DUNE_ALBERTA_CACHE_COORDINATES
320  template< int dim, int cdim >
321  class AlbertaGridGlobalGeometry< dim, cdim, const AlbertaGrid< dim, cdim > >
322  {
324 
325  // remember type of the grid
327 
328  // dimension of barycentric coordinates
329  static constexpr int dimbary = dim + 1;
330 
332 
333  public:
336 
337  static constexpr int dimension = Grid::dimension;
338  static constexpr int mydimension = dimension;
339  static constexpr int codimension = dimension - mydimension;
340  static constexpr int coorddimension = cdim;
341 
342  typedef FieldVector< ctype, mydimension > LocalCoordinate;
343  typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
344 
345  typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed;
346  typedef FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed;
347 
348  typedef FieldMatrix< ctype, coorddimension, mydimension > Jacobian;
349  typedef FieldMatrix< ctype, mydimension, coorddimension > JacobianInverse;
350 
351  private:
352  static constexpr int numCorners = mydimension + 1;
353 
354  typedef FieldMatrix< ctype, numCorners, coorddimension > CoordMatrix;
355 
356  public:
358  {
359  invalidate();
360  }
361 
362  template< class CoordReader >
363  AlbertaGridGlobalGeometry ( const CoordReader &coordReader )
364  {
365  build( coordReader );
366  }
367 
370  {
371  return GeometryTypes::simplex( mydimension );
372  }
373 
375  int corners () const
376  {
377  return numCorners;
378  }
379 
381  GlobalCoordinate corner ( const int i ) const
382  {
383  assert( (i >= 0) && (i < corners()) );
384  const Alberta::GlobalCoordinate &x = elementInfo_.coordinate( i );
386  for( int j = 0; j < coorddimension; ++j )
387  y[ j ] = x[ j ];
388  return y;
389  }
390 
393  {
394  GlobalCoordinate centroid_ = corner( 0 );
395  for( int i = 1; i < numCorners; ++i )
396  centroid_ += corner( i );
397  centroid_ *= ctype( 1 ) / ctype( numCorners );
398  return centroid_;
399  }
400 
402  GlobalCoordinate global ( const LocalCoordinate &local ) const;
403 
405  LocalCoordinate local ( const GlobalCoordinate &global ) const;
406 
413  {
414  return elementInfo_.geometryCache().integrationElement();
415  }
416 
419  {
420  return integrationElement();
421  }
422 
424  ctype volume () const
425  {
426  return integrationElement() / ctype( factorial(mydimension) );
427  }
428 
435  {
436  return elementInfo_.geometryCache().jacobianTransposed();
437  }
438 
440  const JacobianTransposed &
442  {
443  return jacobianTransposed();
444  }
445 
452  {
453  return elementInfo_.geometryCache().jacobianInverseTransposed();
454  }
455 
459  {
460  return jacobianInverseTransposed();
461  }
462 
465  {
466  return jacobianTransposed(local).transposed();
467  }
468 
471  {
472  return jacobianInverseTransposed(local).transposed();
473  }
474 
475  //***********************************************************************
476  // Methods that not belong to the Interface, but have to be public
477  //***********************************************************************
478 
480  void invalidate ()
481  {
482  elementInfo_ = ElementInfo();
483  }
484 
486  template< class CoordReader >
487  void build ( const CoordReader &coordReader )
488  {
489  elementInfo_ = coordReader.elementInfo();
490  }
491 
492  private:
493  ElementInfo elementInfo_;
494  };
495 #endif // #if !DUNE_ALBERTA_CACHE_COORDINATES
496 
497 
498 
499  // AlbertaGridLocalGeometryProvider
500  // --------------------------------
501 
502  template< class Grid >
504  {
506 
507  public:
508  typedef typename Grid::ctype ctype;
509 
510  static constexpr int dimension = Grid::dimension;
511 
512  template< int codim >
513  struct Codim
514  {
516  };
517 
520 
521  static constexpr int numChildren = 2;
522  static constexpr int numFaces = dimension + 1;
523 
524  static constexpr int minFaceTwist = Alberta::Twist< dimension, dimension-1 >::minTwist;
525  static constexpr int maxFaceTwist = Alberta::Twist< dimension, dimension-1 >::maxTwist;
526  static constexpr int numFaceTwists = maxFaceTwist - minFaceTwist + 1;
527 
528  private:
529  struct GeoInFatherCoordReader;
530  struct FaceCoordReader;
531 
533  {
534  buildGeometryInFather();
535  buildFaceGeometry();
536  }
537 
539  {
540  for( int child = 0; child < numChildren; ++child )
541  {
542  delete geometryInFather_[ child ][ 0 ];
543  delete geometryInFather_[ child ][ 1 ];
544  }
545 
546  for( int i = 0; i < numFaces; ++i )
547  {
548  for( int j = 0; j < numFaceTwists; ++j )
549  delete faceGeometry_[ i ][ j ];
550  }
551  }
552 
553  void buildGeometryInFather();
554  void buildFaceGeometry();
555 
556  public:
557  const LocalElementGeometry &
558  geometryInFather ( int child, const int orientation = 1 ) const
559  {
560  assert( (child >= 0) && (child < numChildren) );
561  assert( (orientation == 1) || (orientation == -1) );
562  return *geometryInFather_[ child ][ (orientation + 1) / 2 ];
563  }
564 
565  const LocalFaceGeometry &
566  faceGeometry ( int face, int twist = 0 ) const
567  {
568  assert( (face >= 0) && (face < numFaces) );
569  assert( (twist >= minFaceTwist) && (twist <= maxFaceTwist) );
570  return *faceGeometry_[ face ][ twist - minFaceTwist ];
571  }
572 
573  static const This &instance ()
574  {
575  static This theInstance;
576  return theInstance;
577  }
578 
579  private:
580  template< int codim >
581  static int mapVertices ( int subEntity, int i )
582  {
584  }
585 
586  const LocalElementGeometry *geometryInFather_[ numChildren ][ 2 ];
587  const LocalFaceGeometry *faceGeometry_[ numFaces ][ numFaceTwists ];
588  };
589 
590 } // namespace Dune
591 
592 #endif // #if HAVE_ALBERTA
593 
594 #endif // #ifndef DUNE_ALBERTA_GEOMETRY_HH
int corners() const
number of corner the geometry
Definition: albertagrid/geometry.hh:162
void abs(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:328
const JacobianInverseTransposed & jacobianInverseTransposed([[maybe_unused]] const LocalCoordinate &local) const
transposed inverse of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:232
void print(std::ostream &out) const
Definition: geometry.cc:20
ctype integrationElement(const LocalCoordinate &local) const
integration element of the geometry mapping
Definition: albertagrid/geometry.hh:418
static constexpr int dimensionworld
The dimension of the world the grid lives in.
Definition: common/grid.hh:390
ctype integrationElement([[maybe_unused]] const LocalCoordinate &local) const
integration element of the geometry mapping
Definition: albertagrid/geometry.hh:198
Definition: albertagrid/geometry.hh:503
void build(const CoordReader &coordReader)
build the geometry from a coordinate reader
Definition: geometry.cc:90
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
inverse of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:244
static constexpr int numChildren
Definition: albertagrid/geometry.hh:521
geometry implementation for AlbertaGrid
Definition: albertagrid/geometry.hh:107
Jacobian jacobian(const LocalCoordinate &local) const
geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:238
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
inverse of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:470
AlbertaGridGlobalGeometry()
Definition: albertagrid/geometry.hh:308
Alberta::Real ctype
Definition: albertagrid/geometry.hh:38
void invalidate()
invalidate the geometry
Definition: albertagrid/geometry.hh:254
static constexpr int maxFaceTwist
Definition: albertagrid/geometry.hh:525
GeometryType type() const
obtain the type of reference element
Definition: albertagrid/geometry.hh:369
provides a wrapper for ALBERTA&#39;s el_info structure
int corners() const
number of corner the geometry
Definition: albertagrid/geometry.hh:375
const LocalElementGeometry & geometryInFather(int child, const int orientation=1) const
Definition: albertagrid/geometry.hh:558
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:375
AlbertaGridGeometry(const CoordReader &coordReader)
Definition: albertagrid/geometry.hh:147
void build(const CoordReader &coordReader)
build the geometry from a coordinate reader
Definition: albertagrid/geometry.hh:487
ctype determinant() const
Definition: albertagrid/geometry.hh:72
static const This & instance()
Definition: albertagrid/geometry.hh:573
Alberta::Real ctype
type of coordinates
Definition: albertagrid/geometry.hh:335
GlobalCoordinate corner(const int i) const
obtain the i-th corner of this geometry
Definition: albertagrid/geometry.hh:168
ctype integrationElement() const
integration element of the geometry mapping
Definition: albertagrid/geometry.hh:412
FieldVector< ctype, coorddimension > GlobalCoordinate
Definition: albertagrid/geometry.hh:127
static constexpr int dimension
Definition: albertagrid/geometry.hh:33
GlobalCoordinate corner(const int i) const
obtain the i-th corner of this geometry
Definition: albertagrid/geometry.hh:381
ALBERTA REAL_D GlobalVector
Definition: misc.hh:50
FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed
Definition: albertagrid/geometry.hh:130
ctype volume() const
volume of geometry
Definition: albertagrid/geometry.hh:204
AlbertaGridGeometry< dimension-codim, dimension, Grid > LocalGeometry
Definition: albertagrid/geometry.hh:515
static constexpr int codimension
Definition: albertagrid/geometry.hh:123
static constexpr int mydimension
Definition: albertagrid/geometry.hh:35
static constexpr int numFaceTwists
Definition: albertagrid/geometry.hh:526
static constexpr int coorddimension
Definition: albertagrid/geometry.hh:124
const JacobianTransposed & jacobianTransposed([[maybe_unused]] const LocalCoordinate &local) const
transposed of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:218
std::remove_const< GridImp >::type Grid
Definition: albertagrid/geometry.hh:31
static constexpr int numFaces
Definition: albertagrid/geometry.hh:522
ALBERTA REAL Real
Definition: misc.hh:48
AlbertaGridCoordinateReader(const GridImp &grid, const ElementInfo &elementInfo, int subEntity)
Definition: albertagrid/geometry.hh:43
static constexpr int coorddimension
Definition: albertagrid/geometry.hh:36
GlobalCoordinate center() const
return center of geometry
Definition: albertagrid/geometry.hh:392
Jacobian jacobian(const LocalCoordinate &local) const
geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:464
FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed
Definition: albertagrid/geometry.hh:345
static constexpr int dimension
Definition: albertagrid/geometry.hh:510
ctype volume() const
volume of geometry
Definition: albertagrid/geometry.hh:424
const ElementInfo & elementInfo() const
Definition: albertagrid/geometry.hh:51
static constexpr int minFaceTwist
Definition: albertagrid/geometry.hh:524
FieldVector< ctype, coorddimension > Coordinate
Definition: albertagrid/geometry.hh:41
Codim< 1 >::LocalGeometry LocalFaceGeometry
Definition: albertagrid/geometry.hh:519
LocalCoordinate local(const GlobalCoordinate &global) const
map a point from the geometry to the reference element
Definition: geometry.cc:45
const JacobianInverseTransposed & jacobianInverseTransposed() const
transposed inverse of the geometry mapping&#39;s Jacobian
Definition: geometry.cc:73
const JacobianTransposed & jacobianTransposed() const
transposed of the geometry mapping&#39;s Jacobian
Definition: geometry.cc:55
Include standard header files.
Definition: agrid.hh:59
const JacobianTransposed & jacobianTransposed() const
transposed of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:434
Grid::ctype ctype
Definition: albertagrid/geometry.hh:508
static constexpr int codimension
Definition: albertagrid/geometry.hh:34
FieldVector< ctype, mydimension > LocalCoordinate
Definition: albertagrid/geometry.hh:342
bool affine() const
returns always true since we only have simplices
Definition: albertagrid/geometry.hh:159
Definition: misc.hh:531
FieldMatrix< ctype, mydimension, coorddimension > JacobianTransposed
Definition: albertagrid/geometry.hh:129
static constexpr int dimension
Definition: albertagrid/geometry.hh:121
GeometryType type() const
obtain the type of reference element
Definition: albertagrid/geometry.hh:153
AlbertaGridGeometry()
Definition: albertagrid/geometry.hh:141
const JacobianInverseTransposed & jacobianInverseTransposed(const LocalCoordinate &local) const
transposed inverse of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:458
FieldMatrix< ctype, mydimension, coorddimension > JacobianInverse
Definition: albertagrid/geometry.hh:133
Definition: misc.hh:443
Codim< 0 >::LocalGeometry LocalElementGeometry
Definition: albertagrid/geometry.hh:518
FieldMatrix< ctype, coorddimension, mydimension > JacobianInverseTransposed
Definition: albertagrid/geometry.hh:346
GlobalCoordinate global(const LocalCoordinate &local) const
map a point from the reference element to the geometry
Definition: geometry.cc:34
const JacobianTransposed & jacobianTransposed(const LocalCoordinate &local) const
transposed of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:441
bool hasDeterminant() const
Definition: albertagrid/geometry.hh:67
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/geometry.hh:40
static constexpr int dimension
The dimension of the grid.
Definition: common/grid.hh:387
const JacobianInverseTransposed & jacobianInverseTransposed() const
transposed inverse of the geometry mapping&#39;s Jacobian
Definition: albertagrid/geometry.hh:451
void coordinate(int i, Coordinate &x) const
Definition: albertagrid/geometry.hh:56
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:518
void invalidate()
invalidate the geometry
Definition: albertagrid/geometry.hh:480
ctype integrationElement() const
integration element of the geometry mapping
Definition: albertagrid/geometry.hh:191
Definition: albertagrid/geometry.hh:29
[ provides Dune::Grid ]
Definition: agrid.hh:106
Wrapper and interface classes for element geometries.
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:132
const LocalFaceGeometry & faceGeometry(int face, int twist=0) const
Definition: albertagrid/geometry.hh:566
FieldVector< ctype, coorddimension > GlobalCoordinate
Definition: albertagrid/geometry.hh:343
FieldMatrix< ctype, coorddimension, mydimension > Jacobian
Definition: albertagrid/geometry.hh:348
Alberta::Real ctype
type of coordinates
Definition: albertagrid/geometry.hh:119
static K determinant([[maybe_unused]] const FieldMatrix< K, 0, m > &matrix)
Definition: algebra.hh:30
GlobalCoordinate center() const
return center of geometry
Definition: albertagrid/geometry.hh:175
AlbertaGridGlobalGeometry(const CoordReader &coordReader)
Definition: albertagrid/geometry.hh:363
FieldMatrix< ctype, mydimension, coorddimension > JacobianInverse
Definition: albertagrid/geometry.hh:349
Definition: albertagrid/geometry.hh:513
FieldMatrix< ctype, coorddimension, mydimension > Jacobian
Definition: albertagrid/geometry.hh:132
static constexpr int mydimension
Definition: albertagrid/geometry.hh:122
Definition: albertagrid/geometry.hh:301
AlbertaGridGlobalGeometry(const CoordReader &coordReader)
Definition: albertagrid/geometry.hh:313
FieldVector< ctype, mydimension > LocalCoordinate
Definition: albertagrid/geometry.hh:126