22#ifndef DUMUX_GEOMETRY_DISTRIBUTED_BOUNDINGBOXTREE_HH
23#define DUMUX_GEOMETRY_DISTRIBUTED_BOUNDINGBOXTREE_HH
34#include <dune/common/fvector.hh>
35#include <dune/common/exceptions.hh>
58template<
class GeometricEntitySet>
59 requires requires(
const GeometricEntitySet& set) { { set.comm() }; }
62 static constexpr int dimworld = GeometricEntitySet::dimensionworld;
63 using ctype =
typename GeometricEntitySet::ctype;
77 using Communication = std::decay_t<decltype(std::declval<const GeometricEntitySet>().comm())>;
89 void build(std::shared_ptr<const GeometricEntitySet> set)
93 const int numProc = comm_.size();
99 localTree_ = std::make_shared<const LocalTree>(set);
105 std::array<ctype, 2*dimworld> localBox{};
110 std::vector<ctype> processBoxes(2*dimworld*numProc, 0.0);
111 comm_.allgather(localBox.data(), 2*dimworld, processBoxes.data());
115 std::vector<int> processValid(numProc, 0);
116 comm_.allgather(&localValid, 1, processValid.data());
120 std::vector<ProcessEntity> processEntities;
121 processEntities.reserve(numProc);
122 for (
int p = 0; p < numProc; ++p)
124 if (!processValid[p])
127 const ctype* b = processBoxes.data() + std::size_t(p)*2*dimworld;
128 Dune::FieldVector<ctype, dimworld> lower, upper;
129 for (
int d = 0; d < dimworld; ++d)
132 upper[d] = b[d + dimworld];
135 processEntities.emplace_back(ProcessBoxGeometry{lower, upper}, processEntities.size(), p);
140 assert(!processEntities.empty());
141 processTree_ = std::make_shared<const ProcessTree>(
142 std::make_shared<const ProcessEntitySet>(std::move(processEntities)));
147 {
return *entitySet_; }
155 {
return comm_.rank(); }
159 {
return static_cast<bool>(localTree_); }
165 DUNE_THROW(Dune::InvalidStateException,
"No local bounding box tree on a process without entities");
171 {
return *processTree_; }
175 {
return processTree_->entitySet().rank(leafIdx); }
181 DUNE_THROW(Dune::InvalidStateException,
"No local bounding box on a process without entities");
182 const auto* root = localTree_->getBoundingBoxCoordinates(localTree_->numBoundingBoxes() - 1);
183 return std::span<const ctype, 2*dimworld>{root, 2*dimworld};
188 std::shared_ptr<const EntitySet> entitySet_;
191 std::shared_ptr<const LocalTree> localTree_;
194 std::shared_ptr<const ProcessTree> processTree_;
A thin axis-aligned box geometry.
An axis-aligned bounding box volume hierarchy for dune grids.
A thin axis-aligned box geometry.
Definition boundingboxgeometry.hh:34
An axis-aligned bounding box volume tree implementation.
Definition boundingboxtree.hh:105
BoundingBoxTree< ProcessEntitySet > ProcessTree
the type of the replicated process tree
Definition distributedboundingboxtree.hh:79
DistributedBoundingBoxTree()=default
Default constructor.
void build(std::shared_ptr< const GeometricEntitySet > set)
Build the distributed bounding box tree for the given entity set.
Definition distributedboundingboxtree.hh:89
const LocalTree & localTree() const
the process-local bounding box tree (only valid if hasLocalEntities())
Definition distributedboundingboxtree.hh:162
const EntitySet & entitySet() const
the entity set this tree was built with
Definition distributedboundingboxtree.hh:146
const ProcessTree & processTree() const
the replicated process tree over the per-process boxes
Definition distributedboundingboxtree.hh:170
GeometricEntitySet EntitySet
the type of entity set this tree was built with
Definition distributedboundingboxtree.hh:75
std::span< const ctype, 2 *dimworld > localBoundingBox() const
the bounding box (min then max) of this process' partition (only valid if hasLocalEntities())
Definition distributedboundingboxtree.hh:178
BoundingBoxTree< GeometricEntitySet > LocalTree
the type of the process-local bounding box tree
Definition distributedboundingboxtree.hh:73
DistributedBoundingBoxTree(std::shared_ptr< const GeometricEntitySet > set)
Constructor with an entity set.
Definition distributedboundingboxtree.hh:85
const Communication & comm() const
the communicator this tree was built with
Definition distributedboundingboxtree.hh:150
int processForLeaf(std::size_t leafIdx) const
the rank owning the given leaf of the process tree
Definition distributedboundingboxtree.hh:174
int rank() const
the rank of this process
Definition distributedboundingboxtree.hh:154
std::decay_t< decltype(std::declval< const GeometricEntitySet >().comm())> Communication
the communicator type
Definition distributedboundingboxtree.hh:77
bool hasLocalEntities() const
Definition distributedboundingboxtree.hh:158
A set of axis-aligned bounding boxes each owned by a process rank.
Definition geometricentityset.hh:375
Detail::GeometricEntity::ProcessEntity< ctype, dimworld > Entity
Definition geometricentityset.hh:377
An interface for a set of geometric entities.