DUNE-FEM (unstable)

cornerstorage.hh
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 >
31  class GeoDiscreteCoordFunctionCaller;
32 
33  template< int codim, class CoordFunction, class FunctionSpace, class GridPart, class Storage >
34  class GeoDiscreteCoordFunctionCaller< codim, CoordFunction, LagrangeDiscreteFunctionSpace< FunctionSpace, GridPart, 1, Storage > >
35  {
36  typedef LagrangeDiscreteFunctionSpace< FunctionSpace, GridPart, 1, Storage > DFSpace;
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  {
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 >
85  class GeoCoordFunctionCaller;
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  {
126  typedef GeoDiscreteCoordFunctionCaller< codim, CoordFunction > BaseType;
127 
128  public:
129  typedef typename BaseType::CoordFunctionType CoordFunctionType;
130  typedef typename BaseType::HostEntityType HostEntityType;
131 
132  GeoCoordFunctionCaller ( const CoordFunctionType &coordFunction,
133  const HostEntityType &hostEntity )
134  : BaseType( coordFunction, hostEntity )
135  {}
136  };
137 
138 
139 
140  // GeoCoordVector
141  // --------------
142 
143  template< int mydim, class GridFamily >
144  class GeoCoordVector
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 
162  typedef GeoCoordFunctionCaller< codimension, CoordFunctionType > CoordFunctionCallerType;
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 >
188  class GeoLocalCoordVector
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:
202  typedef LocalFunction LocalCoordFunctionType;
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 >
233  class GeoIntersectionCoordVector
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 >
278  class GeoCornerStorage
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 
289  explicit GeoCornerStorage ( const GeoCoordVector< mydim, GridFamily > &coords )
290  {
291  coords.calculate( coords_ );
292  }
293 
294  template< class LCFTraits >
295  explicit GeoCornerStorage ( const GeoLocalCoordVector< mydim, GridFamily, LCFTraits > &coords )
296  {
297  coords.calculate( coords_ );
298  }
299 
300  explicit GeoCornerStorage ( const GeoIntersectionCoordVector< GridFamily > &coords )
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
static const int dimRange
dimension of the range
Definition: localfunction.hh:119
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
concept Geometry
Model of a geometry object.
Definition: geometry.hh:29
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)