Dune Core Modules (2.9.0)

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