DUNE-FEM (unstable)

filteredgridpart.hh
1 #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
2 #define DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
3 
4 //- system includes
5 #include <cassert>
6 #include <memory>
7 
8 //- dune-grid includes
10 #include <dune/grid/common/gridview.hh>
11 
12 //- dune-fem includes
13 #include <dune/fem/gridpart/adaptiveleafindexset.hh>
14 #include <dune/fem/gridpart/common/gridpart.hh>
15 #include <dune/fem/gridpart/common/metatwistutility.hh>
16 #include <dune/fem/gridpart/filteredgridpart/capabilities.hh>
17 #include <dune/fem/gridpart/filteredgridpart/datahandle.hh>
18 #include <dune/fem/gridpart/filteredgridpart/intersection.hh>
19 #include <dune/fem/gridpart/filteredgridpart/intersectioniterator.hh>
20 #include <dune/fem/gridpart/filteredgridpart/iterator.hh>
21 
22 
23 namespace Dune
24 {
25 
26  namespace Fem
27  {
28 
29  // Forward declarations
30  // --------------------
31 
32  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet = false >
33  class FilteredGridPart;
34 
35 
36 
37  // FilteredGridPartIndexSetSelector
38  // --------------------------------
39 
40  template < class FilteredGP, class HostGP, bool useFilteredIndexSet >
41  struct FilteredGridPartIndexSetSelector
42  {
43  typedef AdaptiveLeafIndexSet< FilteredGP > IndexSetType;
44 
45  static IndexSetType *create(const FilteredGP &gridPart)
46  {
47  return new IndexSetType( gridPart );
48  }
49 
50  template < class IndexSetPtr >
51  static const IndexSetType&
52  indexSet ( const FilteredGP &gridPart, const std::unique_ptr< IndexSetPtr >& idxSetPtr )
53  {
54  assert( idxSetPtr );
55  return *idxSetPtr;
56  }
57  };
58 
59 
60  // FilteredGridPartIndexSetSelector
61  // specialization for non-filtered index set,
62  // i.e. host index set
63  // -----------------------------------------
64 
65  template< class FilteredGP, class HostGP >
66  struct FilteredGridPartIndexSetSelector< FilteredGP, HostGP, false >
67  {
68  typedef typename HostGP::IndexSetType IndexSetType;
69 
70  static IndexSetType *create(const FilteredGP &gridPart)
71  {
72  return nullptr;
73  }
74 
75  template < class IndexSetPtr >
76  static const IndexSetType&
77  indexSet ( const FilteredGP &gridPart, const std::unique_ptr< IndexSetPtr >& )
78  {
79  return gridPart.hostGridPart().indexSet();
80  }
81  };
82 
83 
84 
85  // EntityGridTypeGetter
86  // --------------------
87 
88  template< class Entity >
89  struct EntityGridTypeGetter;
90 
91  template< int codim, int dim, class Grid, template< int, int, class > class Impl >
92  struct EntityGridTypeGetter< Dune::Entity< codim, dim, Grid, Impl > >
93  {
94  typedef Grid Type;
95  };
96 
97  template< class Entity >
98  struct EntityGridTypeGetter< const Entity >
99  {
100  typedef typename EntityGridTypeGetter< Entity >::Type Type;
101  };
102 
103 
104 
105  // FilteredGridPartTraits
106  // ----------------------
107 
108  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet >
109  struct FilteredGridPartTraits
110  {
112  typedef FilteredGridPart< HostGridPartImp, FilterImp, useFilteredIndexSet > GridPartType;
113 
114  struct GridPartFamily
115  {
116  typedef FilterImp Filter;
117  typedef HostGridPartImp HostGridPart;
118 
119  static const int dimension = HostGridPart::dimension;
120  static const int dimensionworld = HostGridPart::dimensionworld;
121 
122  typedef typename HostGridPart::ctype ctype;
123 
124  typedef FilteredGridPartIntersectionIterator< const GridPartFamily > IntersectionIteratorImpl;
125  typedef FilteredGridPartIntersection< Filter, typename HostGridPart::IntersectionType > IntersectionImpl;
126 
129 
130  template< int codim >
131  struct Codim : public HostGridPart::template Codim< codim >
132  {
133  };
134  };
135 
137  typedef HostGridPartImp HostGridPartType;
138 
140  typedef typename HostGridPartType::GridType GridType;
142  typedef GridType Grid;
143 
145  typedef MetaTwistUtility< typename HostGridPartType :: TwistUtilityType > TwistUtilityType ;
146 
148  typedef FilterImp FilterType;
149 
151  typedef typename FilterType::EntityType EntityType;
152 
154  typedef FilteredGridPartIndexSetSelector< GridPartType, HostGridPartType, useFilteredIndexSet > IndexSetSelectorType;
155 
157  typedef typename IndexSetSelectorType::IndexSetType IndexSetType;
158 
160  typedef typename HostGridPartType::Traits::IntersectionIteratorType HostIntersectionIteratorType;
161 
163  typedef typename GridPartFamily::IntersectionIterator IntersectionIteratorType;
164 
166  typedef typename GridPartFamily::Intersection IntersectionType;
167 
169  template< int codim >
170  struct Codim : public HostGridPartType::template Codim< codim >
171  {
172  template< PartitionIteratorType pitype >
173  struct Partition
174  {
175  typedef Dune::EntityIterator< codim, typename EntityGridTypeGetter< EntityType >::Type, FilteredGridPartIterator< codim, pitype, GridPartType > > IteratorType;
176  typedef IteratorType Iterator;
177  };
178 
180  typedef IteratorType Iterator;
181  };
182 
183  typedef typename HostGridPartType::CommunicationType CommunicationType;
184  typedef CommunicationType Communication;
185 
187  static const PartitionIteratorType indexSetPartitionType = HostGridPartType::indexSetPartitionType;
188 
189  static const InterfaceType indexSetInterfaceType = HostGridPartType::indexSetInterfaceType;
190 
192  static const bool conforming = HostGridPartType::Traits::conforming;
193  };
194 
195 
196 
197  //***************************************************************************
198  //
199  // FilteredGridPart
200  //
218  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet >
220  : public GridPartDefault< FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > >
221  {
222  // type of this
225 
226  public:
227  //- Public typedefs and enums
229  typedef FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > Traits;
230 
232  typedef FilterImp FilterType;
233 
234  // type of host grid part
235  typedef typename Traits::HostGridPartType HostGridPartType;
236 
238  typedef typename Traits::GridType GridType;
239 
241  typedef typename Traits::IndexSetType IndexSetType;
242 
244  typedef typename Traits:: IntersectionIteratorType IntersectionIteratorType;
245 
248 
249  typedef typename Traits::CommunicationType CommunicationType;
250 
251  typedef ThisType GridViewType;
252 
254  template< int codim >
255  struct Codim : public Traits :: template Codim< codim >
256  {};
257 
258  private:
259  typedef typename Traits::IndexSetSelectorType IndexSetSelectorType;
260 
261  typedef typename Codim< 0 >::EntityType EntityType;
262 
263  public:
264  //- Public methods
266  FilteredGridPart ( HostGridPartType &hostGridPart, const FilterType &filter )
267  : BaseType( hostGridPart.grid() ),
268  hostGridPart_( &hostGridPart ),
269  filter_( new FilterType(filter) ),
270  indexSetPtr_( IndexSetSelectorType::create( *this ) )
271  {
272  }
273 
276  : BaseType( other ),
277  hostGridPart_( other.hostGridPart_ ),
278  filter_( new FilterType( other.filter()) ),
279  indexSetPtr_ ( IndexSetSelectorType::create( *this ) )
280  { }
281 
282  FilteredGridPart& operator = (const FilteredGridPart &other )
283  {
284  BaseType::operator=( other );
285  hostGridPart_ = other.hostGridPart_;
286  filter_.reset( new FilterType( other.filter() ) );
287  indexSetPtr_.reset( IndexSetSelectorType::create( *this ) );
288  return *this;
289  }
290 
292  // if IndexSetType is from host grid part the original index set is returned
293  const IndexSetType &indexSet() const
294  {
295  return IndexSetSelectorType::indexSet( *this, indexSetPtr_ );
296  }
297 
299  template< int codim >
301  {
302  return begin< codim, InteriorBorder_Partition >();
303  }
304 
306  template< int codim, PartitionIteratorType pitype >
307  typename Codim< codim >::template Partition< pitype >::IteratorType begin () const
308  {
309  typedef typename Codim< codim >::template Partition< pitype >::IteratorType IteratorType;
310  typedef FilteredGridPartIterator< codim, pitype, ThisType > IteratorImpl;
311  return IteratorType( IteratorImpl( *this, hostGridPart().template begin< codim, pitype >() ) );
312  }
313 
315  template< int codim >
317  {
318  return end< codim, InteriorBorder_Partition >();
319  }
320 
322  template< int codim, PartitionIteratorType pitype >
323  typename Codim< codim >::template Partition< pitype >::IteratorType end () const
324  {
325  typedef typename Codim< codim >::template Partition< pitype >::IteratorType IteratorType;
326  typedef FilteredGridPartIterator< codim, pitype, ThisType > IteratorImpl;
327  return IteratorType( IteratorImpl( *this, hostGridPart().template end< codim, pitype >() ) );
328  }
329 
331  int level () const
332  {
333  return hostGridPart().level();
334  }
335 
337  IntersectionIteratorType ibegin ( const EntityType &entity ) const
338  {
339  typedef typename IntersectionIteratorType::Implementation IntersectionIteratorImpl;
340  return IntersectionIteratorType( IntersectionIteratorImpl( filter(), hostGridPart().ibegin( entity ) ) );
341  }
342 
344  IntersectionIteratorType iend ( const EntityType &entity ) const
345  {
346  typedef typename IntersectionIteratorType::Implementation IntersectionIteratorImpl;
347  return IntersectionIteratorType( IntersectionIteratorImpl( filter(), hostGridPart().iend( entity ) ) );
348  }
349 
351  template < class DataHandleImp, class DataType >
353  InterfaceType iftype, CommunicationDirection dir ) const
354  {
355  typedef CommDataHandleIF< DataHandleImp, DataType > HostHandleType;
356  FilteredGridPartDataHandle< HostHandleType, ThisType > handleWrapper( dataHandle, *this );
357  hostGridPart().communicate( handleWrapper, iftype, dir );
358  }
359 
361  template < class EntitySeed >
363  entity ( const EntitySeed &seed ) const
364  {
365  return hostGridPart().entity( seed );
366  }
367 
369  const FilterType &filter () const
370  {
371  return *filter_;
372  }
373 
376  {
377  return *filter_;
378  }
379 
380  template< class Entity >
381  bool contains ( const Entity &entity ) const
382  {
383  return filter().contains( entity );
384  }
385 
386  HostGridPartType &hostGridPart ()
387  {
388  assert( hostGridPart_ );
389  return *hostGridPart_;
390  }
391 
392  const HostGridPartType &hostGridPart () const
393  {
394  assert( hostGridPart_ );
395  return *hostGridPart_;
396  }
397 
399  template <class Entity>
400  const Entity& convert ( const Entity &entity ) const
401  {
402  return hostGridPart().convert( entity );
403  }
404 
405  private:
406  HostGridPartType *hostGridPart_;
407  std::unique_ptr< FilterType > filter_;
408  std::unique_ptr< IndexSetType > indexSetPtr_;
409  };
410 
411  template< class GridPartFamily >
412  struct GridIntersectionAccess< Dune::Intersection< const GridPartFamily, typename GridPartFamily::IntersectionImpl > >
413  {
415  typedef GridIntersectionAccess< typename IntersectionType::Implementation::HostIntersectionType > HostAccessType;
416  typedef typename HostAccessType::GridIntersectionType GridIntersectionType;
417 
418  static const typename HostAccessType::GridIntersectionType &gridIntersection ( const IntersectionType &intersection )
419  {
420  return HostAccessType::gridIntersection( intersection.impl().hostIntersection() );
421  }
422  };
423 
424  } // namespace Fem
425 
426 } // namespace Dune
427 
428 #endif // #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
interface class for an iterator over grid entities
Definition: entityiterator.hh:32
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:26
Wrapper class for entities.
Definition: entity.hh:66
A FilteredGridPart allows to extract a set of entities from a grid satisfying a given constrainted de...
Definition: filteredgridpart.hh:221
FilteredGridPart(HostGridPartType &hostGridPart, const FilterType &filter)
constructor
Definition: filteredgridpart.hh:266
Codim< codim >::template Partition< pitype >::IteratorType end() const
End iterator on the leaf level.
Definition: filteredgridpart.hh:323
IntersectionIteratorType ibegin(const EntityType &entity) const
ibegin of corresponding intersection iterator for given entity
Definition: filteredgridpart.hh:337
Codim< codim >::IteratorType end() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:316
const IndexSetType & indexSet() const
return index set of this grid part
Definition: filteredgridpart.hh:293
Traits::GridType GridType
grid type
Definition: filteredgridpart.hh:238
Traits::IntersectionIteratorType IntersectionIteratorType
intersection iterator type
Definition: filteredgridpart.hh:244
Traits::IndexSetType IndexSetType
index set type
Definition: filteredgridpart.hh:241
int level() const
Returns maxlevel of the grid.
Definition: filteredgridpart.hh:331
FilterType & filter()
return reference to filter
Definition: filteredgridpart.hh:375
Codim< codim >::template Partition< pitype >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:307
Codim< codim >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:300
const FilterType & filter() const
return reference to filter
Definition: filteredgridpart.hh:369
FilteredGridPart(const FilteredGridPart &other)
copy constructor
Definition: filteredgridpart.hh:275
Codim< EntitySeed::codimension >::EntityType entity(const EntitySeed &seed) const
obtain entity pointer from entity seed
Definition: filteredgridpart.hh:363
FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > Traits
traits class
Definition: filteredgridpart.hh:229
FilterImp FilterType
type of filter
Definition: filteredgridpart.hh:232
void communicate(CommDataHandleIF< DataHandleImp, DataType > &dataHandle, InterfaceType iftype, CommunicationDirection dir) const
corresponding communication method for this grid part
Definition: filteredgridpart.hh:352
IntersectionIteratorType iend(const EntityType &entity) const
iend of corresponding intersection iterator for given entity
Definition: filteredgridpart.hh:344
const Entity & convert(const Entity &entity) const
convert the grid's entity to a grid part entity Usually the parameter is GridType :: Codim< codim > :...
Definition: filteredgridpart.hh:400
IntersectionIteratorType::Intersection IntersectionType
intersection type
Definition: filteredgridpart.hh:247
Default implementation for the GridPart classes.
Definition: gridpart.hh:372
const GridType & grid() const
Returns const reference to the underlying grid.
Definition: gridpart.hh:423
Interface for the GridPart classes A GridPart class allows to access only a specific subset of a grid...
Definition: gridpart.hh:76
GridPartTraits Traits
Type of the Traits.
Definition: gridpart.hh:81
Traits::CommunicationType CommunicationType
Collective communication.
Definition: gridpart.hh:97
Traits::IntersectionIteratorType IntersectionIteratorType
type of IntersectionIterator
Definition: gridpart.hh:111
Traits::IndexSetType IndexSetType
Index set implementation.
Definition: gridpart.hh:92
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: intersectioniterator.hh:83
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: intersection.hh:164
Describes the parallel communication interface class for MessageBuffers and DataHandles.
PartitionIteratorType
Parameter to be used for the parallel level- and leaf iterators.
Definition: gridenums.hh:136
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
concept Intersection
Model of an intersection.
Definition: intersection.hh:23
concept Grid
Requirements for implementations of the Dune::Grid interface.
Definition: grid.hh:98
concept Entity
Model of a grid entity.
Definition: entity.hh:107
concept IntersectionIterator
Model of an intersection iterator.
Definition: intersectioniterator.hh:21
Dune namespace.
Definition: alignedallocator.hh:13
Static tag representing a codimension.
Definition: dimension.hh:24
struct providing types of the iterators on codimension cd
Definition: filteredgridpart.hh:171
grid part typedefs, use those of traits
Definition: filteredgridpart.hh:256
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)