Dune Core Modules (2.4.1)

cornerstorage.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_GEOGRID_CORNERSTORAGE_HH
4#define DUNE_GEOGRID_CORNERSTORAGE_HH
5
7
8#include <dune/grid/geometrygrid/coordfunctioncaller.hh>
9
10namespace Dune
11{
12
13 namespace GeoGrid
14 {
15
16 // CoordVector
17 // -----------
18
19 template< int mydim, class Grid, bool fake >
20 class CoordVector;
21
22
23 template< int mydim, class Grid >
24 class CoordVector< mydim, Grid, false >
25 {
26 typedef typename remove_const< Grid >::type::Traits Traits;
27
28 typedef typename Traits::ctype ctype;
29
30 static const int dimension = Traits::dimension;
31 static const int mydimension = mydim;
32 static const int codimension = dimension - mydimension;
33 static const int dimensionworld = Traits::dimensionworld;
34
35 typedef FieldVector< ctype, dimensionworld > Coordinate;
36
37 typedef typename Traits::HostGrid HostGrid;
38 typedef typename Traits::CoordFunction CoordFunction;
39
40 typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
41
42 typedef GeoGrid :: CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
43 CoordFunctionCaller;
44
45 public:
46 CoordVector ( const HostEntity &hostEntity,
47 const CoordFunction &coordFunction )
48 : coordFunctionCaller_( hostEntity, coordFunction )
49 {}
50
51 template< std::size_t size >
52 void calculate ( array< Coordinate, size > (&corners) ) const
53 {
54 const std::size_t numCorners = coordFunctionCaller_.size();
55 assert( size >= numCorners );
56 for( std::size_t i = 0; i < numCorners; ++i )
57 coordFunctionCaller_.evaluate( i, corners[ i ] );
58 }
59
60 private:
61 const CoordFunctionCaller coordFunctionCaller_;
62 };
63
64
65 template< int mydim, class Grid >
66 class CoordVector< mydim, Grid, true >
67 {
68 typedef typename remove_const< Grid > :: type :: Traits Traits;
69
70 typedef typename Traits::ctype ctype;
71
72 static const int dimension = Traits::dimension;
73 static const int mydimension = mydim;
74 static const int codimension = dimension - mydimension;
75 static const int dimensionworld = Traits::dimensionworld;
76
77 typedef FieldVector< ctype, dimensionworld > Coordinate;
78
79 typedef typename Traits::HostGrid HostGrid;
80 typedef typename Traits::CoordFunction CoordFunction;
81
82 typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
83
84 typedef GeoGrid::CoordFunctionCaller< HostElement, typename CoordFunction::Interface >
85 CoordFunctionCaller;
86
87 public:
88 CoordVector ( const HostElement &hostElement,
89 const unsigned int subEntity,
90 const CoordFunction &coordFunction )
91 : coordFunctionCaller_( hostElement, coordFunction ),
92 subEntity_( subEntity )
93 {}
94
95 template< std::size_t size >
96 void calculate ( array< Coordinate, size > (&corners) ) const
97 {
98 const GeometryType type = coordFunctionCaller_.type();
99 const ReferenceElement< ctype, dimension > &refElement
101 const std::size_t numCorners = refElement.size( subEntity_, codimension, dimension );
102 assert( size >= numCorners );
103 for( std::size_t i = 0; i < numCorners; ++i )
104 {
105 const std::size_t j = refElement.subEntity( subEntity_, codimension, i, dimension );
106 coordFunctionCaller_.evaluate( j, corners[ i ] );
107 }
108 }
109
110 private:
111 const CoordFunctionCaller coordFunctionCaller_;
112 const unsigned int subEntity_;
113 };
114
115
116
117 // IntersectionCoordVector
118 // -----------------------
119
120 template< class Grid >
121 class IntersectionCoordVector
122 {
123 typedef typename remove_const< Grid >::type::Traits Traits;
124
125 typedef typename Traits::ctype ctype;
126
127 static const int dimension = Traits::dimension;
128 static const int codimension = 1;
129 static const int mydimension = dimension-codimension;
130 static const int dimensionworld = Traits::dimensionworld;
131
132 typedef FieldVector< ctype, dimensionworld > Coordinate;
133
134 typedef typename Traits::HostGrid HostGrid;
135
136 typedef typename Traits::template Codim< 0 >::GeometryImpl ElementGeometryImpl;
137 typedef typename Traits::template Codim< codimension >::LocalGeometry HostLocalGeometry;
138
139 public:
140 IntersectionCoordVector ( const ElementGeometryImpl &elementGeometry,
141 const HostLocalGeometry &hostLocalGeometry )
142 : elementGeometry_( elementGeometry ),
143 hostLocalGeometry_( hostLocalGeometry )
144 {}
145
146 template< std::size_t size >
147 void calculate ( array< Coordinate, size > (&corners) ) const
148 {
149 const std::size_t numCorners = hostLocalGeometry_.corners();
150 assert( size >= numCorners );
151 for( std::size_t i = 0; i < numCorners; ++i )
152 corners[ i ] = elementGeometry_.global( hostLocalGeometry_.corner( i ) );
153 }
154
155 template< unsigned int numCorners >
156 void calculate ( Coordinate (&corners)[ numCorners ] ) const
157 {
158 assert( numCorners == hostLocalGeometry_.corners() );
159 }
160
161 private:
162 const ElementGeometryImpl &elementGeometry_;
163 HostLocalGeometry hostLocalGeometry_;
164 };
165
166
167
168 // CornerStorage
169 // -------------
170
171 template< int mydim, int cdim, class Grid >
172 class CornerStorage
173 {
174 typedef typename remove_const< Grid >::type::Traits Traits;
175
176 typedef typename Traits::ctype ctype;
177 typedef FieldVector< ctype, cdim > Coordinate;
178
179 typedef array< Coordinate, (1 << mydim) > Coords;
180
181 public:
182 typedef typename Coords::const_iterator const_iterator;
183
184 template< bool fake >
185 explicit CornerStorage ( const CoordVector< mydim, Grid, fake > &coords )
186 {
187 coords.calculate( coords_ );
188 }
189
190 explicit CornerStorage ( const IntersectionCoordVector< Grid > &coords )
191 {
192 coords.calculate( coords_ );
193 }
194
195 const Coordinate &operator[] ( unsigned int i ) const
196 {
197 return coords_[ i ];
198 }
199
200 const_iterator begin () const { return coords_.begin(); }
201 const_iterator end () const { return coords_.end(); }
202
203 private:
204 Coords coords_;
205 };
206
207 } // namespace GeoGrid
208
209} // namespace Dune
210
211#endif // #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH
Fallback implementation of the std::array class (a static array)
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Dune namespace.
Definition: alignment.hh:10
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:484
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)