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>
36 template<
typename GV,
typename P>
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>
106 template<
typename GV,
typename P>
134 template<dim_type codim>
149 return gridView().grid();
161 return indexSet().baseIndexSet();
164 template<dim_type codim>
168 return gridView().template begin<codim,Partitions::partitionIterator()>();
171 template<dim_type codim>
175 return gridView().template end<codim,Partitions::partitionIterator()>();
178 template<dim_type codim, PartitionIteratorType pitype>
182 return gridView().template begin<codim,pitype>();
185 template<dim_type codim, PartitionIteratorType pitype>
189 return gridView().template end<codim,pitype>();
194 return indexSet().size(codim);
199 return indexSet().size(gt);
202 template<
typename Entity>
205 return indexSet().contains(e);
210 return indexSet().contains(codim);
215 return indexSet().contains(gt);
220 return gridView().ibegin(entity);
225 return gridView().iend(entity);
230 return gridView().comm();
236 return Partitions::contains(Dune::Partitions::overlap) ? gridView().overlapSize(codim) : 0;
242 return Partitions::contains(Dune::Partitions::ghost) ? gridView().ghostSize(codim) : 0;
245 template<
typename DataHandle>
246 void communicate(DataHandle& data, InterfaceType iftype, CommunicationDirection dir)
const 248 gridView().communicate(data,iftype,dir);
254 return indexSet().gridView();
258 : _index_set(
std::make_shared<
IndexSet>(gv,supported_codims,true))
274 _index_set->addCodim(codim);
280 _index_set->removeCodim(codim);
286 return _index_set->needsUpdate();
300 return _index_set->update(force);
305 std::shared_ptr<IndexSet> _index_set;
309 template<
typename GV,
typename P>
313 template<
typename,
typename>
334 return Traits::invalidIndex();
337 template<dim_type codim>
348 if (!(_needs_update || force))
350 std::fill(_gt_offsets.begin(),_gt_offsets.end(),0);
351 std::fill(_mapped_gt_offsets.begin(),_mapped_gt_offsets.end(),0);
352 _active_geometry_types.reset();
353 _geometry_types.resize(0);
354 for (
dim_type codim = 0; codim <= GV::dimension; ++codim)
356 if (!_wanted_codims.test(codim))
358 for (
const auto& gt : baseIndexSet().types(codim))
360 auto gt_index = GlobalGeometryTypeIndex::index(gt);
361 _gt_offsets[gt_index + 1] = baseIndexSet().size(gt);
362 _geometry_types.push_back(gt);
363 _active_geometry_types.set(gt_index);
366 for (
dim_type codim = 0; codim <= GV::dimension; ++codim)
368 auto range = std::equal_range(
369 _geometry_types.begin(),
370 _geometry_types.end(),
371 GeometryType(GeometryType::none,GV::dimension - codim),
372 [](
const GeometryType& x,
const GeometryType& y)
375 return y.dim() < x.dim();
377 _per_codim_geometry_types[codim] = {range.first,range.second};
380 std::partial_sum(_gt_offsets.begin(),_gt_offsets.end(),_gt_offsets.begin());
381 _active_codims = _wanted_codims;
382 _needs_update =
false;
390 assert(!needsUpdate());
391 auto gt_index = GlobalGeometryTypeIndex::index(gt);
392 return _mapped_gt_offsets[gt_index + 1] - _mapped_gt_offsets[gt_index];
397 assert(!needsUpdate());
398 auto dim = GV::dimension;
399 #if DUNE_VERSION_NEWER_REV(DUNE_GEOMETRY,2,4,1) 403 return codim <
dim ? _mapped_gt_offsets[GlobalGeometryTypeIndex::size(
dim-codim)] -
404 _mapped_gt_offsets[GlobalGeometryTypeIndex::size(
dim-codim-1)] : 0;
408 template<
typename Entity>
411 return Partitions::contains(e.partitionType()) ? baseIndexSet().contains(e) :
false;
416 return _active_codims.test(codim);
421 return _active_geometry_types.test(GlobalGeometryTypeIndex::index(gt));
426 return _gv.indexSet();
431 assert(!needsUpdate());
432 return _per_codim_geometry_types[codim];
437 assert(!needsUpdate());
438 return {_geometry_types.begin(),_geometry_types.end()};
443 , _needs_update(true)
444 , _wanted_codims(wanted_codims)
454 return _needs_update;
461 _needs_update =
true;
462 _wanted_codims.reset();
467 _wanted_codims.set(codim);
468 _needs_update = _wanted_codims != _active_codims || _wanted_codims.none();
473 _wanted_codims.reset(codim);
474 _needs_update = _wanted_codims != _active_codims || _wanted_codims.none();
482 std::array<size_type,GlobalGeometryTypeIndex::size(GV::dimension) + 1>
_gt_offsets;
487 std::vector<GeometryType> _geometry_types;
488 std::array<Types,GV::dimension + 1> _per_codim_geometry_types;
492 template<
typename GV,
typename P>
499 template<
typename,
typename>
504 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 && __GNUC_MINOR__ < 8 526 using Base::gridView;
527 using Base::baseIndexSet;
528 using Base::invalidIndex;
529 using Base::contains;
530 using Base::needsUpdate;
534 static constexpr
bool hasAllEntities(Dune::Dim<Grid::dimension + 1>)
539 template<dim_type dim = 0>
540 static constexpr
bool hasAllEntities(Dune::Dim<dim> = {})
542 return Capabilities::hasEntity<Grid,dim>::v && hasAllEntities(Dune::Dim<dim+1>{});
545 bool update(
bool force)
547 if (!Base::update(force))
550 _mapped_gt_offsets[0] = 0;
551 update_codims(std::integral_constant<
bool,hasAllEntities()>{});
552 std::partial_sum(_mapped_gt_offsets.begin(),_mapped_gt_offsets.end(),_mapped_gt_offsets.begin());
556 void update_codims(std::true_type)
558 update_codim(Dune::Codim<0>{});
561 void update_codim(Dune::Codim<GV::dimension+1>)
564 template<dim_type cd>
565 void update_codim(Dune::Codim<cd> codim)
567 if (_active_codims.test(codim))
568 for (
const auto&
e : entities(gridView(),codim,Dune::Partitions::all))
571 auto gt_index = GlobalGeometryTypeIndex::index(gt);
572 if (Partitions::contains(
e.partitionType()))
573 _indices[_gt_offsets[gt_index] + baseIndexSet().index(
e)] = _mapped_gt_offsets[gt_index + 1]++;
575 update_codim(Dune::Codim<cd+1>{});
579 void update_codims(std::false_type)
581 std::fill(_indices.begin(),_indices.end(),
invalidIndex());
583 auto& index_set = baseIndexSet();
585 for (
const auto&
e : elements(gridView(),Dune::Partitions::all))
587 if (!Partitions::contains(
e.partitionType()))
590 auto& ref_el = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(
e.type());
591 for (
dim_type codim = 0; codim <= Grid::dimension; ++codim)
593 if (!_active_codims.test(codim))
596 size_type sub_entity_count = ref_el.size(codim);
598 for(
size_type i = 0; i < sub_entity_count; ++i)
600 auto gt = ref_el.type(i,codim);
601 auto gt_index = GlobalGeometryTypeIndex::index(gt);
602 auto index = index_set.subIndex(
e,i,codim);
603 if (_indices[_gt_offsets[gt_index] + index] ==
invalidIndex())
604 _indices[_gt_offsets[gt_index] + index] = _mapped_gt_offsets[gt_index + 1]++;
616 assert(!needsUpdate());
617 assert(Partitions::contains(e.partitionType()));
618 assert(contains(e.type()));
619 auto gt_index = GlobalGeometryTypeIndex::index(e.type());
620 return _indices[_gt_offsets[gt_index] + baseIndexSet().index(e)];
626 assert(!needsUpdate());
627 assert(Partitions::contains(e.partitionType()));
628 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(e.type()).type(i,codim);
629 assert(contains(gt));
630 auto gt_index = GlobalGeometryTypeIndex::index(gt);
631 return _indices[_gt_offsets[gt_index] + baseIndexSet().subIndex(e,i,codim)];
638 assert(!needsUpdate());
639 assert(Partitions::contains(e.partitionType()));
640 assert(contains(e.type()));
641 auto gt_index = GlobalGeometryTypeIndex::index(e.type());
642 return _indices[_gt_offsets[gt_index] + baseIndexSet().index(e)] + _mapped_gt_offsets[gt_index];
648 assert(!needsUpdate());
649 assert(Partitions::contains(e.partitionType()));
650 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(e.type()).type(i,codim);
651 assert(contains(gt));
652 auto gt_index = GlobalGeometryTypeIndex::index(gt);
653 return _indices[_gt_offsets[gt_index] + baseIndexSet().subIndex(e,i,codim)] + _mapped_gt_offsets[gt_index];
658 :
Base(gv,wanted_codims)
666 using Base::_active_codims;
667 using Base::_gt_offsets;
668 using Base::_mapped_gt_offsets;
670 std::vector<Index> _indices;
674 template<
typename GV>
681 template<
typename,
typename>
692 using Base::baseIndexSet;
693 using Base::contains;
699 if (!Base::update(force))
701 _mapped_gt_offsets[0] = 0;
702 for (
const auto& gt : Base::types())
703 _mapped_gt_offsets[GlobalGeometryTypeIndex::index(gt) + 1] =
baseIndexSet().size(gt);
704 std::partial_sum(_mapped_gt_offsets.begin(),_mapped_gt_offsets.end(),_mapped_gt_offsets.begin());
721 return baseIndexSet().index(e) + _mapped_gt_offsets[Dune::GlobalGeometryTypeIndex::index(e.type())];
728 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(e.type()).type(i,codim);
737 auto gt = ReferenceElements<typename Base::Traits::CoordinateField,GV::dimension>::general(e.type()).type(i,codim);
739 return baseIndexSet().subIndex(e,i,codim) + _mapped_gt_offsets[Dune::GlobalGeometryTypeIndex::index(gt)];
743 : Base(gv,wanted_codims)
751 using Base::_mapped_gt_offsets;
755 template<
typename GV>
758 template<
typename GV>
761 template<
typename GV>
771 using type = std::false_type;
774 template<
typename GV,
typename P>
775 struct _isEntitySet<PartitionViewEntitySet<GV,P>>
777 using type = std::true_type;
792 #endif // DUNE_PDELAB_COMMON_PARTITIONVIEWENTITYSET_HH const BaseIndexSet & baseIndexSet() const
Returns the IndexSet of the underlying GridView.
Definition: partitionviewentityset.hh:159
size_type overlapSize(dim_type codim) const
Returns the overlap size of this EntitySet, which depends on its PartitionSet.
Definition: partitionviewentityset.hh:234
typename Traits::template Codim< codim > Codim
Definition: partitionviewentityset.hh:135
typename GV::template Codim< codim >::Geometry Geometry
Definition: partitionviewentityset.hh:89
Codim< codim >::Iterator end() const
Definition: partitionviewentityset.hh:173
Index index(const E &e) const
Definition: partitionviewentityset.hh:614
typename GV::template Codim< codim >::template Partition< pitype >::Iterator Iterator
Definition: partitionviewentityset.hh:97
IntersectionIterator iend(const typename Codim< 0 >::Entity &entity) const
Definition: partitionviewentityset.hh:223
typename GV::template Codim< codim >::Entity Entity
Definition: partitionviewentityset.hh:87
typename GV::template Codim< codim >::LocalGeometry LocalGeometry
Definition: partitionviewentityset.hh:91
Index subIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:624
typename Traits::Index Index
Definition: partitionviewentityset.hh:326
void removeCodim(dim_type codim)
Remove all entities of the given codim from this EntitySet.
Definition: partitionviewentityset.hh:278
PartitionViewEntitySetIndexSetBase(const GV &gv, CodimMask wanted_codims)
Definition: partitionviewentityset.hh:441
typename Traits::CoordinateField CoordinateField
Definition: partitionviewentityset.hh:124
static constexpr CodimMask allCodims()
Definition: partitionviewentityset.hh:142
typename Traits::BaseIndexSet BaseIndexSet
Definition: partitionviewentityset.hh:323
Definition: partitionviewentityset.hh:34
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:324
typename Traits::IntersectionIterator IntersectionIterator
Definition: partitionviewentityset.hh:121
typename Traits::Index Index
Definition: partitionviewentityset.hh:326
static const bool conforming
Definition: partitionviewentityset.hh:75
static const dim_type dimensionworld
Definition: partitionviewentityset.hh:79
CodimMask _active_codims
Definition: partitionviewentityset.hh:481
typename Traits::Partitions Partitions
Definition: partitionviewentityset.hh:114
typename GV::template Codim< 0 >::Entity Element
Definition: partitionviewentityset.hh:51
size_type ghostSize(dim_type codim) const
Returns the ghost size of this EntitySet, which depends on its PartitionSet.
Definition: partitionviewentityset.hh:240
typename Traits::Types Types
Definition: partitionviewentityset.hh:327
typename GV::Traits::IndexSet BaseIndexSet
Definition: partitionviewentityset.hh:49
void reset()
Definition: partitionviewentityset.hh:459
GV::template Codim< codim >::template Partition< pitype >::Iterator begin() const
Definition: partitionviewentityset.hh:180
static const int dim
Definition: adaptivity.hh:83
typename Traits::CodimMask CodimMask
Definition: partitionviewentityset.hh:123
typename Traits::dim_type dim_type
Definition: partitionviewentityset.hh:325
typename GV::Traits::Intersection Intersection
Definition: partitionviewentityset.hh:53
Definition: partitionviewentityset.hh:82
const CollectiveCommunication & comm() const
Definition: partitionviewentityset.hh:228
Definition: adaptivity.hh:27
void addCodim(dim_type codim)
Add all entities of the given codim to this EntitySet.
Definition: partitionviewentityset.hh:272
typename Traits::template Codim< codim > Codim
Definition: partitionviewentityset.hh:338
Index IndexType
Definition: partitionviewentityset.hh:330
std::bitset< GlobalGeometryTypeIndex::size(GV::dimension)> _active_geometry_types
Definition: partitionviewentityset.hh:480
typename Traits::GridView GridView
Definition: partitionviewentityset.hh:116
bool contains(const GeometryType >) const
Definition: partitionviewentityset.hh:213
typename impl::_isEntitySet< T >::type isEntitySet
Type Trait to determine whether T is an EntitySet.
Definition: partitionviewentityset.hh:786
bool update(bool force)
Definition: partitionviewentityset.hh:346
CodimMask _wanted_codims
Definition: partitionviewentityset.hh:479
bool contains(const GeometryType >) const
Definition: partitionviewentityset.hh:419
size_type size(GeometryType gt) const
Definition: partitionviewentityset.hh:388
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:324
Index subIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:725
GV _gv
Definition: partitionviewentityset.hh:477
bool contains(const Entity &e) const
Definition: partitionviewentityset.hh:409
Types types() const
Definition: partitionviewentityset.hh:435
const std::size_t offset
Definition: localfunctionspace.hh:74
typename Grid::ctype CoordinateField
Definition: partitionviewentityset.hh:68
const Entity & e
Definition: localfunctionspace.hh:111
void reset()
Reset this EntitySet, which removes all entities from it.
Definition: partitionviewentityset.hh:266
IteratorRange< std::vector< GeometryType >::const_iterator > Types
Definition: partitionviewentityset.hh:64
bool contains(const Entity &e) const
Definition: partitionviewentityset.hh:203
Definition: pdelab.hh:436
std::array< size_type, GlobalGeometryTypeIndex::size(GV::dimension)+1 > _gt_offsets
Definition: partitionviewentityset.hh:482
static constexpr Index invalidIndex()
Definition: partitionviewentityset.hh:70
std::size_t size_type
Definition: partitionviewentityset.hh:59
size_type size(dim_type codim) const
Definition: partitionviewentityset.hh:395
IntersectionIterator ibegin(const typename Codim< 0 >::Entity &entity) const
Definition: partitionviewentityset.hh:218
void addCodim(dim_type codim)
Definition: partitionviewentityset.hh:465
Index uniqueIndex(const E &e) const
Definition: partitionviewentityset.hh:718
typename Traits::CodimMask CodimMask
Definition: partitionviewentityset.hh:328
static constexpr Partitions partitions()
Definition: partitionviewentityset.hh:137
typename Traits::Element Element
Definition: partitionviewentityset.hh:119
GV::template Codim< codim >::template Partition< pitype >::Iterator end() const
Definition: partitionviewentityset.hh:187
bool needsUpdate() const
Returns true if you need to call update on this EntitySet before using it.
Definition: partitionviewentityset.hh:284
Definition: partitionviewentityset.hh:40
typename Traits::Partitions Partitions
Definition: partitionviewentityset.hh:320
PartitionViewEntitySetIndexSet(const GV &gv, CodimMask wanted_codims, bool initialize)
Definition: partitionviewentityset.hh:657
Index uniqueSubIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:735
typename GV::Traits::IntersectionIterator IntersectionIterator
Definition: partitionviewentityset.hh:55
typename std::decay< P >::type Partitions
Definition: partitionviewentityset.hh:43
std::bitset< GV::dimension+1 > CodimMask
Definition: partitionviewentityset.hh:66
typename Traits::Partitions Partitions
Definition: partitionviewentityset.hh:320
Index uniqueIndex(const E &e) const
Definition: partitionviewentityset.hh:636
Codim< codim >::Iterator begin() const
Definition: partitionviewentityset.hh:166
PartitionViewEntitySet(const GridView &gv, CodimMask supported_codims)
Definition: partitionviewentityset.hh:257
Index uniqueSubIndex(const E &e, size_type i, dim_type codim) const
Definition: partitionviewentityset.hh:646
bool contains(dim_type codim) const
Definition: partitionviewentityset.hh:208
typename Traits::Grid Grid
Definition: partitionviewentityset.hh:321
typename Traits::Intersection Intersection
Definition: partitionviewentityset.hh:120
Types types(dim_type codim) const
Definition: partitionviewentityset.hh:429
typename GV::Traits::CollectiveCommunication CollectiveCommunication
Definition: partitionviewentityset.hh:57
const Grid & grid() const
Definition: partitionviewentityset.hh:147
int dim_type
Definition: partitionviewentityset.hh:60
bool _needs_update
Definition: partitionviewentityset.hh:478
PartitionViewEntitySetIndexSet(const GV &gv, CodimMask wanted_codims, bool initialize=true)
Definition: partitionviewentityset.hh:742
CoordinateField ctype
Definition: partitionviewentityset.hh:128
typename Traits::size_type size_type
Definition: partitionviewentityset.hh:125
typename Traits::CodimMask CodimMask
Definition: partitionviewentityset.hh:328
typename Traits::GridView GridView
Definition: partitionviewentityset.hh:322
Definition: partitionviewentityset.hh:310
PartitionViewEntitySet(const GridView &gv)
Definition: partitionviewentityset.hh:261
bool update(bool force=false)
Update the internal state of this EntitySet.
Definition: partitionviewentityset.hh:298
typename BaseIndexSet::IndexType Index
Definition: partitionviewentityset.hh:62
Definition: partitionviewentityset.hh:37
typename GV::Traits::Grid Grid
Definition: partitionviewentityset.hh:45
static constexpr Index invalidIndex()
Definition: partitionviewentityset.hh:332
typename Traits::BaseIndexSet BaseIndexSet
Definition: partitionviewentityset.hh:118
std::array< size_type, GlobalGeometryTypeIndex::size(GV::dimension)+1 > _mapped_gt_offsets
Definition: partitionviewentityset.hh:483
Definition: partitionviewentityset.hh:94
size_type size(dim_type codim) const
Definition: partitionviewentityset.hh:192
bool needsUpdate() const
Definition: partitionviewentityset.hh:452
const GridView & gridView() const
Definition: partitionviewentityset.hh:447
const BaseIndexSet & baseIndexSet() const
Definition: partitionviewentityset.hh:424
void removeCodim(dim_type codim)
Definition: partitionviewentityset.hh:471
static const dim_type dimension
Definition: partitionviewentityset.hh:77
typename Traits::dim_type dim_type
Definition: partitionviewentityset.hh:325
typename GV::template Codim< codim >::template Partition< Partitions::partitionIterator()>::Iterator Iterator
Definition: partitionviewentityset.hh:85
GV GridView
Definition: partitionviewentityset.hh:46
typename Traits::Grid Grid
Definition: partitionviewentityset.hh:115
const IndexSet & indexSet() const
Returns the IndexSet of this EntitySet.
Definition: partitionviewentityset.hh:153
bool contains(dim_type codim) const
Definition: partitionviewentityset.hh:414
typename Traits::Index Index
Definition: partitionviewentityset.hh:326
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir) const
Definition: partitionviewentityset.hh:246
typename Traits::CollectiveCommunication CollectiveCommunication
Definition: partitionviewentityset.hh:122
typename Traits::IndexSet IndexSet
Definition: partitionviewentityset.hh:117
const GridView & gridView() const
Returns the underlying GridView.
Definition: partitionviewentityset.hh:252
Index index(const E &e) const
Definition: partitionviewentityset.hh:711
size_type size(const GeometryType >) const
Definition: partitionviewentityset.hh:197