1#ifndef DUNE_PDELAB_COMMON_PARTITION_HALO_UNCOLORED_HH
2#define DUNE_PDELAB_COMMON_PARTITION_HALO_UNCOLORED_HH
7#include <dune/grid/concepts/gridview.hh>
17#if __cpp_lib_execution >= 201603L
21namespace Dune::PDELab::EntitySetPartition::Impl {
28template<Dune::Concept::Gr
idView GV>
29class UncoloredHaloMixin {
32 explicit UncoloredHaloMixin(
std::size_t halo_distance)
33 : _halo_distance{halo_distance}
40 template<Dune::Concept::Entity Entity>
41 requires (Entity::codimension == 0)
48 return (*_entity_in_halo)[_element_mapper->index(entity)]
57 requires std::is_base_of_v<UncoloredHaloMixin<GV>, Super>
58 void updateHalo(
const Super& super) {
59 static_assert(std::same_as<GV, typename Super::EntitySet>);
60 static_assert(Super::Element::dimension == Super::EntitySet::dimension,
61 "Not implemented: Partition overlap information is only available on codim == 0 entities");
63 using Element =
typename Super::Element;
65 _element_mapper = std::make_shared<Dune::MultipleCodimMultipleGeomTypeMapper<GV>>(super.entitySet(),
mcmgElementLayout());
69 _entity_in_halo =
nullptr;
70 _element_mapper =
nullptr;
74 auto all_entities_layout = [](
GeometryType gt,
int dimgrid) {
return true; };
84#if __cpp_lib_atomic_ref >= 201806L
87 constexpr auto atomic_load_relaxed = []<
class T>(T& obj) {
90 constexpr auto atomic_store_relaxed = []<
class T>(T& obj, T val) {
94 static_assert(__atomic_always_lock_free(
sizeof(
char), 0));
95 static_assert(__atomic_always_lock_free(
sizeof(
std::size_t), 0));
96 constexpr auto atomic_load_relaxed = []<
class T>(T& obj) {
98 __atomic_load(&obj, &tmp, __ATOMIC_RELAXED);
101 constexpr auto atomic_store_relaxed = []<
class T>(T& obj, T val) {
102 __atomic_store(&obj, &val, __ATOMIC_RELAXED);
109 for (
const auto& sub_entity :
subEntities(entity,
Dune::Codim<codim>{})) {
110 auto entity_index = all_mapper.index(sub_entity);
111 atomic_store_relaxed(entity_owner[entity_index],
id);
119 for (
const auto& sub_entity :
subEntities(entity,
Dune::Codim<codim>{})) {
120 auto entity_index = all_mapper.index(sub_entity);
121 auto owner = atomic_load_relaxed(entity_owner[entity_index]);
123 atomic_store_relaxed(entity_in_overlap[entity_index],
char{
true});
131 mark_entity_overlap(entity,
id);
132 if (halo_distance != 0) {
133 for (
const auto& intersection :
intersections(super.entitySet(), entity))
134 if (intersection.neighbor())
135 mark_overlap(intersection.outside(),
id, halo_distance-1);
140 auto propagate_overlap = [&](
const Element& entity,
auto,
auto) {
141 auto entity_index = _element_mapper->index(entity);
143 for (
const auto& sub_entity :
subEntities(entity,
Dune::Codim<codim>{})) {
144 auto sub_entity_index = all_mapper.index(sub_entity);
145 bool in_overlap = atomic_load_relaxed(entity_in_overlap[sub_entity_index]);
147 atomic_store_relaxed(entity_in_halo[entity_index],
char{
true});
154 auto for_each_element = [halo_distance = _halo_distance](
const auto& entity_sets,
auto apply){
155 auto patches =
std::distance(entity_sets.begin(), entity_sets.end());
158#
if __cpp_lib_execution >= 201603L
161 partitions.begin(), partitions.end(), [&](
auto patch_id){
162 for (const auto& entity : entity_sets[patch_id])
163 apply(entity, patch_id, halo_distance);
167 for (
const auto& concurrent_entity_sets : super) {
170 entity_in_overlap.
assign(all_mapper.size(),
false);
173 for_each_element(concurrent_entity_sets, mark_owner);
176 for_each_element(concurrent_entity_sets, mark_overlap);
179 for_each_element(concurrent_entity_sets, propagate_overlap);
182 _entity_in_halo = std::make_shared<std::vector<bool>>(entity_in_halo.size());
183 std::copy(entity_in_halo.begin(), entity_in_halo.end(), _entity_in_halo->begin());
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
constexpr void forEach(Range &&range, F &&f)
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon=DefaultEpsilon< T, style >::value())
For backward compatibility – Do not use this!
HaloRegion
Possible halo regions of an entity in a partition.
Definition region.hh:12
static constexpr std::size_t all_overlap_halo_region
Constant for a halo distance with all halo regions being in the overlap.
Definition region.hh:24
static constexpr std::size_t all_interior_halo_region
Constant for a halo distance with all halo regions being in the interior.
Definition region.hh:21
IteratorRange<... > intersections(const GV &gv, const Entity &e)
IteratorRange<... > subEntities(const E &e, Codim< codim > c)
MCMGLayout mcmgElementLayout()
GridImp::template Codim< cd >::Entity Entity