dune-fem  2.6-git
adaptiveleafgridpart.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_ADAPTIVELEAFGRIDPART_HH
2 #define DUNE_FEM_ADAPTIVELEAFGRIDPART_HH
3 
4 //- dune-grid includes
5 #include <dune/grid/common/gridview.hh>
6 
7 //- dune-fem includes
14 
15 namespace Dune
16 {
17 
18  namespace Fem
19  {
20 
21  /*- see dune/grid/common/gridenums.hh
22  enum InterfaceType {
23  InteriorBorder_InteriorBorder_Interface=0, //!< send/receive interior and border entities
24  InteriorBorder_All_Interface=1, //!< send interior and border, receive all entities
25  Overlap_OverlapFront_Interface=2, //!< send overlap, receive overlap and front entities
26  Overlap_All_Interface=3, //!< send overlap, receive all entities
27  All_All_Interface=4 //!< send all and receive all entities
28  };
29  enum PartitionIteratorType {
30  Interior_Partition=0, //!< only interior entities
31  InteriorBorder_Partition=1, //!< interior and border entities
32  Overlap_Partition=2, //!< only overlap entities
33  OverlapFront_Partition=3, //!< overlap and front entities
34  All_Partition=4, //!< all entities
35  Ghost_Partition=5 //!< only ghost entities
36  };
37  */
38 
39  template <PartitionIteratorType ittype>
41  {
42  static const InterfaceType value = InteriorBorder_All_Interface;
43  };
44  template <>
45  struct IteratorToInterface< InteriorBorder_Partition >
46  {
47  static const InterfaceType value = InteriorBorder_InteriorBorder_Interface;
48  };
49 
51  //
52  // --AdaptiveLeafIndexGridPart
53  //
55 
63  template< class TraitsImp >
65  : public GridPartDefault< TraitsImp >
66  {
69 
70  public:
72  typedef TraitsImp Traits;
73 
75  typedef typename Traits :: GridPartType GridPartType;
77  typedef typename Traits :: GridType GridType;
79  typedef typename Traits :: IndexSetType IndexSetType;
80 
82  template< int codim >
83  struct Codim
84  : public BaseType :: template Codim< codim >
85  {};
86 
87  private:
88  typedef typename GridType::LeafGridView LeafGridView;
89 
90  public:
93 
95  typedef typename IntersectionIteratorType::Intersection IntersectionType;
96 
97  protected:
98  struct Key
99  {
102 
103  bool operator ==( const Key& other ) const
104  {
105  // compare grid pointers
106  return (&grid_) == (& other.grid_ );
107  }
108 
109  operator std::unique_ptr< GridPartType > () const
110  {
111  return std::unique_ptr< GridPartType > (new GridPartType(grid_, this) );
112  }
113  };
114  typedef Key KeyType;
115 
117 
118  // type of entity with codimension zero
119  typedef typename Codim< 0 > :: EntityType ElementType;
120 
121  // the leaf grid view
122  LeafGridView leafGridView_ ;
123 
124  // reference to index set
126 
127  using BaseType::grid_;
128 
129  public:
132  : BaseType( grid ),
133  leafGridView_( grid.leafGridView() ),
134  indexSet_( &IndexSetProviderType::getObject( KeyType( grid ) ) )
135  {}
136 
139  : BaseType( other ),
140  leafGridView_( other.leafGridView_ ),
141  indexSet_( &IndexSetProviderType::getObject( KeyType( other.grid_ ) ) )
142  {}
143 
144  protected:
147  : BaseType( grid ),
148  leafGridView_( grid.leafGridView() ),
149  indexSet_( nullptr )
150  {}
151 
152  public:
156  {
157  if( indexSet_ )
158  {
160  indexSet_ = nullptr;
161  }
162  }
163 
164  using BaseType::grid;
165 
167  const IndexSetType &indexSet () const
168  {
169  assert( indexSet_ );
170  return *indexSet_;
171  }
172 
174  template< int codim >
175  typename Codim< codim > :: IteratorType
176  begin () const
177  {
178  return begin< codim, InteriorBorder_Partition >();
179  }
180 
182  template< int codim, PartitionIteratorType pitype >
183  typename Codim< codim > :: template Partition< pitype > :: IteratorType
184  begin () const
185  {
186  return leafGridView_.template begin< codim, pitype >();
187  }
188 
190  template< int codim >
191  typename Codim< codim > :: IteratorType
192  end () const
193  {
194  return end< codim, InteriorBorder_Partition >();
195  }
196 
198  template< int codim, PartitionIteratorType pitype >
199  typename Codim< codim > :: template Partition< pitype > :: IteratorType
200  end () const
201  {
202  return leafGridView_.template end< codim, pitype >();
203  }
204 
207  ibegin ( const ElementType &entity ) const
208  {
209  return leafGridView_.ibegin( entity );
210  }
211 
214  iend ( const ElementType &entity ) const
215  {
216  return leafGridView_.iend( entity );
217  }
218 
220  int level () const
221  {
222  return grid().maxLevel();
223  }
224 
226  template< class DataHandle, class Data >
227  decltype( auto ) communicate ( CommDataHandleIF< DataHandle, Data > &data, InterfaceType iftype, CommunicationDirection dir ) const
228  {
229  return leafGridView_.communicate( data, iftype, dir );
230  }
231 
232  protected:
233  const GridPartType& asImp() const
234  {
235  return static_cast<const GridPartType &> (*this);
236  }
237 
239  {
240  return static_cast<GridPartType &> (*this);
241  }
242  };
243 
251  template< class Grid, PartitionIteratorType idxpitype = All_Partition, bool onlyCodimensionZero = false >
252  class AdaptiveLeafGridPart;
253 
255  template< class Grid, PartitionIteratorType idxpitype , bool onlyCodimensionZero >
257  {
258  public:
260  typedef Grid GridType;
261 
264 
267 
268  typedef typename GridType::CollectiveCommunication CollectiveCommunicationType;
269 
270  protected:
271  // choose the AdaptiveIndexSet (based on the HierarchicIndexSet)
272  // to be revised
273  template < int dummy, bool onlyCodimZero >
275  {
276  static const PartitionIteratorType indexSetPartitionType = idxpitype;
279  };
280 
281  template <int dummy>
282  struct AdaptiveLeafIndexSetChooser<dummy, true >
283  {
284  static const PartitionIteratorType indexSetPartitionType = idxpitype;
287  };
288 
289  // also for Cartesian grids (e.g. YaspGrid) use adaptive leaf index set in parallel
290  typedef AdaptiveLeafIndexSetChooser<-1, onlyCodimensionZero > IndexSetChooserType;
291 
292  public:
295 
298 
299  // type of intersection iterator
300  typedef typename GridType::LeafGridView::IntersectionIterator IntersectionIteratorType;
301 
302  template< int codim >
303  struct Codim
304  {
305  typedef typename GridType::template Codim< codim >::Geometry GeometryType;
306  typedef typename GridType::template Codim< codim >::LocalGeometry LocalGeometryType;
307 
308  typedef typename GridType::template Codim< codim >::Entity EntityType;
309  typedef typename GridType::template Codim< codim >::EntitySeed EntitySeedType;
310 
311  template< PartitionIteratorType pitype >
312  struct Partition
313  {
315  };
316  };
317 
319  static const bool conforming = Dune::Capabilities::isLeafwiseConforming< GridType > :: v;
320  };
321 
322  template< class Grid, PartitionIteratorType idxpitype , bool onlyCodimensionZero >
324  : public AdaptiveGridPartBase< AdaptiveLeafGridPartTraits< Grid, idxpitype, onlyCodimensionZero > >
325  {
327  typedef typename BaseType :: KeyType KeyType;
328  public:
329  typedef typename BaseType :: GridType GridType;
332  : BaseType( grid )
333  {
334  }
335 
337  AdaptiveLeafGridPart ( GridType& grid, const KeyType* dummy )
338  : BaseType( grid, dummy )
339  {
340  }
341 
343  AdaptiveLeafGridPart ( const AdaptiveLeafGridPart& other ) = default;
344  };
345 
353  template< class Grid, PartitionIteratorType idxpitype = All_Partition >
355 
356 
357  template< class Grid, PartitionIteratorType idxpitype = All_Partition >
359 
367  template< class Grid, PartitionIteratorType idxpitype >
369  {
370  public:
373 
376  };
377 
385  template< class Grid, PartitionIteratorType idxpitype >
387  : public AdaptiveGridPartBase< IntersectionAdaptiveLeafGridPartTraits< Grid, idxpitype > >
388  {
390  typedef typename BaseType :: KeyType KeyType;
391  public:
392  typedef typename BaseType :: GridType GridType;
395  : BaseType( grid )
396  {
397  }
398 
400  IntersectionAdaptiveLeafGridPart ( GridType& grid, const KeyType* dummy )
401  : BaseType( grid, dummy )
402  {
403  }
404 
407  };
408 
409 
410 
411  // Capabilities
412  // ------------
413 
414  namespace GridPartCapabilities
415  {
416 
417  // Capabilities for AdaptiveLeafGridPart
418  // -------------------------------------
419 
420  template< class Grid, PartitionIteratorType idxpitype, bool onlyCodimensionZero >
421  struct hasGrid< AdaptiveLeafGridPart< Grid, idxpitype, onlyCodimensionZero > >
422  {
423  static const bool v = true;
424  };
425 
426  template< class Grid, PartitionIteratorType idxpitype, bool onlyCodimensionZero >
427  struct hasSingleGeometryType< AdaptiveLeafGridPart< Grid, idxpitype, onlyCodimensionZero > >
428  {
429  static const bool v = Dune::Capabilities::hasSingleGeometryType< Grid >::v;
430  static const unsigned int topologyId
431  = Dune::Capabilities::hasSingleGeometryType< Grid >::topologyId;
432  };
433 
434  template< class Grid, PartitionIteratorType idxpitype, bool onlyCodimensionZero >
435  struct isCartesian< AdaptiveLeafGridPart< Grid, idxpitype, onlyCodimensionZero > >
436  {
437  static const bool v = Dune::Capabilities::isCartesian< Grid >::v;
438  };
439 
440  template< class Grid, PartitionIteratorType idxpitype, bool onlyCodimensionZero, int codim >
441  struct hasEntity< AdaptiveLeafGridPart< Grid, idxpitype, onlyCodimensionZero >, codim >
442  {
443  static const bool v = Dune::Capabilities::hasEntity< Grid, codim >::v;
444  };
445 
446  template< class Grid, PartitionIteratorType idxpitype, bool onlyCodimensionZero, int codim >
447  struct canCommunicate< AdaptiveLeafGridPart< Grid, idxpitype, onlyCodimensionZero >, codim >
448  {
449  static const bool v = Dune::Capabilities::canCommunicate< Grid, codim >::v;
450  };
451 
452  template< class Grid, PartitionIteratorType idxpitype, bool onlyCodimensionZero >
453  struct isConforming< AdaptiveLeafGridPart< Grid, idxpitype, onlyCodimensionZero > >
454  {
455  static const bool v = Dune::Capabilities::isLeafwiseConforming< Grid >::v;
456  };
457 
458 
459  // Capabilities for DGAdaptiveLeafGridPart
460  // ---------------------------------------
461 
462  template< class Grid, PartitionIteratorType idxpitype >
463  struct hasGrid< DGAdaptiveLeafGridPart< Grid, idxpitype > >
464  {
465  static const bool v = true;
466  };
467 
468  template< class Grid, PartitionIteratorType idxpitype >
469  struct hasSingleGeometryType< DGAdaptiveLeafGridPart< Grid, idxpitype > >
470  {
471  static const bool v = Dune::Capabilities::hasSingleGeometryType< Grid >::v;
472  static const unsigned int topologyId
473  = Dune::Capabilities::hasSingleGeometryType< Grid >::topologyId;
474  };
475 
476  template< class Grid, PartitionIteratorType idxpitype >
477  struct isCartesian< DGAdaptiveLeafGridPart< Grid, idxpitype > >
478  {
479  static const bool v = Dune::Capabilities::isCartesian< Grid >::v;
480  };
481 
482  template< class Grid, PartitionIteratorType idxpitype, int codim >
483  struct hasEntity< DGAdaptiveLeafGridPart< Grid, idxpitype >, codim >
484  {
485  static const bool v = Dune::Capabilities::hasEntity< Grid, codim >::v;
486  };
487 
488  template< class Grid, PartitionIteratorType idxpitype, int codim >
489  struct canCommunicate< DGAdaptiveLeafGridPart< Grid, idxpitype >, codim >
490  {
491  static const bool v = Dune::Capabilities::canCommunicate< Grid, codim >::v;
492  };
493 
494  template< class Grid, PartitionIteratorType idxpitype >
495  struct isConforming< DGAdaptiveLeafGridPart< Grid, idxpitype > >
496  {
497  static const bool v = Dune::Capabilities::isLeafwiseConforming< Grid >::v;
498  };
499 
500 
501  // Capbilities for IntersectionAdaptiveLeafGridPart
502  // ------------------------------------------------
503 
504  template< class Grid, PartitionIteratorType idxpitype >
505  struct hasGrid< IntersectionAdaptiveLeafGridPart< Grid, idxpitype > >
506  {
507  static const bool v = true;
508  };
509 
510  template< class Grid, PartitionIteratorType idxpitype >
512  {
513  static const bool v = Dune::Capabilities::hasSingleGeometryType< Grid >::v;
514  static const unsigned int topologyId
515  = Dune::Capabilities::hasSingleGeometryType< Grid >::topologyId;
516  };
517 
518  template< class Grid, PartitionIteratorType idxpitype >
519  struct isCartesian< IntersectionAdaptiveLeafGridPart< Grid, idxpitype > >
520  {
521  static const bool v = Dune::Capabilities::isCartesian< Grid >::v;
522  };
523 
524  template< class Grid, PartitionIteratorType idxpitype, int codim >
525  struct hasEntity< IntersectionAdaptiveLeafGridPart< Grid, idxpitype >, codim >
526  {
527  static const bool v = Dune::Capabilities::hasEntity< Grid, codim >::v;
528  };
529 
530  template< class Grid, PartitionIteratorType idxpitype, int codim >
531  struct canCommunicate< IntersectionAdaptiveLeafGridPart< Grid, idxpitype >, codim >
532  {
533  static const bool v = Dune::Capabilities::canCommunicate< Grid, codim >::v;
534  };
535 
536  template< class Grid, PartitionIteratorType idxpitype >
537  struct isConforming< IntersectionAdaptiveLeafGridPart< Grid, idxpitype > >
538  {
539  static const bool v = Dune::Capabilities::isLeafwiseConforming< Grid >::v;
540  };
541 
542  } // namespace GridPartCapabilities
543 
544  } // namespace Fem
545 
546 } // namespace Dune
547 
548 #endif // #ifndef DUNE_FEM_ADAPTIVELEAFGRIDPART_HH
Definition: bindguard.hh:11
Definition: adaptiveleafgridpart.hh:41
static const InterfaceType value
Definition: adaptiveleafgridpart.hh:42
A grid part with an index set specially designed for adaptive calculations.
Definition: adaptiveleafgridpart.hh:66
Traits ::GridType GridType
Grid implementation type.
Definition: adaptiveleafgridpart.hh:77
IntersectionIteratorType iend(const ElementType &entity) const
iend of corresponding intersection iterator for given entity
Definition: adaptiveleafgridpart.hh:214
IntersectionIteratorType ibegin(const ElementType &entity) const
ibegin of corresponding intersection iterator for given entity
Definition: adaptiveleafgridpart.hh:207
int level() const
Returns maxlevel of the grid.
Definition: adaptiveleafgridpart.hh:220
SingletonList< KeyType, IndexSetType > IndexSetProviderType
Definition: adaptiveleafgridpart.hh:116
AdaptiveGridPartBase(GridType &grid, const KeyType *)
Constructor constructing object held by index set (for iterator access)
Definition: adaptiveleafgridpart.hh:146
GridPartType & asImp()
Definition: adaptiveleafgridpart.hh:238
LeafGridView leafGridView_
Definition: adaptiveleafgridpart.hh:122
Codim< codim >::IteratorType end() const
Begin iterator on the leaf level.
Definition: adaptiveleafgridpart.hh:192
Traits ::IndexSetType IndexSetType
The leaf index set of the grid implementation.
Definition: adaptiveleafgridpart.hh:79
Codim< codim >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: adaptiveleafgridpart.hh:176
Codim< codim >::template Partition< pitype >::IteratorType begin() const
Begin iterator on the leaf level.
Definition: adaptiveleafgridpart.hh:184
Key KeyType
Definition: adaptiveleafgridpart.hh:114
const IndexSetType & indexSet() const
Returns reference to index set of the underlying grid.
Definition: adaptiveleafgridpart.hh:167
TraitsImp Traits
Type definitions.
Definition: adaptiveleafgridpart.hh:72
Codim< codim >::template Partition< pitype >::IteratorType end() const
End iterator on the leaf level.
Definition: adaptiveleafgridpart.hh:200
Traits ::GridPartType GridPartType
Grid implementation type.
Definition: adaptiveleafgridpart.hh:75
const GridPartType & asImp() const
Definition: adaptiveleafgridpart.hh:233
~AdaptiveGridPartBase()
Destructor removing index set, if only one reference left, index set removed.
Definition: adaptiveleafgridpart.hh:155
Codim< 0 >::EntityType ElementType
Definition: adaptiveleafgridpart.hh:119
AdaptiveGridPartBase(const ThisType &other)
Copy Constructor.
Definition: adaptiveleafgridpart.hh:138
AdaptiveGridPartBase(GridType &grid)
constructor
Definition: adaptiveleafgridpart.hh:131
IntersectionIteratorType::Intersection IntersectionType
type of intersection
Definition: adaptiveleafgridpart.hh:95
Traits::IntersectionIteratorType IntersectionIteratorType
type of intersection iterator
Definition: adaptiveleafgridpart.hh:92
const IndexSetType * indexSet_
Definition: adaptiveleafgridpart.hh:125
Struct providing types of the leaf iterators on codimension codim.
Definition: adaptiveleafgridpart.hh:85
Definition: adaptiveleafgridpart.hh:99
GridType & grid_
Definition: adaptiveleafgridpart.hh:100
Key(GridType &grid)
Definition: adaptiveleafgridpart.hh:101
bool operator==(const Key &other) const
Definition: adaptiveleafgridpart.hh:103
Definition: adaptiveleafgridpart.hh:325
AdaptiveLeafGridPart(GridType &grid)
Constructor.
Definition: adaptiveleafgridpart.hh:331
AdaptiveLeafGridPart(const AdaptiveLeafGridPart &other)=default
copy constructor
BaseType ::GridType GridType
Definition: adaptiveleafgridpart.hh:329
AdaptiveLeafGridPart(GridType &grid, const KeyType *dummy)
copy constructor (for construction from KeyType, no public use)
Definition: adaptiveleafgridpart.hh:337
Type definitions for the LeafGridPart class.
Definition: adaptiveleafgridpart.hh:257
AdaptiveLeafGridPart< GridType, idxpitype, onlyCodimensionZero > GridPartType
type of the grid part , i.e. this type
Definition: adaptiveleafgridpart.hh:263
Grid GridType
type of the grid
Definition: adaptiveleafgridpart.hh:260
static const bool conforming
is true if grid on this view only has conforming intersections
Definition: adaptiveleafgridpart.hh:319
IndexSetChooserType::IndexSetType IndexSetType
type of the index set
Definition: adaptiveleafgridpart.hh:294
AdaptiveLeafIndexSetChooser<-1, onlyCodimensionZero > IndexSetChooserType
Definition: adaptiveleafgridpart.hh:290
GridType::CollectiveCommunication CollectiveCommunicationType
Definition: adaptiveleafgridpart.hh:268
static const InterfaceType indexSetInterfaceType
Definition: adaptiveleafgridpart.hh:297
GridType::LeafGridView::IntersectionIterator IntersectionIteratorType
Definition: adaptiveleafgridpart.hh:300
static const PartitionIteratorType indexSetPartitionType
Definition: adaptiveleafgridpart.hh:296
TwistUtility< GridType > TwistUtilityType
The type of the corresponding TwistUtility.
Definition: adaptiveleafgridpart.hh:266
AdaptiveLeafIndexSet< GridPartType > IndexSetType
Definition: adaptiveleafgridpart.hh:278
static const PartitionIteratorType indexSetPartitionType
Definition: adaptiveleafgridpart.hh:276
static const InterfaceType indexSetInterfaceType
Definition: adaptiveleafgridpart.hh:277
DGAdaptiveLeafIndexSet< GridPartType > IndexSetType
Definition: adaptiveleafgridpart.hh:286
Definition: adaptiveleafgridpart.hh:304
GridType::template Codim< codim >::Entity EntityType
Definition: adaptiveleafgridpart.hh:308
GridType::template Codim< codim >::Geometry GeometryType
Definition: adaptiveleafgridpart.hh:305
GridType::template Codim< codim >::EntitySeed EntitySeedType
Definition: adaptiveleafgridpart.hh:309
GridType::template Codim< codim >::LocalGeometry LocalGeometryType
Definition: adaptiveleafgridpart.hh:306
Definition: adaptiveleafgridpart.hh:313
GridType::template Codim< codim >::template Partition< pitype >::LeafIterator IteratorType
Definition: adaptiveleafgridpart.hh:314
A grid part with an index set specially designed for adaptive calculations including indices for inte...
Definition: adaptiveleafgridpart.hh:388
IntersectionAdaptiveLeafGridPart(const IntersectionAdaptiveLeafGridPart &other)=default
copy constructor
BaseType ::GridType GridType
Definition: adaptiveleafgridpart.hh:392
IntersectionAdaptiveLeafGridPart(GridType &grid)
Constructor.
Definition: adaptiveleafgridpart.hh:394
IntersectionAdaptiveLeafGridPart(GridType &grid, const KeyType *dummy)
copy constructor (for construction from KeyType, no public use)
Definition: adaptiveleafgridpart.hh:400
A grid part with an index set specially designed for adaptive calculations including indices for inte...
Definition: adaptiveleafgridpart.hh:369
IntersectionAdaptiveLeafGridPart< Grid, idxpitype > GridPartType
type of the grid part , i.e. this type
Definition: adaptiveleafgridpart.hh:372
IntersectionAdaptiveLeafIndexSet< GridPartType > IndexSetType
type of the index set
Definition: adaptiveleafgridpart.hh:375
consecutive, persistent index set for the leaf level based on the grid's hierarchy index set
Definition: adaptiveleafindexset.hh:1336
Definition: adaptiveleafindexset.hh:1407
consecutive, persistent index set for the leaf level based on the grid's hierarchy index set
Definition: adaptiveleafindexset.hh:1477
specialize with 'false' if grid part has no underlying dune grid (default=true)
Definition: gridpart/common/capabilities.hh:18
static const bool v
Definition: gridpart/common/capabilities.hh:19
specialize with 'true' for if the codimension 0 entity of the grid part has only one possible geometr...
Definition: gridpart/common/capabilities.hh:29
static const bool v
Definition: gridpart/common/capabilities.hh:30
static const unsigned int topologyId
Definition: gridpart/common/capabilities.hh:31
specialize with 'true' if the grid part is cartesian (default=false)
Definition: gridpart/common/capabilities.hh:40
static const bool v
Definition: gridpart/common/capabilities.hh:41
specialize with 'true' for all codims that a grid implements entities for (default=false)
Definition: gridpart/common/capabilities.hh:50
static const bool v
Definition: gridpart/common/capabilities.hh:51
specialize with 'true' for all codims that a grid can communicate data on (default=false)
Definition: gridpart/common/capabilities.hh:60
static const bool v
Definition: gridpart/common/capabilities.hh:61
specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: gridpart/common/capabilities.hh:70
static const bool v
Definition: gridpart/common/capabilities.hh:71
void communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir) const
corresponding communication method for grid part
Definition: gridpart.hh:247
Default implementation for the GridPart classes.
Definition: gridpart.hh:299
GridType & grid_
Definition: gridpart.hh:326
Traits::template Codim< EntitySeed::codimension >::EntityType entity(const EntitySeed &seed) const
Definition: gridpart.hh:362
const GridType & grid() const
Returns const reference to the underlying grid.
Definition: gridpart.hh:342
Utility to get twist from IntersectionIterator, if provided by grid (i.e. AlbertaGrid,...
Definition: twistutility.hh:82
Singleton list for key/object pairs.
Definition: singletonlist.hh:54
static void removeObject(const ObjectType &object)
Definition: singletonlist.hh:119