1 #ifndef DUNE_PDELAB_COMMON_PARTITIONVIEWENTITYSET_HH
2 #define DUNE_PDELAB_COMMON_PARTITIONVIEWENTITYSET_HH
10 #include <type_traits>
12 #include <dune/common/version.hh>
13 #include <dune/common/iteratorrange.hh>
14 #include <dune/geometry/referenceelements.hh>
15 #include <dune/geometry/typeindex.hh>
16 #include <dune/grid/common/capabilities.hh>
17 #include <dune/grid/common/partitionset.hh>
18 #include <dune/grid/common/rangegenerators.hh>
30 using Dune::descendantElements;
31 using Dune::intersections;
33 template<
typename GV,
typename P>
34 class PartitionViewEntitySet;
36 template<
typename GV,
typename P>
37 class PartitionViewEntitySetIndexSet;
39 template<
typename GV,
typename P>
45 using Grid =
typename GV::Traits::Grid;
62 using Index =
typename BaseIndexSet::IndexType;
64 using Types = IteratorRange<std::vector<GeometryType>::const_iterator>;
72 return ~static_cast<Index>(0ull);
81 template<dim_type codim>
93 template<PartitionIteratorType pitype>
118 template<
typename GV,
typename P>
146 template<dim_type codim>
176 template<dim_type codim>
177 typename Codim<codim>::Iterator
180 return gridView().template begin<codim,Partitions::partitionIterator()>();
183 template<dim_type codim>
184 typename Codim<codim>::Iterator
187 return gridView().template end<codim,Partitions::partitionIterator()>();
190 template<dim_type codim, PartitionIteratorType pitype>
191 typename GV::template Codim<codim>::template Partition<pitype>::Iterator
194 return gridView().template begin<codim,pitype>();
197 template<dim_type codim, PartitionIteratorType pitype>
198 typename GV::template Codim<codim>::template Partition<pitype>::Iterator
201 return gridView().template end<codim,pitype>();
214 template<
typename Entity>
248 return Partitions::contains(Dune::Partitions::overlap) ?
gridView().overlapSize(codim) : 0;
254 return Partitions::contains(Dune::Partitions::ghost) ?
gridView().ghostSize(codim) : 0;
257 template<
typename DataHandle>
258 void communicate(DataHandle& data, InterfaceType iftype, CommunicationDirection dir)
const
260 gridView().communicate(data,iftype,dir);
270 : _index_set(std::make_shared<
IndexSet>(gv,supported_codims,true))
274 : _index_set(std::make_shared<
IndexSet>(gv,
CodimMask(initialize ? ~0ull : 0ull),initialize))
286 _index_set->addCodim(codim);
292 _index_set->removeCodim(codim);
298 return _index_set->needsUpdate();
312 return _index_set->update(force);
324 return _index_set == other._index_set;
329 return not (*
this == other);
334 std::shared_ptr<IndexSet> _index_set;
338 template<
typename GV,
typename P>
342 template<
typename,
typename>
366 template<dim_type codim>
382 _geometry_types.resize(0);
383 for (
dim_type codim = 0; codim <= GV::dimension; ++codim)
391 _geometry_types.push_back(gt);
395 for (
dim_type codim = 0; codim <= GV::dimension; ++codim)
397 auto range = std::equal_range(
398 _geometry_types.begin(),
399 _geometry_types.end(),
400 GeometryTypes::none(GV::dimension - codim),
401 [](
const GeometryType& x,
const GeometryType& y)
404 return y.dim() < x.dim();
406 _per_codim_geometry_types[codim] = {range.first,range.second};
427 auto dim = GV::dimension;
432 template<
typename Entity>
435 return Partitions::contains(
e.partitionType()) ?
baseIndexSet().contains(
e) :
false;
450 return _gv.indexSet();
456 return _per_codim_geometry_types[codim];
462 return {_geometry_types.begin(),_geometry_types.end()};
511 std::vector<GeometryType> _geometry_types;
512 std::array<Types,GV::dimension + 1> _per_codim_geometry_types;
516 template<
typename GV,
typename P>
523 template<
typename,
typename>
544 static constexpr
bool hasAllEntityIterators(Dune::Dim<Grid::dimension + 1>)
549 template<dim_type dim = 0>
550 static constexpr
bool hasAllEntityIterators(Dune::Dim<dim> = {})
552 return Capabilities::hasEntityIterator<Grid,dim>::v && hasAllEntityIterators(Dune::Dim<dim+1>{});
555 bool update(
bool force)
560 _mapped_gt_offsets[0] = 0;
561 update_codims(std::integral_constant<
bool,hasAllEntityIterators()>{});
562 std::partial_sum(_mapped_gt_offsets.begin(),_mapped_gt_offsets.end(),_mapped_gt_offsets.begin());
566 void update_codims(std::true_type)
568 update_codim(Dune::Codim<0>{});
571 void update_codim(Dune::Codim<GV::dimension+1>)
574 template<dim_type cd>
575 void update_codim(Dune::Codim<cd> codim)
577 if (_active_codims.test(codim))
578 for (
const auto&
e : entities(
gridView(),codim,Dune::Partitions::all))
582 if (Partitions::contains(
e.partitionType()))
583 _indices[_gt_offsets[gt_index] +
baseIndexSet().index(
e)] = _mapped_gt_offsets[gt_index + 1]++;
585 update_codim(Dune::Codim<cd+1>{});
589 void update_codims(std::false_type)
591 std::fill(_indices.begin(),_indices.end(),
invalidIndex());
595 for (
const auto&
e : elements(
gridView(),Dune::Partitions::all))
597 if (!Partitions::contains(
e.partitionType()))
600 auto ref_el = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(
e.type());
601 for (
dim_type codim = 0; codim <= Grid::dimension; ++codim)
603 if (!_active_codims.test(codim))
606 size_type sub_entity_count = ref_el.size(codim);
608 for(
size_type i = 0; i < sub_entity_count; ++i)
610 auto gt = ref_el.type(i,codim);
612 auto index = index_set.subIndex(
e,i,codim);
614 _indices[_gt_offsets[gt_index] +
index] = _mapped_gt_offsets[gt_index + 1]++;
627 assert(Partitions::contains(
e.partitionType()));
630 return _indices[_gt_offsets[gt_index] +
baseIndexSet().index(
e)];
637 assert(Partitions::contains(
e.partitionType()));
638 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(
e.type()).type(i,codim);
641 return _indices[_gt_offsets[gt_index] +
baseIndexSet().subIndex(
e,i,codim)];
649 assert(Partitions::contains(
e.partitionType()));
652 return _indices[_gt_offsets[gt_index] +
baseIndexSet().index(
e)] + _mapped_gt_offsets[gt_index];
659 assert(Partitions::contains(
e.partitionType()));
660 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(
e.type()).type(i,codim);
663 return _indices[_gt_offsets[gt_index] +
baseIndexSet().subIndex(
e,i,codim)] + _mapped_gt_offsets[gt_index];
668 :
Base(gv,wanted_codims)
680 std::vector<Index> _indices;
684 template<
typename GV>
691 template<
typename,
typename>
711 _mapped_gt_offsets[0] = 0;
714 std::partial_sum(_mapped_gt_offsets.begin(),_mapped_gt_offsets.end(),_mapped_gt_offsets.begin());
738 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(
e.type()).type(i,codim);
747 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(
e.type()).type(i,codim);
753 :
Base(gv,wanted_codims)
765 template<
typename GV>
768 template<
typename GV>
771 template<
typename GV>
781 using type = std::false_type;
784 template<
typename GV,
typename P>
787 using type = std::true_type;
static const int dim
Definition: adaptivity.hh:84
std::size_t index
Definition: interpolate.hh:97
const Entity & e
Definition: localfunctionspace.hh:123
const std::size_t offset
Definition: localfunctionspace.hh:75
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
@ conforming
Definition: pdelab/boilerplate/pdelab.hh:436
typename impl::_isEntitySet< T >::type isEntitySet
Type Trait to determine whether T is an EntitySet.
Definition: partitionviewentityset.hh:796
Partition view (or entity set) of a grid view.
Definition: partitionviewentityset.hh:120
PartitionViewEntitySet(const GridView &gv, CodimMask supported_codims)
Definition: partitionviewentityset.hh:269
static const dim_type dimension
Definition: partitionviewentityset.hh:143
void reset()
Reset this EntitySet, which removes all entities from it.
Definition: partitionviewentityset.hh:278
CoordinateField ctype
Definition: partitionviewentityset.hh:140
static const dim_type dimensionworld
Definition: partitionviewentityset.hh:144
bool contains(const GeometryType >) const
Definition: partitionviewentityset.hh:225
bool operator==(const PartitionViewEntitySet &other) const
Compare to another partition view.
Definition: partitionviewentityset.hh:323
const IndexSet & indexSet() const
Returns the IndexSet of this EntitySet.
Definition: partitionviewentityset.hh:165
const Grid & grid() const
Definition: partitionviewentityset.hh:159
bool update(bool force=false)
Update the internal state of this EntitySet.
Definition: partitionviewentityset.hh:310
constexpr static CodimMask allCodims()
Definition: partitionviewentityset.hh:154
IntersectionIterator iend(const typename Codim< 0 >::Entity &entity) const
Definition: partitionviewentityset.hh:235
typename Traits::CodimMask CodimMask
Definition: partitionviewentityset.hh:135
typename Traits::IntersectionIterator IntersectionIterator
Definition: partitionviewentityset.hh:133
Codim< codim >::Iterator end() const
Definition: partitionviewentityset.hh:185
typename Traits::CollectiveCommunication CollectiveCommunication
Definition: partitionviewentityset.hh:134
bool operator!=(const PartitionViewEntitySet &other) const
Compare to another partition view.
Definition: partitionviewentityset.hh:328
typename Traits::GridView GridView
Definition: partitionviewentityset.hh:128
size_type size(dim_type codim) const
Definition: partitionviewentityset.hh:204
constexpr static Partitions partitions()
Definition: partitionviewentityset.hh:149
size_type size(const GeometryType >) const
Definition: partitionviewentityset.hh:209
bool contains(const Entity &e) const
Definition: partitionviewentityset.hh:215
typename Traits::Grid Grid
Definition: partitionviewentityset.hh:127
void removeCodim(dim_type codim)
Remove all entities of the given codim from this EntitySet.
Definition: partitionviewentityset.hh:290
bool contains(dim_type codim) const
Definition: partitionviewentityset.hh:220
typename Traits::IndexSet IndexSet
Definition: partitionviewentityset.hh:129
PartitionViewEntitySet(const GridView &gv, bool initialize=true)
Definition: partitionviewentityset.hh:273
typename Traits::Partitions Partitions
Definition: partitionviewentityset.hh:126
size_type overlapSize(dim_type codim) const
Returns the overlap size of this EntitySet, which depends on its PartitionSet.
Definition: partitionviewentityset.hh:246
Codim< codim >::Iterator begin() const
Definition: partitionviewentityset.hh:178
static const bool conforming
Definition: partitionviewentityset.hh:142
bool needsUpdate() const
Returns true if you need to call update on this EntitySet before using it.
Definition: partitionviewentityset.hh:296
GV::template Codim< codim >::template Partition< pitype >::Iterator end() const
Definition: partitionviewentityset.hh:199
const GridView & gridView() const
Returns the underlying GridView.
Definition: partitionviewentityset.hh:264
typename Traits::CoordinateField CoordinateField
Definition: partitionviewentityset.hh:136
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir) const
Definition: partitionviewentityset.hh:258
typename Traits::Intersection Intersection
Definition: partitionviewentityset.hh:132
const CollectiveCommunication & comm() const
Definition: partitionviewentityset.hh:240
void addCodim(dim_type codim)
Add all entities of the given codim to this EntitySet.
Definition: partitionviewentityset.hh:284
typename Traits::Element Element
Definition: partitionviewentityset.hh:131
GV::template Codim< codim >::template Partition< pitype >::Iterator begin() const
Definition: partitionviewentityset.hh:192
typename Traits::BaseIndexSet BaseIndexSet
Definition: partitionviewentityset.hh:130
typename Traits::template Codim< codim > Codim
Definition: partitionviewentityset.hh:147
const BaseIndexSet & baseIndexSet() const
Returns the IndexSet of the underlying GridView.
Definition: partitionviewentityset.hh:171
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:137
IntersectionIterator ibegin(const typename Codim< 0 >::Entity &entity) const
Definition: partitionviewentityset.hh:230
typename Traits::dim_type dim_type
Definition: partitionviewentityset.hh:138
size_type ghostSize(dim_type codim) const
Returns the ghost size of this EntitySet, which depends on its PartitionSet.
Definition: partitionviewentityset.hh:252
Definition: partitionviewentityset.hh:519
Index index(const E &e) const
Definition: partitionviewentityset.hh:624
typename Traits::dim_type dim_type
Definition: partitionviewentityset.hh:354
const GridView & gridView() const
Definition: partitionviewentityset.hh:471
constexpr static Index invalidIndex()
Definition: partitionviewentityset.hh:361
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:353
Index uniqueSubIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:656
bool needsUpdate() const
Definition: partitionviewentityset.hh:476
const BaseIndexSet & baseIndexSet() const
Definition: partitionviewentityset.hh:448
PartitionViewEntitySetIndexSet(const GV &gv, CodimMask wanted_codims, bool initialize)
Definition: partitionviewentityset.hh:667
Index subIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:634
Index uniqueIndex(const E &e) const
Definition: partitionviewentityset.hh:646
bool contains(dim_type codim) const
Definition: partitionviewentityset.hh:438
Definition: partitionviewentityset.hh:41
typename BaseIndexSet::IndexType Index
Definition: partitionviewentityset.hh:62
typename GV::Traits::Grid Grid
Definition: partitionviewentityset.hh:45
typename GV::template Codim< 0 >::Entity Element
Definition: partitionviewentityset.hh:51
int dim_type
Definition: partitionviewentityset.hh:60
PartitionViewEntitySetIndexSet< GV, Partitions > IndexSet
Definition: partitionviewentityset.hh:48
typename GV::Traits::IntersectionIterator IntersectionIterator
Definition: partitionviewentityset.hh:55
static const dim_type dimensionworld
Definition: partitionviewentityset.hh:79
IteratorRange< std::vector< GeometryType >::const_iterator > Types
Definition: partitionviewentityset.hh:64
GV GridView
Definition: partitionviewentityset.hh:46
static const bool conforming
Definition: partitionviewentityset.hh:75
std::size_t size_type
Definition: partitionviewentityset.hh:59
typename GV::Traits::Intersection Intersection
Definition: partitionviewentityset.hh:53
typename GV::Traits::CollectiveCommunication CollectiveCommunication
Definition: partitionviewentityset.hh:57
constexpr static Index invalidIndex()
Definition: partitionviewentityset.hh:70
typename std::decay< P >::type Partitions
Definition: partitionviewentityset.hh:43
static const dim_type dimension
Definition: partitionviewentityset.hh:77
std::bitset< GV::dimension+1 > CodimMask
Definition: partitionviewentityset.hh:66
typename GV::Traits::IndexSet BaseIndexSet
Definition: partitionviewentityset.hh:49
typename Grid::ctype CoordinateField
Definition: partitionviewentityset.hh:68
Definition: partitionviewentityset.hh:83
typename GV::template Codim< codim >::Entity Entity
Definition: partitionviewentityset.hh:87
typename GV::template Codim< codim >::Geometry Geometry
Definition: partitionviewentityset.hh:89
typename GV::template Codim< codim >::template Partition< Partitions::partitionIterator()>::Iterator Iterator
Definition: partitionviewentityset.hh:85
typename GV::template Codim< codim >::LocalGeometry LocalGeometry
Definition: partitionviewentityset.hh:91
Definition: partitionviewentityset.hh:95
typename GV::template Codim< codim >::template Partition< pitype >::Iterator Iterator
Definition: partitionviewentityset.hh:97
Definition: partitionviewentityset.hh:340
size_type size(GeometryType gt) const
Definition: partitionviewentityset.hh:417
bool contains(const GeometryType >) const
Definition: partitionviewentityset.hh:443
CodimMask _wanted_codims
Definition: partitionviewentityset.hh:503
GV _gv
Definition: partitionviewentityset.hh:501
typename Traits::dim_type dim_type
Definition: partitionviewentityset.hh:354
const GridView & gridView() const
Definition: partitionviewentityset.hh:471
constexpr static Index invalidIndex()
Definition: partitionviewentityset.hh:361
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:353
typename Traits::Partitions Partitions
Definition: partitionviewentityset.hh:349
bool needsUpdate() const
Definition: partitionviewentityset.hh:476
Types types() const
Definition: partitionviewentityset.hh:459
typename Traits::CodimMask CodimMask
Definition: partitionviewentityset.hh:357
bool _needs_update
Definition: partitionviewentityset.hh:502
size_type size(dim_type codim) const
Definition: partitionviewentityset.hh:424
PartitionViewEntitySetIndexSetBase(const PartitionViewEntitySetIndexSetBase &)=delete
typename Traits::BaseIndexSet BaseIndexSet
Definition: partitionviewentityset.hh:352
void removeCodim(dim_type codim)
Definition: partitionviewentityset.hh:495
void reset()
Definition: partitionviewentityset.hh:483
std::array< size_type, GlobalGeometryTypeIndex::size(GV::dimension)+1 > _mapped_gt_offsets
Definition: partitionviewentityset.hh:507
const BaseIndexSet & baseIndexSet() const
Definition: partitionviewentityset.hh:448
PartitionViewEntitySetIndexSetBase & operator=(const PartitionViewEntitySetIndexSetBase &)=delete
void addCodim(dim_type codim)
Definition: partitionviewentityset.hh:489
CodimMask _active_codims
Definition: partitionviewentityset.hh:505
bool update(bool force)
Definition: partitionviewentityset.hh:375
std::bitset< GlobalGeometryTypeIndex::size(GV::dimension)> _active_geometry_types
Definition: partitionviewentityset.hh:504
PartitionViewEntitySetIndexSetBase(const GV &gv, CodimMask wanted_codims)
Definition: partitionviewentityset.hh:465
typename Traits::GridView GridView
Definition: partitionviewentityset.hh:351
typename Traits::Index Index
Definition: partitionviewentityset.hh:355
typename Traits::Types Types
Definition: partitionviewentityset.hh:356
typename Traits::Grid Grid
Definition: partitionviewentityset.hh:350
typename Traits::template Codim< codim > Codim
Definition: partitionviewentityset.hh:367
Types types(dim_type codim) const
Definition: partitionviewentityset.hh:453
bool contains(const Entity &e) const
Definition: partitionviewentityset.hh:433
std::array< size_type, GlobalGeometryTypeIndex::size(GV::dimension)+1 > _gt_offsets
Definition: partitionviewentityset.hh:506
bool contains(dim_type codim) const
Definition: partitionviewentityset.hh:438
Index IndexType
Definition: partitionviewentityset.hh:359
typename Traits::dim_type dim_type
Definition: partitionviewentityset.hh:354
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:353
typename Traits::Partitions Partitions
Definition: partitionviewentityset.hh:349
PartitionViewEntitySetIndexSet(const GV &gv, CodimMask wanted_codims, bool initialize=true)
Definition: partitionviewentityset.hh:752
typename Traits::CodimMask CodimMask
Definition: partitionviewentityset.hh:357
Index uniqueSubIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:745
Index subIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:735
typename Traits::Index Index
Definition: partitionviewentityset.hh:355
Index uniqueIndex(const E &e) const
Definition: partitionviewentityset.hh:728
Index index(const E &e) const
Definition: partitionviewentityset.hh:721