dune-fem  2.4.1-rc
cornerstorage.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_GEOGRIDPART_CORNERSTORAGE_HH
2 #define DUNE_FEM_GRIDPART_GEOGRIDPART_CORNERSTORAGE_HH
3 
4 #include <array>
5 #include <type_traits>
6 
7 #include <dune/grid/geometrygrid/hostcorners.hh>
8 #include <dune/grid/geometrygrid/coordfunction.hh>
9 
10 
11 namespace Dune
12 {
13 
14  namespace Fem
15  {
16 
17  // External Forward Declarations
18  // -----------------------------
19 
20  class IsDiscreteFunction;
21 
22  template< class, class, int, template< class > class >
24 
25 
26 
27  // GeoDiscreteCoordFunctionCaller
28  // ------------------------------
29 
30  template< int codim, class CoordFunction, class DFSpace = typename CoordFunction::DiscreteFunctionSpaceType >
32 
33  template< int codim, class CoordFunction, class FunctionSpace, class GridPart, template< class > class Storage >
34  class GeoDiscreteCoordFunctionCaller< codim, CoordFunction, LagrangeDiscreteFunctionSpace< FunctionSpace, GridPart, 1, Storage > >
35  {
37  static_assert( (Conversion< DFSpace, typename CoordFunction::DiscreteFunctionSpaceType >::sameType), "Invalid use of template argument DFSpace." );
38 
39  public:
40  typedef CoordFunction CoordFunctionType;
41 
42  typedef typename CoordFunctionType::GridPartType::template Codim< codim >::EntityType HostEntityType;
43  typedef typename CoordFunctionType::RangeType RangeType;
44 
45  static const int dimRange = CoordFunctionType::FunctionSpaceType::dimRange;
46  static const int dimension = HostEntityType::dimension;
47  static const int mydimension = HostEntityType::mydimension;
48 
49  GeoDiscreteCoordFunctionCaller ( const CoordFunction &coordFunction,
50  const HostEntityType &hostEntity )
51  : coordFunction_( coordFunction ),
52  hostEntity_( hostEntity )
53  {}
54 
55  void evaluate ( unsigned int i, RangeType &y ) const
56  {
57  const int index = coordFunction_.gridPart().indexSet().subIndex( hostEntity_, i, dimension );
58  assert( (index >= 0) && (index < (int)(coordFunction_.space().blockMapper().size())) );
59 
60  typedef typename CoordFunctionType::ConstDofBlockPtrType ConstDofBlockPtrType;
61  ConstDofBlockPtrType block = coordFunction_.block( index );
62 
63  for( int k = 0; k < dimRange; ++k )
64  y[ k ] = (*block)[ k ];
65  }
66 
67  GeometryType type () const
68  {
69  return hostEntity_.type();
70  }
71 
72  std::size_t numCorners () const
73  {
74  return ReferenceElements< typename CoordFunctionType::GridPartType::GridType::ctype, mydimension >::general( type() ).size( mydimension );
75  }
76 
77  private:
78  const CoordFunctionType &coordFunction_;
79  const HostEntityType &hostEntity_;
80  };
81 
82 
83 
84  // GeoCoordFunctionCaller
85  // ----------------------
86 
87  template< int codim, class CoordFunction, bool discrete = Conversion< CoordFunction, IsDiscreteFunction >::exists >
89 
90  template< int codim, class CoordFunction >
91  class GeoCoordFunctionCaller< codim, CoordFunction, false >
92  {
93  public:
94  typedef CoordFunction CoordFunctionType;
95 
96  typedef typename CoordFunctionType::GridPartType::template Codim< codim >::EntityType HostEntityType;
97  typedef typename CoordFunctionType::RangeType RangeType;
98 
99  GeoCoordFunctionCaller ( const CoordFunction &coordFunction,
100  const HostEntityType &hostEntity )
101  : coordFunction_( coordFunction ),
102  hostCorners_( hostEntity )
103  {}
104 
105  void evaluate ( unsigned int i, RangeType &y ) const
106  {
107  coordFunction_.evaluate( hostCorners_[ i ], y );
108  }
109 
110  GeometryType type () const
111  {
112  return hostCorners_.type();
113  }
114 
115  std::size_t numCorners () const
116  {
117  return hostCorners_.size();
118  }
119 
120  private:
121  const CoordFunction &coordFunction_;
122  GeoGrid::HostCorners< HostEntityType > hostCorners_;
123  };
124 
125  template< int codim, class CoordFunction >
126  class GeoCoordFunctionCaller< codim, CoordFunction, true >
127  : public GeoDiscreteCoordFunctionCaller< codim, CoordFunction >
128  {
130 
131  public:
132  typedef typename BaseType::CoordFunctionType CoordFunctionType;
133  typedef typename BaseType::HostEntityType HostEntityType;
134 
135  GeoCoordFunctionCaller ( const CoordFunctionType &coordFunction,
136  const HostEntityType &hostEntity )
137  : BaseType( coordFunction, hostEntity )
138  {}
139  };
140 
141 
142 
143  // GeoCoordVector
144  // --------------
145 
146  template< int mydim, class GridFamily >
148  {
149  typedef typename std::remove_const< GridFamily >::type::Traits Traits;
150 
151  typedef typename std::remove_const< GridFamily >::type::ctype ctype;
152 
153  static const int dimension = std::remove_const< GridFamily >::type::dimension;
154  static const int mydimension = mydim;
155  static const int codimension = dimension - mydimension;
156  static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
157 
158  typedef FieldVector< ctype, dimensionworld > Coordinate;
159 
160  typedef typename Traits::HostGridPartType HostGridPartType;
161  typedef typename Traits::CoordFunctionType CoordFunctionType;
162 
163  typedef typename HostGridPartType::template Codim< codimension >::EntityType HostEntityType;
164 
166 
167  public:
168  GeoCoordVector ( const CoordFunctionType &coordFunction,
169  const HostEntityType &hostEntity )
170  : coordFunctionCaller_( coordFunction, hostEntity )
171  {}
172 
173  template< std::size_t size >
174  void calculate ( std::array< Coordinate, size > &corners ) const
175  {
176  const std::size_t numCorners = coordFunctionCaller_.numCorners();
177  for( std::size_t i = 0; i < numCorners; ++i )
178  coordFunctionCaller_.evaluate( i, corners[ i ] );
179  }
180 
181  private:
182  const CoordFunctionCallerType coordFunctionCaller_;
183  };
184 
185 
186 
187  // GeoLocalCoordVector
188  // -------------------
189 
190  template< int mydim, class GridFamily, class LocalFunction >
192  {
193  typedef typename std::remove_const< GridFamily >::type::Traits Traits;
194 
195  typedef typename std::remove_const< GridFamily >::type::ctype ctype;
196 
197  static const int dimension = std::remove_const< GridFamily >::type::dimension;
198  static const int mydimension = mydim;
199  static const int codimension = dimension - mydimension;
200  static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
201 
202  typedef FieldVector< ctype, dimensionworld > Coordinate;
203 
204  public:
206 
207  explicit GeoLocalCoordVector ( const LocalCoordFunctionType &localCoordFunction )
208  : localCoordFunction_( localCoordFunction )
209  {}
210 
211  template< std::size_t size >
212  void calculate ( std::array< Coordinate, size > &corners ) const
213  {
214  assert( (localCoordFunction_.numDofs() % dimensionworld) == 0 );
215  const std::size_t numCorners = localCoordFunction_.numDofs() / dimensionworld;
216  assert( size >= numCorners );
217  for( std::size_t i = 0; i < numCorners; ++i )
218  {
219  for( int k = 0; k < dimensionworld; ++k )
220  corners[ i ][ k ] = localCoordFunction_[ i*dimensionworld + k ];
221  }
222  }
223 
224  private:
225  static_assert( LocalCoordFunctionType::dimRange == dimensionworld, "Invalid local coordinate function." );
226 
227  const LocalCoordFunctionType &localCoordFunction_;
228  };
229 
230 
231 
232  // IntersectionCoordVector
233  // -----------------------
234 
235  template< class GridFamily >
237  {
238  typedef typename std::remove_const< GridFamily >::type::Traits Traits;
239 
240  typedef typename std::remove_const< GridFamily >::type::ctype ctype;
241 
242  static const int dimension = std::remove_const< GridFamily >::type::dimension;
243  static const int codimension = 1;
244  static const int mydimension = dimension-codimension;
245  static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
246 
247  typedef FieldVector< ctype, dimensionworld > Coordinate;
248 
249  typedef typename Traits::template Codim< 0 >::Geometry ElementGeometryType;
250  typedef typename Traits::template Codim< codimension >::LocalGeometry HostLocalGeometryType;
251 
252  typedef typename ElementGeometryType::Implementation ElementGeometryImplType;
253 
254  public:
255  GeoIntersectionCoordVector ( const ElementGeometryImplType &elementGeometry,
256  const HostLocalGeometryType &hostLocalGeometry )
257  : elementGeometry_( elementGeometry ),
258  hostLocalGeometry_( hostLocalGeometry )
259  {}
260 
261  template< std::size_t size >
262  void calculate ( std::array< Coordinate, size > &corners ) const
263  {
264  const std::size_t numCorners = hostLocalGeometry_.corners();
265  assert( size >= numCorners );
266  for( std::size_t i = 0; i < numCorners; ++i )
267  corners[ i ] = elementGeometry_.global( hostLocalGeometry_.corner( i ) );
268  }
269 
270  private:
271  const ElementGeometryImplType &elementGeometry_;
272  HostLocalGeometryType hostLocalGeometry_;
273  };
274 
275 
276 
277  // GeoCornerStorage
278  // ----------------
279 
280  template< int mydim, int cdim, class GridFamily >
282  {
283  typedef typename std::remove_const< GridFamily >::type::ctype ctype;
284 
285  typedef FieldVector< ctype, cdim > Coordinate;
286 
287  typedef std::array< Coordinate, (1 << mydim) > Coords;
288 
289  public:
290  typedef typename Coords::const_iterator const_iterator;
291 
293  {
294  coords.calculate( coords_ );
295  }
296 
297  template< class LCFTraits >
299  {
300  coords.calculate( coords_ );
301  }
302 
304  {
305  coords.calculate( coords_ );
306  }
307 
308  const Coordinate &operator[] ( unsigned int i ) const
309  {
310  return coords_[ i ];
311  }
312 
313  const_iterator begin () const { return coords_.begin(); }
314  const_iterator end () const { return coords_.end(); }
315 
316  private:
317  Coords coords_;
318  };
319 
320  } // namespace Fem
321 
322 } // namespace Dune
323 
324 #endif // #ifndef DUNE_FEM_GRIDPART_GEOGRIDPART_CORNERSTORAGE_HH
GeometryType type() const
Definition: cornerstorage.hh:110
CoordFunction CoordFunctionType
Definition: cornerstorage.hh:94
void evaluate(unsigned int i, RangeType &y) const
Definition: cornerstorage.hh:105
Lagrange discrete function space.
Definition: cornerstorage.hh:23
void calculate(std::array< Coordinate, size > &corners) const
Definition: cornerstorage.hh:262
A vector valued function space.
Definition: functionspace.hh:16
Definition: cornerstorage.hh:147
CoordFunctionType::GridPartType::template Codim< codim >::EntityType HostEntityType
Definition: cornerstorage.hh:42
void calculate(std::array< Coordinate, size > &corners) const
Definition: cornerstorage.hh:212
Definition: cornerstorage.hh:31
CoordFunctionType::GridPartType::template Codim< codim >::EntityType HostEntityType
Definition: cornerstorage.hh:96
const_iterator end() const
Definition: cornerstorage.hh:314
CoordFunctionType::RangeType RangeType
Definition: cornerstorage.hh:97
interface for local functions
Definition: localfunction.hh:41
GeoCoordFunctionCaller(const CoordFunctionType &coordFunction, const HostEntityType &hostEntity)
Definition: cornerstorage.hh:135
Definition: cornerstorage.hh:88
GeoCornerStorage(const GeoIntersectionCoordVector< GridFamily > &coords)
Definition: cornerstorage.hh:303
LocalFunction LocalCoordFunctionType
Definition: cornerstorage.hh:205
Definition: coordinate.hh:4
BaseType::HostEntityType HostEntityType
Definition: cornerstorage.hh:133
GeoCornerStorage(const GeoCoordVector< mydim, GridFamily > &coords)
Definition: cornerstorage.hh:292
GeoCornerStorage(const GeoLocalCoordVector< mydim, GridFamily, LCFTraits > &coords)
Definition: cornerstorage.hh:298
BaseType::CoordFunctionType CoordFunctionType
Definition: cornerstorage.hh:132
const_iterator begin() const
Definition: cornerstorage.hh:313
GeoCoordFunctionCaller(const CoordFunction &coordFunction, const HostEntityType &hostEntity)
Definition: cornerstorage.hh:99
GeoLocalCoordVector(const LocalCoordFunctionType &localCoordFunction)
Definition: cornerstorage.hh:207
void calculate(std::array< Coordinate, size > &corners) const
Definition: cornerstorage.hh:174
GeoDiscreteCoordFunctionCaller(const CoordFunction &coordFunction, const HostEntityType &hostEntity)
Definition: cornerstorage.hh:49
Definition: cornerstorage.hh:236
Definition: cornerstorage.hh:281
std::size_t numCorners() const
Definition: cornerstorage.hh:115
Definition: cornerstorage.hh:191
Coords::const_iterator const_iterator
Definition: cornerstorage.hh:290
GeoCoordVector(const CoordFunctionType &coordFunction, const HostEntityType &hostEntity)
Definition: cornerstorage.hh:168
GeoIntersectionCoordVector(const ElementGeometryImplType &elementGeometry, const HostLocalGeometryType &hostLocalGeometry)
Definition: cornerstorage.hh:255