dune-grid  2.6-git
cornerstorage.hh
Go to the documentation of this file.
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 
6 #include <array>
7 
9 
10 namespace 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 std::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 ( std::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 std::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 
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 ( std::array< Coordinate, size > (&corners) ) const
97  {
98  const GeometryType type = coordFunctionCaller_.type();
99  auto refElement = referenceElement< ctype, dimension >( type );
100  const std::size_t numCorners = refElement.size( subEntity_, codimension, dimension );
101  assert( size >= numCorners );
102  for( std::size_t i = 0; i < numCorners; ++i )
103  {
104  const std::size_t j = refElement.subEntity( subEntity_, codimension, i, dimension );
105  coordFunctionCaller_.evaluate( j, corners[ i ] );
106  }
107  }
108 
109  private:
110  const CoordFunctionCaller coordFunctionCaller_;
111  const unsigned int subEntity_;
112  };
113 
114 
115 
116  // IntersectionCoordVector
117  // -----------------------
118 
119  template< class Grid >
121  {
122  typedef typename std::remove_const< Grid >::type::Traits Traits;
123 
124  typedef typename Traits::ctype ctype;
125 
126  static const int dimension = Traits::dimension;
127  static const int codimension = 1;
128  static const int mydimension = dimension-codimension;
129  static const int dimensionworld = Traits::dimensionworld;
130 
131  typedef FieldVector< ctype, dimensionworld > Coordinate;
132 
133  typedef typename Traits::HostGrid HostGrid;
134 
135  typedef typename Traits::template Codim< 0 >::GeometryImpl ElementGeometryImpl;
136  typedef typename Traits::template Codim< codimension >::LocalGeometry HostLocalGeometry;
137 
138  public:
139  IntersectionCoordVector ( const ElementGeometryImpl &elementGeometry,
140  const HostLocalGeometry &hostLocalGeometry )
141  : elementGeometry_( elementGeometry ),
142  hostLocalGeometry_( hostLocalGeometry )
143  {}
144 
145  template< std::size_t size >
146  void calculate ( std::array< Coordinate, size > (&corners) ) const
147  {
148  const std::size_t numCorners = hostLocalGeometry_.corners();
149  assert( size >= numCorners );
150  for( std::size_t i = 0; i < numCorners; ++i )
151  corners[ i ] = elementGeometry_.global( hostLocalGeometry_.corner( i ) );
152  }
153 
154  template< unsigned int numCorners >
155  void calculate ( Coordinate (&corners)[ numCorners ] ) const
156  {
157  assert( numCorners == hostLocalGeometry_.corners() );
158  }
159 
160  private:
161  const ElementGeometryImpl &elementGeometry_;
162  HostLocalGeometry hostLocalGeometry_;
163  };
164 
165 
166 
167  // CornerStorage
168  // -------------
169 
170  template< int mydim, int cdim, class Grid >
172  {
173  typedef typename std::remove_const< Grid >::type::Traits Traits;
174 
175  typedef typename Traits::ctype ctype;
176  typedef FieldVector< ctype, cdim > Coordinate;
177 
178  typedef std::array< Coordinate, (1 << mydim) > Coords;
179 
180  public:
181  typedef typename Coords::const_iterator const_iterator;
182 
183  template< bool fake >
185  {
186  coords.calculate( coords_ );
187  }
188 
190  {
191  coords.calculate( coords_ );
192  }
193 
194  const Coordinate &operator[] ( unsigned int i ) const
195  {
196  return coords_[ i ];
197  }
198 
199  const_iterator begin () const { return coords_.begin(); }
200  const_iterator end () const { return coords_.end(); }
201 
202  private:
203  Coords coords_;
204  };
205 
206  } // namespace GeoGrid
207 
208 } // namespace Dune
209 
210 #endif // #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH
Include standard header files.
Definition: agrid.hh:58
CoordVector(const HostEntity &hostEntity, const CoordFunction &coordFunction)
Definition: cornerstorage.hh:46
const_iterator end() const
Definition: cornerstorage.hh:200
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:373
const_iterator begin() const
Definition: cornerstorage.hh:199
void calculate(std::array< Coordinate, size >(&corners)) const
Definition: cornerstorage.hh:146
void calculate(std::array< Coordinate, size >(&corners)) const
Definition: cornerstorage.hh:52
CornerStorage(const CoordVector< mydim, Grid, fake > &coords)
Definition: cornerstorage.hh:184
Definition: cornerstorage.hh:120
Definition: cornerstorage.hh:20
Definition: coordfunctioncaller.hh:19
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:178
IntersectionCoordVector(const ElementGeometryImpl &elementGeometry, const HostLocalGeometry &hostLocalGeometry)
Definition: cornerstorage.hh:139
void calculate(std::array< Coordinate, size >(&corners)) const
Definition: cornerstorage.hh:96
Definition: cornerstorage.hh:171
void calculate(Coordinate(&corners)[numCorners]) const
Definition: cornerstorage.hh:155
Coords::const_iterator const_iterator
Definition: cornerstorage.hh:181
CoordVector(const HostElement &hostElement, const unsigned int subEntity, const CoordFunction &coordFunction)
Definition: cornerstorage.hh:88
CornerStorage(const IntersectionCoordVector< Grid > &coords)
Definition: cornerstorage.hh:189