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