Dune Core Modules (2.9.0)

geometricgridlevel.hh
1#ifndef DUNE_SPGRID_GEOMETRICGRIDLEVEL_HH
2#define DUNE_SPGRID_GEOMETRICGRIDLEVEL_HH
3
4#include <array>
5#include <cassert>
6
7#include <dune/common/hybridutilities.hh>
8
9#include <dune/geometry/dimension.hh>
10
11#include <dune/grid/spgrid/direction.hh>
12#include <dune/grid/spgrid/geometrycache.hh>
13#include <dune/grid/spgrid/normal.hh>
14#include <dune/grid/spgrid/referencecube.hh>
15
16namespace Dune
17{
18
19 // SPGeometricGridLevel
20 // --------------------
21
22 template< class ct, int dim >
23 class SPGeometricGridLevel
24 {
25 typedef SPGeometricGridLevel< ct, dim > This;
26
27 public:
28 typedef SPReferenceCubeContainer< ct, dim > ReferenceCubeContainer;
29
30 typedef typename ReferenceCubeContainer::ReferenceCube ReferenceCube;
31
32 typedef typename ReferenceCube::ctype ctype;
33 static const int dimension = ReferenceCube::dimension;
34
35 typedef typename ReferenceCube::GlobalVector GlobalVector;
36
37 static const unsigned int numDirections = ReferenceCube::numCorners;
38
39 typedef SPDirection< dimension > Direction;
40
41 template< int codim >
42 struct Codim
43 {
44 typedef typename ReferenceCubeContainer::template Codim< codim >::ReferenceCube ReferenceCube;
45 typedef SPGeometryCache< ctype, dimension, codim > GeometryCache;
46 };
47
48 SPGeometricGridLevel ( const ReferenceCubeContainer &refCubes, const GlobalVector &h );
49 SPGeometricGridLevel ( const This &other );
50
51 ~SPGeometricGridLevel ();
52
53 const ReferenceCube &referenceCube () const { return refCubes_.get(); }
54
55 template< int codim >
56 const typename Codim< codim >::ReferenceCube &
57 referenceCube () const { return refCubes_.template get< codim >(); }
58
59 const GlobalVector &h () const { return h_; }
60
61 template< int codim >
62 const typename Codim< codim >::GeometryCache &
63 geometryCache ( Direction dir, Dune::Codim< codim > = Dune::Codim< codim >() ) const
64 {
65 assert( dir.mydimension() == dimension - codim );
66 return *static_cast< const typename Codim< codim >::GeometryCache * >( geometryCache_[ dir.bits() ] );
67 }
68
69 const typename Codim< 0 >::GeometryCache &geometryCache ( Dune::Codim< 0 > ) const
70 {
71 SPDirectionIterator< dimension, 0 > dirIt;
72 return geometryCache< 0 >( *dirIt );
73 }
74
75 ctype faceVolume ( int i ) const { assert( (i >= 0) && (i < ReferenceCube::numFaces) ); return faceVolume_[ i ]; }
76
77 private:
78 void buildGeometry ();
79
80 const ReferenceCubeContainer &refCubes_;
81
82 GlobalVector h_;
83 std::array< void *, numDirections > geometryCache_;
84 std::array< ctype, ReferenceCube::numFaces > faceVolume_;
85 };
86
87
88
89 // Implementation of SPGeometricGridLevel
90 // --------------------------------------
91
92 template< class ct, int dim >
93 inline SPGeometricGridLevel< ct, dim >
94 ::SPGeometricGridLevel ( const ReferenceCubeContainer &refCubes, const GlobalVector &h )
95 : refCubes_( refCubes ),
96 h_( h )
97 {
98 buildGeometry();
99 }
100
101
102 template< class ct, int dim >
103 inline SPGeometricGridLevel< ct, dim >::SPGeometricGridLevel ( const This &other )
104 : refCubes_( other.refCubes_ ),
105 h_( other.h_ )
106 {
107 buildGeometry();
108 }
109
110
111 template< class ct, int dim >
112 inline SPGeometricGridLevel< ct, dim >::~SPGeometricGridLevel ()
113 {
114 Hybrid::forEach( std::make_integer_sequence< int, dimension+1 >(), [ this ] ( auto codim ) {
115 for( SPDirectionIterator< dimension, codim > dirIt; dirIt; ++dirIt )
116 {
117 delete static_cast< typename Codim< codim >::GeometryCache * >( geometryCache_[ (*dirIt).bits() ] );
118 geometryCache_[ (*dirIt).bits() ] = nullptr;
119 }
120 } );
121 }
122
123
124 template< class ct, int dim >
125 inline void SPGeometricGridLevel< ct, dim >::buildGeometry ()
126 {
127 Hybrid::forEach( std::make_integer_sequence< int, dimension+1 >(), [ this ] ( auto codim ) {
128 typedef typename Codim< codim >::GeometryCache GeometryCache;
129 for( SPDirectionIterator< dimension, codim > dirIt; dirIt; ++dirIt )
130 geometryCache_[ (*dirIt).bits() ] = new GeometryCache( h_, *dirIt );
131 } );
132
133 const ctype volume = geometryCache( Dune::Codim< 0 >() ).volume();
134 for( int face = 0; face < ReferenceCube::numFaces; ++face )
135 {
136 SPNormalId< dimension > normalId( face );
137 SPNormalVector< ctype, dimension > normal( normalId );
138 faceVolume_[ face ] = std::abs( volume / (normal * h_) );
139 }
140 }
141
142} // namespace Dune
143
144#endif // #ifndef DUNE_SPGRID_GEOMETRICGRIDLEVEL_HH
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:268
Dune namespace.
Definition: alignedallocator.hh:13
Static tag representing a codimension.
Definition: dimension.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)