dune-fem  2.4.1-rc
filteredgridpart.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
2 #define DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
3 
4 //- system includes
5 #include <cassert>
6 
7 //- dune-grid includes
8 #include <dune/grid/common/datahandleif.hh>
9 #include <dune/grid/common/gridview.hh>
10 
11 //- dune-fem includes
19 
20 
21 namespace Dune
22 {
23 
24  namespace Fem
25  {
26 
27  // Forward declarations
28  // --------------------
29 
30  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet = false >
31  class FilteredGridPart;
32 
33 
34 
35  // FilteredGridPartIndexSetSelector
36  // --------------------------------
37 
38  template < class FilteredGP, class HostGP, bool useFilteredIndexSet >
40  {
42 
43  static IndexSetType *create(const FilteredGP &gridPart)
44  {
45  return new IndexSetType( gridPart );
46  }
47 
48  template < class IndexSetPtr >
49  static const IndexSetType &
50  indexSet ( const FilteredGP &gridPart, const IndexSetPtr *idxSetPtr )
51  {
52  assert( idxSetPtr );
53  return *idxSetPtr;
54  }
55  };
56 
57 
58  // when index set from gridpartimp is used return 0
59  template< class FilteredGP, class HostGP >
60  struct FilteredGridPartIndexSetSelector< FilteredGP, HostGP, false >
61  {
62  typedef typename HostGP::IndexSetType IndexSetType;
63 
64  static IndexSetType *create(const FilteredGP &gridPart)
65  {
66  return 0;
67  }
68 
69  template < class IndexSetPtr >
70  static const IndexSetType &
71  indexSet ( const FilteredGP &gridPart, const IndexSetPtr * )
72  {
73  return gridPart.hostGridPart().indexSet();
74  }
75  };
76 
77 
78 
79  // EntityGridTypeGetter
80  // --------------------
81 
82  template< class Entity >
84 
85  template< int codim, int dim, class Grid, template< int, int, class > class Impl >
86  struct EntityGridTypeGetter< Dune::Entity< codim, dim, Grid, Impl > >
87  {
88  typedef Grid Type;
89  };
90 
91  template< class Entity >
92  struct EntityGridTypeGetter< const Entity >
93  {
95  };
96 
97 
98 
99  // FilteredGridPartTraits
100  // ----------------------
101 
102  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet >
104  {
107 
109  typedef HostGridPartImp HostGridPartType;
110 
112  typedef typename HostGridPartType::GridType GridType;
113 
116 
118  typedef FilterImp FilterType;
119 
121  typedef typename FilterType::EntityType EntityType;
122 
125 
128 
130  typedef typename HostGridPartType::Traits::IntersectionIteratorType HostIntersectionIteratorType;
131 
134 
136 
138  template< int codim >
139  struct Codim
140  {
141  typedef typename HostGridPartType::template Codim< codim >::GeometryType GeometryType;
142  typedef typename HostGridPartType::template Codim< codim >::LocalGeometryType LocalGeometryType;
143 
144  typedef typename HostGridPartType::template Codim< codim >::EntityType EntityType;
145  typedef typename HostGridPartType::template Codim< codim >::EntityPointerType EntityPointerType;
146 
147  typedef typename HostGridPartType::template Codim< codim >::EntitySeedType EntitySeedType;
148 
149  template< PartitionIteratorType pitype >
150  struct Partition
151  {
152  typedef Dune::EntityIterator< codim, typename EntityGridTypeGetter< EntityType >::Type, FilteredGridPartIterator< codim, pitype, GridPartType > > IteratorType;
153  };
154 
156  };
157 
158  typedef typename HostGridPartType::CollectiveCommunicationType CollectiveCommunicationType;
159 
161  static const PartitionIteratorType indexSetPartitionType = HostGridPartType::indexSetPartitionType;
162 
163  static const InterfaceType indexSetInterfaceType = HostGridPartType::indexSetInterfaceType;
164 
166  static const bool conforming = HostGridPartType::Traits::conforming;
167  };
168 
169 
170 
171  //***************************************************************************
172  //
173  // FilteredGridPart
174  //
192  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet >
193  class FilteredGridPart
194  : public GridPartInterface< FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > >
195  {
196  // type of this
198 
199  public:
200  //- Public typedefs and enums
203 
205  typedef FilterImp FilterType;
206 
207  // type of host grid part
209 
211  typedef typename Traits::GridType GridType;
212 
215 
218 
221 
223 
225  template< int codim >
226  struct Codim : public Traits :: template Codim< codim >
227  {};
228 
229  private:
231 
232  typedef typename Codim< 0 >::EntityType EntityType;
233 
234  public:
235  //- Public methods
237  FilteredGridPart ( HostGridPartType &hostGridPart, const FilterType &filter )
238  : hostGridPart_( hostGridPart ),
239  filter_( filter ),
240  indexSetPtr_( 0 )
241  {
242  indexSetPtr_ = IndexSetSelectorType::create( *this );
243  }
244 
247  {
248  if( indexSetPtr_ )
249  delete indexSetPtr_;
250  }
251 
254  : hostGridPart_( other.hostGridPart_ ),
255  filter_( other.filter_ ),
256  indexSetPtr_ ( IndexSetSelectorType::create( *this ) )
257  { }
258 
260  const GridType &grid () const
261  {
262  return hostGridPart().grid();
263  }
264 
266  GridType &grid ()
267  {
268  return hostGridPart().grid();
269  }
270 
272  // if IndexSetType is from host grid part the original index set is returned
273  const IndexSetType &indexSet() const
274  {
275  return IndexSetSelectorType::indexSet( *this, indexSetPtr_ );
276  }
277 
279  template< int codim >
281  {
282  return begin< codim, InteriorBorder_Partition >();
283  }
284 
286  template< int codim, PartitionIteratorType pitype >
287  typename Codim< codim >::template Partition< pitype >::IteratorType begin () const
288  {
289  typedef typename Codim< codim >::template Partition< pitype >::IteratorType IteratorType;
290  typedef typename IteratorType::Implementation IteratorImpl;
291  return IteratorType( IteratorImpl( *this, hostGridPart().template begin< codim, pitype >() ) );
292  }
293 
295  template< int codim >
297  {
298  return end< codim, InteriorBorder_Partition >();
299  }
300 
302  template< int codim, PartitionIteratorType pitype >
303  typename Codim< codim >::template Partition< pitype >::IteratorType end () const
304  {
305  typedef typename Codim< codim >::template Partition< pitype >::IteratorType IteratorType;
306  typedef typename IteratorType::Implementation IteratorImpl;
307  return IteratorType( IteratorImpl( *this, hostGridPart().template end< codim, pitype >() ) );
308  }
309 
311  int level () const
312  {
313  return hostGridPart().level();
314  }
315 
317  IntersectionIteratorType ibegin ( const EntityType &entity ) const
318  {
319  return typename ThisType::IntersectionIteratorType( *this, entity, hostGridPart().ibegin( entity ) );
320  }
321 
323  IntersectionIteratorType iend ( const EntityType &entity ) const
324  {
325  return typename ThisType::IntersectionIteratorType( *this, entity, hostGridPart().iend( entity ) );
326  }
327 
328  int boundaryId ( const IntersectionType &intersection ) const
329  {
330  return intersection.boundaryId();
331  }
332 
333  const CollectiveCommunicationType &comm () const { return hostGridPart_.comm(); }
334 
336  template < class DataHandleImp, class DataType >
337  void communicate ( CommDataHandleIF< DataHandleImp, DataType > &dataHandle,
338  InterfaceType iftype, CommunicationDirection dir ) const
339  {
340  typedef CommDataHandleIF< DataHandleImp, DataType > HostHandleType;
341  FilteredGridPartDataHandle< HostHandleType, ThisType > handleWrapper( dataHandle, *this );
342  hostGridPart().communicate( handleWrapper, iftype, dir );
343  }
344 
346  template < class EntitySeed >
348  entity ( const EntitySeed &seed ) const
349  {
350  return hostGridPart().entity( seed );
351  }
352 
354  const FilterType &filter () const
355  {
356  return filter_;
357  }
358 
360  FilterType &filter ()
361  {
362  return filter_;
363  }
364 
365  template< class Entity >
366  bool contains ( const Entity &entity ) const
367  {
368  return filter().contains( entity );
369  }
370 
371  HostGridPartType &hostGridPart ()
372  {
373  return hostGridPart_;
374  }
375 
376  const HostGridPartType &hostGridPart () const
377  {
378  return hostGridPart_;
379  }
380 
382  template <class Entity>
383  const Entity& convert ( const Entity &entity ) const
384  {
385  return hostGridPart().convert( entity );
386  }
387 
388  private:
389  HostGridPartType &hostGridPart_;
390  FilterType filter_;
391  const IndexSetType *indexSetPtr_;
392  };
393 
394  } // namespace Fem
395 
396 } // namespace Dune
397 
398 #endif // #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
int boundaryId(const IntersectionType &intersection) const
Definition: filteredgridpart.hh:328
IndexSetSelectorType::IndexSetType IndexSetType
index set use in this gridpart
Definition: filteredgridpart.hh:127
Codim< EntitySeed::codimension >::EntityType entity(const EntitySeed &seed) const
obtain entity pointer from entity seed
Definition: filteredgridpart.hh:348
FilteredGridPartIndexSetSelector< GridPartType, HostGridPartType, useFilteredIndexSet > IndexSetSelectorType
index set use in this gridpart
Definition: filteredgridpart.hh:124
bool contains(const Entity &entity) const
Definition: filteredgridpart.hh:366
HostGridPartType::template Codim< codim >::EntityType EntityType
Definition: filteredgridpart.hh:144
HostGP::IndexSetType IndexSetType
Definition: filteredgridpart.hh:62
const GridType & grid() const
return const reference to underlying grid
Definition: filteredgridpart.hh:260
FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > Traits
traits class
Definition: filteredgridpart.hh:202
Traits::IntersectionIteratorType IntersectionIteratorType
intersection iterator type
Definition: filteredgridpart.hh:217
const FilterType & filter() const
return reference to filter
Definition: filteredgridpart.hh:354
Definition: filteredgridpart/intersectioniterator.hh:23
~FilteredGridPart()
destructor
Definition: filteredgridpart.hh:246
Definition: filteredgridpart.hh:39
void communicate(CommDataHandleIF< DataHandleImp, DataType > &dataHandle, InterfaceType iftype, CommunicationDirection dir) const
corresponding communication method for this grid part
Definition: filteredgridpart.hh:337
static const IndexSetType & indexSet(const FilteredGP &gridPart, const IndexSetPtr *idxSetPtr)
Definition: filteredgridpart.hh:50
IntersectionIteratorType::Intersection IntersectionType
intersection type
Definition: filteredgridpart.hh:220
IntersectionIteratorType iend(const EntityType &entity) const
iend of corresponding intersection iterator for given entity
Definition: filteredgridpart.hh:323
const CollectiveCommunicationType & comm() const
Definition: filteredgridpart.hh:333
struct providing types of the iterators on codimension cd
Definition: filteredgridpart.hh:139
HostGridPartType::template Codim< codim >::LocalGeometryType LocalGeometryType
Definition: filteredgridpart.hh:142
int level() const
Returns maxlevel of the grid.
Definition: filteredgridpart.hh:311
Codim< codim >::template Partition< pitype >::IteratorType end() const
End iterator on the leaf level.
Definition: filteredgridpart.hh:303
A FilteredGridPart allows to extract a set of entities from a grid satisfying a given constrainted de...
Definition: gridpart/filteredgridpart/capabilities.hh:23
int boundaryId() const
overloaded boundaryId method
Definition: filteredgridpart/intersectioniterator.hh:177
HostGridPartImp HostGridPartType
grid part imp
Definition: filteredgridpart.hh:109
static const IndexSetType & indexSet(const FilteredGP &gridPart, const IndexSetPtr *)
Definition: filteredgridpart.hh:71
Traits::IndexSetType IndexSetType
index set type
Definition: filteredgridpart.hh:214
IntersectionIteratorType ibegin(const EntityType &entity) const
ibegin of corresponding intersection iterator for given entity
Definition: filteredgridpart.hh:317
Definition: filteredgridpart.hh:83
const HostGridPartType & hostGridPart() const
Definition: filteredgridpart.hh:376
Codim< codim >::template Partition< pitype >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:287
Codim< codim >::IteratorType end() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:296
FilterType & filter()
return reference to filter
Definition: filteredgridpart.hh:360
HostGridPartType::Traits::IntersectionIteratorType HostIntersectionIteratorType
of host grid part intersection iterator type
Definition: filteredgridpart.hh:130
Definition: filteredgridpart.hh:150
Definition: filteredgridpart/datahandle.hh:29
Definition: coordinate.hh:4
HostGridPartType::template Codim< codim >::EntitySeedType EntitySeedType
Definition: filteredgridpart.hh:147
Codim< codim >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:280
Traits::HostGridPartType HostGridPartType
Definition: filteredgridpart.hh:208
const Entity & convert(const Entity &entity) const
convert the grid&#39;s entity to a grid part entity Usually the parameter is GridType :: Codim< codim > :...
Definition: filteredgridpart.hh:383
AdaptiveLeafIndexSet< FilteredGP > IndexSetType
Definition: filteredgridpart.hh:41
Traits::CollectiveCommunicationType CollectiveCommunicationType
Definition: filteredgridpart.hh:222
Definition: filteredgridpart.hh:103
FilteredGridPartIntersectionIterator< const FilterType, const GridPartType, HostIntersectionIteratorType > IntersectionIteratorType
type of intersection iterator
Definition: filteredgridpart.hh:133
static IndexSetType * create(const FilteredGP &gridPart)
Definition: filteredgridpart.hh:64
FilterImp FilterType
type of filter
Definition: filteredgridpart.hh:205
HostGridPartType::GridType GridType
type of grid
Definition: filteredgridpart.hh:112
FilterType::EntityType EntityType
type of entity
Definition: filteredgridpart.hh:121
FilteredGridPart(HostGridPartType &hostGridPart, const FilterType &filter)
constructor
Definition: filteredgridpart.hh:237
IntersectionIteratorType::Intersection IntersectionType
Definition: filteredgridpart.hh:135
const IndexSetType & indexSet() const
return index set of this grid part
Definition: filteredgridpart.hh:273
HostGridPartType::template Codim< codim >::EntityPointerType EntityPointerType
Definition: filteredgridpart.hh:145
MetaTwistUtility forwards the twist calls to the TwistUtility of the underlying HostTwistUtility.
Definition: metatwistutility.hh:21
HostGridPartType::template Codim< codim >::GeometryType GeometryType
Definition: filteredgridpart.hh:141
Partition< InteriorBorder_Partition >::IteratorType IteratorType
Definition: filteredgridpart.hh:155
consecutive, persistent index set for the leaf level based on the grid&#39;s hierarchy index set ...
Definition: adaptiveleafindexset.hh:31
Interface for the GridPart classes A GridPart class allows to access only a specific subset of a grid...
Definition: gridpart.hh:75
EntityGridTypeGetter< Entity >::Type Type
Definition: filteredgridpart.hh:94
FilterImp FilterType
export filter type
Definition: filteredgridpart.hh:118
Traits::GridType GridType
grid type
Definition: filteredgridpart.hh:211
static IndexSetType * create(const FilteredGP &gridPart)
Definition: filteredgridpart.hh:43
MetaTwistUtility< typename HostGridPartType::TwistUtilityType > TwistUtilityType
The type of the corresponding TwistUtility.
Definition: filteredgridpart.hh:115
HostGridPartType::CollectiveCommunicationType CollectiveCommunicationType
Definition: filteredgridpart.hh:158
grid part typedefs, use those of traits
Definition: filteredgridpart.hh:226
FilteredGridPart(const FilteredGridPart &other)
copy constructor
Definition: filteredgridpart.hh:253
Dune::EntityIterator< codim, typename EntityGridTypeGetter< EntityType >::Type, FilteredGridPartIterator< codim, pitype, GridPartType > > IteratorType
Definition: filteredgridpart.hh:152
Definition: filteredgridpart/iterator.hh:20
HostGridPartType & hostGridPart()
Definition: filteredgridpart.hh:371
GridType & grid()
return reference to underlying grid
Definition: filteredgridpart.hh:266
FilteredGridPart< HostGridPartImp, FilterImp, useFilteredIndexSet > GridPartType
type of grid part
Definition: filteredgridpart.hh:106