dune-fem  2.8-git
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 #include <memory>
7 
8 //- dune-grid includes
9 #include <dune/grid/common/datahandleif.hh>
10 #include <dune/grid/common/gridview.hh>
11 
12 //- dune-fem includes
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 >
42  {
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 >
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  {
101  };
102 
103 
104 
105  // FilteredGridPartTraits
106  // ----------------------
107 
108  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet >
110  {
113 
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 
126 
127  typedef Dune::IntersectionIterator< const GridPartFamily, IntersectionIteratorImpl, IntersectionImpl > IntersectionIterator;
128  typedef Dune::Intersection< const GridPartFamily, IntersectionImpl > Intersection;
129 
130  template< int codim >
131  struct Codim
132  {
133  typedef typename HostGridPart::template Codim< codim >::GeometryType Geometry;
134  typedef typename HostGridPart::template Codim< codim >::LocalGeometryType LocalGeometry;
135 
136  typedef typename HostGridPart::template Codim< codim >::EntityType Entity;
137  typedef typename HostGridPart::template Codim< codim >::EntitySeedType EntitySeed;
138  };
139  };
140 
142  typedef HostGridPartImp HostGridPartType;
143 
145  typedef typename HostGridPartType::GridType GridType;
146 
149 
151  typedef FilterImp FilterType;
152 
154  typedef typename FilterType::EntityType EntityType;
155 
158 
161 
163  typedef typename HostGridPartType::Traits::IntersectionIteratorType HostIntersectionIteratorType;
164 
167 
170 
172  template< int codim >
173  struct Codim
174  {
175  typedef typename HostGridPartType::template Codim< codim >::GeometryType GeometryType;
176  typedef typename HostGridPartType::template Codim< codim >::LocalGeometryType LocalGeometryType;
177 
178  typedef typename HostGridPartType::template Codim< codim >::EntityType EntityType;
179  typedef typename HostGridPartType::template Codim< codim >::EntitySeedType EntitySeedType;
180 
181  template< PartitionIteratorType pitype >
182  struct Partition
183  {
184  typedef Dune::EntityIterator< codim, typename EntityGridTypeGetter< EntityType >::Type, FilteredGridPartIterator< codim, pitype, GridPartType > > IteratorType;
185  };
186 
188  };
189 
190  typedef typename HostGridPartType::CollectiveCommunicationType CollectiveCommunicationType;
191 
193  static const PartitionIteratorType indexSetPartitionType = HostGridPartType::indexSetPartitionType;
194 
195  static const InterfaceType indexSetInterfaceType = HostGridPartType::indexSetInterfaceType;
196 
198  static const bool conforming = HostGridPartType::Traits::conforming;
199  };
200 
201 
202 
203  //***************************************************************************
204  //
205  // FilteredGridPart
206  //
224  template< class HostGridPartImp, class FilterImp, bool useFilteredIndexSet >
226  : public GridPartInterface< FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > >
227  , public AddGridView< FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > >
228  {
229  // type of this
232 
233  public:
234  //- Public typedefs and enums
237 
239  typedef FilterImp FilterType;
240 
241  // type of host grid part
243 
245  typedef typename Traits::GridType GridType;
246 
249 
252 
254  typedef typename IntersectionIteratorType::Intersection IntersectionType;
255 
257 
259 
261  template< int codim >
262  struct Codim : public Traits :: template Codim< codim >
263  {};
264 
265  private:
267 
268  typedef typename Codim< 0 >::EntityType EntityType;
269 
270  public:
271  //- Public methods
274  : AddGridViewType( this ),
275  hostGridPart_( hostGridPart ),
276  filter_( filter ),
277  indexSetPtr_( IndexSetSelectorType::create( *this ) )
278  {
279  }
280 
283  hostGridPart_( hostGridPart ),
284  filter_( filter ),
285  indexSetPtr_( IndexSetSelectorType::create( *this ) )
286  {
287  }
288 
291  : AddGridViewType( other ),
292  hostGridPart_( other.hostGridPart_ ),
293  filter_( other.filter_ ),
294  indexSetPtr_ ( IndexSetSelectorType::create( *this ) )
295  { }
296 
298  const GridType &grid () const
299  {
300  return hostGridPart().grid();
301  }
302 
305  {
306  return hostGridPart().grid();
307  }
308 
310  // if IndexSetType is from host grid part the original index set is returned
311  const IndexSetType &indexSet() const
312  {
313  return IndexSetSelectorType::indexSet( *this, indexSetPtr_ );
314  }
315 
317  template< int codim >
319  {
320  return begin< codim, InteriorBorder_Partition >();
321  }
322 
324  template< int codim, PartitionIteratorType pitype >
325  typename Codim< codim >::template Partition< pitype >::IteratorType begin () const
326  {
327  typedef typename Codim< codim >::template Partition< pitype >::IteratorType IteratorType;
329  return IteratorType( IteratorImpl( *this, hostGridPart().template begin< codim, pitype >() ) );
330  }
331 
333  template< int codim >
335  {
336  return end< codim, InteriorBorder_Partition >();
337  }
338 
340  template< int codim, PartitionIteratorType pitype >
341  typename Codim< codim >::template Partition< pitype >::IteratorType end () const
342  {
343  typedef typename Codim< codim >::template Partition< pitype >::IteratorType IteratorType;
345  return IteratorType( IteratorImpl( *this, hostGridPart().template end< codim, pitype >() ) );
346  }
347 
349  int level () const
350  {
351  return hostGridPart().level();
352  }
353 
355  IntersectionIteratorType ibegin ( const EntityType &entity ) const
356  {
357  typedef typename IntersectionIteratorType::Implementation IntersectionIteratorImpl;
358  return IntersectionIteratorType( IntersectionIteratorImpl( filter(), hostGridPart().ibegin( entity ) ) );
359  }
360 
362  IntersectionIteratorType iend ( const EntityType &entity ) const
363  {
364  typedef typename IntersectionIteratorType::Implementation IntersectionIteratorImpl;
365  return IntersectionIteratorType( IntersectionIteratorImpl( filter(), hostGridPart().iend( entity ) ) );
366  }
367 
369  int boundaryId ( const IntersectionType &intersection ) const
370  {
371  return hostGridPart().boundaryId( intersection.impl().hostIntersection() );
372  }
373 
374  const CollectiveCommunicationType &comm () const { return hostGridPart_.comm(); }
375 
377  template < class DataHandleImp, class DataType >
378  void communicate ( CommDataHandleIF< DataHandleImp, DataType > &dataHandle,
379  InterfaceType iftype, CommunicationDirection dir ) const
380  {
381  typedef CommDataHandleIF< DataHandleImp, DataType > HostHandleType;
382  FilteredGridPartDataHandle< HostHandleType, ThisType > handleWrapper( dataHandle, *this );
383  hostGridPart().communicate( handleWrapper, iftype, dir );
384  }
385 
387  template < class EntitySeed >
388  typename Codim< EntitySeed::codimension >::EntityType
389  entity ( const EntitySeed &seed ) const
390  {
391  return hostGridPart().entity( seed );
392  }
393 
395  const FilterType &filter () const
396  {
397  return filter_;
398  }
399 
402  {
403  return filter_;
404  }
405 
406  template< class Entity >
407  bool contains ( const Entity &entity ) const
408  {
409  return filter().contains( entity );
410  }
411 
413  {
414  return hostGridPart_;
415  }
416 
418  {
419  return hostGridPart_;
420  }
421 
423  template <class Entity>
424  const Entity& convert ( const Entity &entity ) const
425  {
426  return hostGridPart().convert( entity );
427  }
428 
429  private:
430  HostGridPartType &hostGridPart_;
431  FilterType filter_;
432  std::unique_ptr< IndexSetType > indexSetPtr_;
433  };
434 
435  } // namespace Fem
436 
437 } // namespace Dune
438 
439 #endif // #ifndef DUNE_FEM_GRIDPART_FILTEREDGRIDPART_HH
Definition: bindguard.hh:11
consecutive, persistent index set for the leaf level based on the grid's hierarchy index set
Definition: adaptiveleafindexset.hh:1345
Interface for the GridPart classes A GridPart class allows to access only a specific subset of a grid...
Definition: gridpart.hh:77
Definition: gridpart.hh:419
Definition: gridpart2gridview.hh:69
MetaTwistUtility forwards the twist calls to the TwistUtility of the underlying HostTwistUtility.
Definition: metatwistutility.hh:22
A FilteredGridPart allows to extract a set of entities from a grid satisfying a given constrainted de...
Definition: filteredgridpart.hh:228
int boundaryId(const IntersectionType &intersection) const
boundary id
Definition: filteredgridpart.hh:369
HostGridPartType & hostGridPart()
Definition: filteredgridpart.hh:412
const GridType & grid() const
return const reference to underlying grid
Definition: filteredgridpart.hh:298
FilteredGridPart(HostGridPartType &hostGridPart, const FilterType &filter)
constructor
Definition: filteredgridpart.hh:273
Codim< codim >::template Partition< pitype >::IteratorType end() const
End iterator on the leaf level.
Definition: filteredgridpart.hh:341
IntersectionIteratorType ibegin(const EntityType &entity) const
ibegin of corresponding intersection iterator for given entity
Definition: filteredgridpart.hh:355
Codim< codim >::IteratorType end() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:334
Traits::CollectiveCommunicationType CollectiveCommunicationType
Definition: filteredgridpart.hh:256
const CollectiveCommunicationType & comm() const
Definition: filteredgridpart.hh:374
const IndexSetType & indexSet() const
return index set of this grid part
Definition: filteredgridpart.hh:311
FilteredGridPart(HostGridPartType &hostGridPart, const FilterType &filter, const GridViewType *gridView)
Definition: filteredgridpart.hh:281
Traits::GridType GridType
grid type
Definition: filteredgridpart.hh:245
Traits::IntersectionIteratorType IntersectionIteratorType
intersection iterator type
Definition: filteredgridpart.hh:251
Traits::IndexSetType IndexSetType
index set type
Definition: filteredgridpart.hh:248
int level() const
Returns maxlevel of the grid.
Definition: filteredgridpart.hh:349
FilterType & filter()
return reference to filter
Definition: filteredgridpart.hh:401
Codim< codim >::template Partition< pitype >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:325
Codim< codim >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: filteredgridpart.hh:318
AddGridViewType::GridViewType GridViewType
Definition: filteredgridpart.hh:258
bool contains(const Entity &entity) const
Definition: filteredgridpart.hh:407
const FilterType & filter() const
return reference to filter
Definition: filteredgridpart.hh:395
FilteredGridPart(const FilteredGridPart &other)
copy constructor
Definition: filteredgridpart.hh:290
Codim< EntitySeed::codimension >::EntityType entity(const EntitySeed &seed) const
obtain entity pointer from entity seed
Definition: filteredgridpart.hh:389
FilteredGridPartTraits< HostGridPartImp, FilterImp, useFilteredIndexSet > Traits
traits class
Definition: filteredgridpart.hh:236
FilterImp FilterType
type of filter
Definition: filteredgridpart.hh:239
GridType & grid()
return reference to underlying grid
Definition: filteredgridpart.hh:304
Traits::HostGridPartType HostGridPartType
Definition: filteredgridpart.hh:242
void communicate(CommDataHandleIF< DataHandleImp, DataType > &dataHandle, InterfaceType iftype, CommunicationDirection dir) const
corresponding communication method for this grid part
Definition: filteredgridpart.hh:378
IntersectionIteratorType iend(const EntityType &entity) const
iend of corresponding intersection iterator for given entity
Definition: filteredgridpart.hh:362
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:424
IntersectionIteratorType::Intersection IntersectionType
intersection type
Definition: filteredgridpart.hh:254
const HostGridPartType & hostGridPart() const
Definition: filteredgridpart.hh:417
Definition: gridpart/filteredgridpart/datahandle.hh:31
Definition: filteredgridpart/intersection.hh:21
Definition: filteredgridpart/intersectioniterator.hh:24
Definition: filteredgridpart/iterator.hh:21
Definition: filteredgridpart.hh:42
AdaptiveLeafIndexSet< FilteredGP > IndexSetType
Definition: filteredgridpart.hh:43
static const IndexSetType & indexSet(const FilteredGP &gridPart, const std::unique_ptr< IndexSetPtr > &idxSetPtr)
Definition: filteredgridpart.hh:52
static IndexSetType * create(const FilteredGP &gridPart)
Definition: filteredgridpart.hh:45
static const IndexSetType & indexSet(const FilteredGP &gridPart, const std::unique_ptr< IndexSetPtr > &)
Definition: filteredgridpart.hh:77
static IndexSetType * create(const FilteredGP &gridPart)
Definition: filteredgridpart.hh:70
HostGP::IndexSetType IndexSetType
Definition: filteredgridpart.hh:68
Definition: filteredgridpart.hh:89
EntityGridTypeGetter< Entity >::Type Type
Definition: filteredgridpart.hh:100
Definition: filteredgridpart.hh:110
HostGridPartImp HostGridPartType
grid part imp
Definition: filteredgridpart.hh:142
FilterType::EntityType EntityType
type of entity
Definition: filteredgridpart.hh:154
HostGridPartType::Traits::IntersectionIteratorType HostIntersectionIteratorType
of host grid part intersection iterator type
Definition: filteredgridpart.hh:163
GridPartFamily::Intersection IntersectionType
type of intersection
Definition: filteredgridpart.hh:169
IndexSetSelectorType::IndexSetType IndexSetType
index set use in this gridpart
Definition: filteredgridpart.hh:160
FilteredGridPartIndexSetSelector< GridPartType, HostGridPartType, useFilteredIndexSet > IndexSetSelectorType
index set use in this gridpart
Definition: filteredgridpart.hh:157
FilteredGridPart< HostGridPartImp, FilterImp, useFilteredIndexSet > GridPartType
type of grid part
Definition: filteredgridpart.hh:112
static const bool conforming
is true if grid on this view only has conforming intersections
Definition: filteredgridpart.hh:198
MetaTwistUtility< typename HostGridPartType ::TwistUtilityType > TwistUtilityType
The type of the corresponding TwistUtility.
Definition: filteredgridpart.hh:148
static const InterfaceType indexSetInterfaceType
Definition: filteredgridpart.hh:195
static const PartitionIteratorType indexSetPartitionType
maximum partition type, the index set provides indices for
Definition: filteredgridpart.hh:193
HostGridPartType::CollectiveCommunicationType CollectiveCommunicationType
Definition: filteredgridpart.hh:190
HostGridPartType::GridType GridType
type of grid
Definition: filteredgridpart.hh:145
GridPartFamily::IntersectionIterator IntersectionIteratorType
type of intersection iterator
Definition: filteredgridpart.hh:166
FilterImp FilterType
export filter type
Definition: filteredgridpart.hh:151
Definition: filteredgridpart.hh:115
Dune::Intersection< const GridPartFamily, IntersectionImpl > Intersection
Definition: filteredgridpart.hh:128
HostGridPart::ctype ctype
Definition: filteredgridpart.hh:122
HostGridPartImp HostGridPart
Definition: filteredgridpart.hh:117
static const int dimension
Definition: filteredgridpart.hh:119
FilterImp Filter
Definition: filteredgridpart.hh:116
FilteredGridPartIntersectionIterator< const GridPartFamily > IntersectionIteratorImpl
Definition: filteredgridpart.hh:124
FilteredGridPartIntersection< Filter, typename HostGridPart::IntersectionType > IntersectionImpl
Definition: filteredgridpart.hh:125
static const int dimensionworld
Definition: filteredgridpart.hh:120
Dune::IntersectionIterator< const GridPartFamily, IntersectionIteratorImpl, IntersectionImpl > IntersectionIterator
Definition: filteredgridpart.hh:127
HostGridPart::template Codim< codim >::LocalGeometryType LocalGeometry
Definition: filteredgridpart.hh:134
HostGridPart::template Codim< codim >::GeometryType Geometry
Definition: filteredgridpart.hh:133
HostGridPart::template Codim< codim >::EntitySeedType EntitySeed
Definition: filteredgridpart.hh:137
HostGridPart::template Codim< codim >::EntityType Entity
Definition: filteredgridpart.hh:136
struct providing types of the iterators on codimension cd
Definition: filteredgridpart.hh:174
HostGridPartType::template Codim< codim >::EntitySeedType EntitySeedType
Definition: filteredgridpart.hh:179
HostGridPartType::template Codim< codim >::EntityType EntityType
Definition: filteredgridpart.hh:178
HostGridPartType::template Codim< codim >::GeometryType GeometryType
Definition: filteredgridpart.hh:175
Partition< InteriorBorder_Partition >::IteratorType IteratorType
Definition: filteredgridpart.hh:187
HostGridPartType::template Codim< codim >::LocalGeometryType LocalGeometryType
Definition: filteredgridpart.hh:176
Definition: filteredgridpart.hh:183
Dune::EntityIterator< codim, typename EntityGridTypeGetter< EntityType >::Type, FilteredGridPartIterator< codim, pitype, GridPartType > > IteratorType
Definition: filteredgridpart.hh:184
grid part typedefs, use those of traits
Definition: filteredgridpart.hh:263