dune-grid  2.2.1
cornerstorage.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH
2 #define DUNE_GEOGRID_CORNERSTORAGE_HH
3 
5 
6 namespace Dune
7 {
8 
9  namespace GeoGrid
10  {
11 
12  // CoordVector
13  // -----------
14 
15  template< int mydim, class Grid, bool fake >
16  class CoordVector;
17 
18 
19  template< int mydim, class Grid >
20  class CoordVector< mydim, Grid, false >
21  {
22  typedef typename remove_const< Grid >::type::Traits Traits;
23 
24  typedef typename Traits::ctype ctype;
25 
26  static const int dimension = Traits::dimension;
27  static const int mydimension = mydim;
28  static const int codimension = dimension - mydimension;
29  static const int dimensionworld = Traits::dimensionworld;
30 
31  typedef FieldVector< ctype, dimensionworld > Coordinate;
32 
33  typedef typename Traits::HostGrid HostGrid;
34  typedef typename Traits::CoordFunction CoordFunction;
35 
36  typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
37 
40 
41  public:
42  CoordVector ( const HostEntity &hostEntity,
43  const CoordFunction &coordFunction )
44  : coordFunctionCaller_( hostEntity, coordFunction )
45  {}
46 
47  template< unsigned int numCorners >
48  void calculate ( Coordinate (&corners)[ numCorners ] ) const
49  {
50  assert( numCorners == coordFunctionCaller_.numCorners() );
51  for( unsigned int i = 0; i < numCorners; ++i )
52  coordFunctionCaller_.evaluate( i, corners[ i ] );
53  }
54 
55  private:
56  const CoordFunctionCaller coordFunctionCaller_;
57  };
58 
59 
60  template< int mydim, class Grid >
61  class CoordVector< mydim, Grid, true >
62  {
63  typedef typename remove_const< Grid > :: type :: Traits Traits;
64 
65  typedef typename Traits::ctype ctype;
66 
67  static const int dimension = Traits::dimension;
68  static const int mydimension = mydim;
69  static const int codimension = dimension - mydimension;
70  static const int dimensionworld = Traits::dimensionworld;
71 
72  typedef FieldVector< ctype, dimensionworld > Coordinate;
73 
74  typedef typename Traits::HostGrid HostGrid;
75  typedef typename Traits::CoordFunction CoordFunction;
76 
77  typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
78 
81 
82  public:
83  CoordVector ( const HostElement &hostElement,
84  const unsigned int subEntity,
85  const CoordFunction &coordFunction )
86  : coordFunctionCaller_( hostElement, coordFunction ),
87  subEntity_( subEntity )
88  {}
89 
90  template< unsigned int numCorners >
91  void calculate ( Coordinate (&corners)[ numCorners ] ) const
92  {
93  const GeometryType type = coordFunctionCaller_.type();
94  const GenericReferenceElement< ctype, dimension > &refElement
95  = GenericReferenceElements< ctype, dimension >::general( type );
96  assert( numCorners == refElement.size( subEntity_, codimension, dimension ) );
97 
98  for( unsigned int i = 0; i < numCorners; ++i )
99  {
100  const unsigned int j = refElement.subEntity( subEntity_, codimension, i, dimension );
101  coordFunctionCaller_.evaluate( j, corners[ i ] );
102  }
103  }
104 
105  private:
106  const CoordFunctionCaller coordFunctionCaller_;
107  const unsigned int subEntity_;
108  };
109 
110 
111 
112  // IntersectionCoordVector
113  // -----------------------
114 
115  template< class Grid >
117  {
118  typedef typename remove_const< Grid >::type::Traits Traits;
119 
120  typedef typename Traits::ctype ctype;
121 
122  static const int dimension = Traits::dimension;
123  static const int codimension = 1;
124  static const int mydimension = dimension-codimension;
125  static const int dimensionworld = Traits::dimensionworld;
126 
127  typedef FieldVector< ctype, dimensionworld > Coordinate;
128 
129  typedef typename Traits::HostGrid HostGrid;
130 
131  typedef typename Traits::template Codim< 0 >::GeometryImpl ElementGeometryImpl;
132  typedef typename Traits::template Codim< codimension >::LocalGeometry HostLocalGeometry;
133 
134  public:
135  IntersectionCoordVector ( const ElementGeometryImpl &elementGeometry,
136  const HostLocalGeometry &hostLocalGeometry )
137  : elementGeometry_( elementGeometry ),
138  hostLocalGeometry_( hostLocalGeometry )
139  {}
140 
141  template< unsigned int numCorners >
142  void calculate ( Coordinate (&corners)[ numCorners ] ) const
143  {
144  assert( numCorners == hostLocalGeometry_.corners() );
145  for( unsigned int i = 0; i < numCorners; ++i )
146  corners[ i ] = elementGeometry_.global( hostLocalGeometry_.corner( i ) );
147  }
148 
149  private:
150  const ElementGeometryImpl &elementGeometry_;
151  HostLocalGeometry hostLocalGeometry_;
152  };
153 
154 
155 
156 
157  // CornerStorage
158  // -------------
159 
160  template< class Topology, class Grid >
162  {
163  typedef typename remove_const< Grid >::type::Traits Traits;
164 
165  typedef typename Traits::ctype ctype;
166 
167  static const int dimension = Traits::dimension;
168  static const int mydimension = Topology::dimension;
169  static const int codimension = dimension - mydimension;
170  static const int dimensionworld = Traits::dimensionworld;
171 
172  typedef FieldVector< ctype, dimensionworld > Coordinate;
173 
174  public:
175  static const unsigned int size = Topology::numCorners;
176 
177  template< class SubTopology >
178  struct SubStorage
179  {
181  };
182 
183  template< bool fake >
184  explicit
186  {
187  coords.calculate( coords_ );
188  }
189 
191  {
192  coords.calculate( coords_ );
193  }
194 
195  template< class Mapping, unsigned int codim >
196  explicit
197  CornerStorage ( const GenericGeometry::SubMappingCoords< Mapping, codim > &coords )
198  {
199  for( unsigned int i = 0; i < size; ++i )
200  coords_[ i ] = coords[ i ];
201  }
202 
203  const Coordinate &operator[] ( unsigned int i ) const
204  {
205  return coords_[ i ];
206  }
207 
208  private:
209  Coordinate coords_[ size ];
210  };
211 
212  } // namespace GeoGrid
213 
214 } // namespace Dune
215 
216 #endif // #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH