13#ifndef DUMUX_GEOMETRY_DISTRIBUTED_INTERSECTING_ENTITIES_HH
14#define DUMUX_GEOMETRY_DISTRIBUTED_INTERSECTING_ENTITIES_HH
20#include <dune/common/fvector.hh>
21#include <dune/common/promotiontraits.hh>
22#include <dune/geometry/type.hh>
23#include <dune/geometry/multilineargeometry.hh>
24#include <dune/grid/common/gridenums.hh>
25#include <dune/grid/common/partitionset.hh>
42template<
class Entity,
class PartitionSet>
45 if constexpr (
requires { e.partitionType(); })
46 return partitions.contains(e.partitionType());
60{
return inPartition(e, Dune::Partitions::interior); }
79template<
class EntitySet,
class ctype,
int dimworld>
80inline std::vector<std::pair<int, std::size_t>>
83 bool isCartesianGrid =
false,
84 bool onlyOwned =
true)
86 std::vector<std::pair<int, std::size_t>> result;
91 const int rank = tree.
rank();
92 result.reserve(localEntities.size());
93 for (
const auto localIdx : localEntities)
98 result.emplace_back(rank, localIdx);
108template<
class DomainEntitySet,
class TargetEntitySet>
111 using ctype =
typename Dune::PromotionTraits<typename DomainEntitySet::ctype, typename TargetEntitySet::ctype>::PromotedType;
153template<
class DomainEntitySet,
class TargetEntitySet,
154 class DomainPartitionSet = Dune::Partitions::Interior>
155std::vector<DistributedIntersectionInfo<DomainEntitySet, TargetEntitySet>>
158 DomainPartitionSet domainPartitions = {})
160 static_assert(int(DomainEntitySet::dimensionworld) == int(TargetEntitySet::dimensionworld),
161 "Can only intersect distributed bounding box trees of the same world dimension");
163 using Info = DistributedIntersectionInfo<DomainEntitySet, TargetEntitySet>;
164 static constexpr int dimworld = DomainEntitySet::dimensionworld;
165 static constexpr int dimTarget = TargetEntitySet::Entity::Geometry::mydimension;
166 using TargetCtype =
typename TargetEntitySet::ctype;
167 using ImportedGeometry = Dune::MultiLinearGeometry<TargetCtype, dimTarget, dimworld>;
168 using ImportedEntitySet = GeometriesEntitySet<ImportedGeometry>;
169 using ImportedGlobalPosition = Dune::FieldVector<TargetCtype, dimworld>;
171 const auto& comm = treeA.
comm();
172 const int myRank = comm.rank();
173 const int numProc = comm.size();
179 std::vector<std::vector<char>> sendBufs(numProc);
185 std::vector<std::vector<int>> destinations(setB.size());
188 destinations[targetIdx].push_back(p);
191 std::vector<char> entityBuf;
192 for (
const auto& entity : setB)
194 const auto entityIdx = setB.index(entity);
199 const auto geometry = entity.geometry();
203 const int numCorners = geometry.corners();
205 for (
int c = 0; c < numCorners; ++c)
207 const auto corner = geometry.corner(c);
208 for (
int d = 0; d < dimworld; ++d)
212 for (
const int p : destinations[entityIdx])
213 sendBufs[p].insert(sendBufs[p].end(), entityBuf.begin(), entityBuf.end());
221 std::vector<char> recvBuf;
226 std::vector<ImportedGeometry> importedGeometries;
227 std::vector<std::pair<int, std::size_t>> importedOrigin;
231 const char* cursor = recvBuf.data();
232 const char*
const end = recvBuf.data() + recvBuf.size();
240 std::vector<ImportedGlobalPosition> corners(numCorners);
242 for (
int d = 0; d < dimworld; ++d)
246 if (originRank == myRank)
249 ImportedGeometry geometry(Dune::GeometryType(topologyId, dimTarget), corners);
252 std::array<TargetCtype, 2*dimworld>
box{};
257 importedGeometries.push_back(std::move(geometry));
258 importedOrigin.emplace_back(originRank, originIndex);
263 std::vector<Info> result;
267 const auto& localTreeA = treeA.
localTree();
275 for (
const auto& is : raw)
281 result.push_back(Info{
282 myRank, is.first(), myRank, is.second(),
283 {is.corners().begin(), is.corners().end()}
289 if (!importedGeometries.empty())
291 const auto importedSet = std::make_shared<const ImportedEntitySet>(std::move(importedGeometries));
294 for (
const auto& is : raw)
298 const auto [originRank, originIndex] = importedOrigin[is.second()];
299 result.push_back(Info{
300 myRank, is.first(), originRank, originIndex,
301 {is.corners().begin(), is.corners().end()}
An axis-aligned bounding box volume hierarchy for dune grids.
An axis-aligned bounding box volume tree implementation.
Definition boundingboxtree.hh:105
An MPI-parallel axis-aligned bounding box volume tree.
Definition distributedboundingboxtree.hh:61
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
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
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
bool hasLocalEntities() const
whether this process holds any local entities
Definition distributedboundingboxtree.hh:158
A distributed (MPI-parallel) axis-aligned bounding box volume hierarchy.
An interface for a set of geometric entities.
void intersectingBoxes(const ctype *box, const BoundingBoxTree< EntitySet > &tree, std::size_t node, std::vector< std::size_t > &entities)
Compute all entities whose bounding box overlaps the given box.
Definition intersectingentities.hh:167
void computeGeometryBoundingBox(ctype *b, const Geometry &geometry)
Compute the bounding box of a geometry.
Definition boundingboxtree.hh:51
std::vector< std::pair< int, std::size_t > > intersectingEntities(const Dune::FieldVector< ctype, dimworld > &point, const DistributedBoundingBoxTree< EntitySet > &tree, bool isCartesianGrid=false, bool onlyOwned=true)
Compute all intersections between entities and a point on a distributed tree.
Definition distributedintersectingentities.hh:81
std::vector< char > exchangeSparse(const Communication &comm, std::vector< std::vector< char > > &sendBufs, int tag=7373)
Exchange variable-sized byte messages with a sparse set of peer processes.
Definition nonblockingsparseexchange.hh:46
Algorithms that finds which geometric entities intersect.
Definition cvfelocalresidual.hh:25
void packValue(std::vector< char > &buf, const T &value)
Append the raw bytes of a trivially-copyable value to a byte buffer.
Definition packing.hh:25
bool isUniquelyOwned(const Entity &e)
Whether an entity is uniquely owned by the calling process.
Definition distributedintersectingentities.hh:59
T unpackValue(const char *&cursor)
Read a trivially-copyable value from a byte buffer and advance the cursor.
Definition packing.hh:34
bool inPartition(const Entity &e, PartitionSet partitions)
Whether an entity belongs to one of the given parallel partitions.
Definition distributedintersectingentities.hh:43
constexpr Box box
Definition method.hh:176
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition throatproperties.hh:220
bool intersectsBoundingBoxBoundingBox(const ctypea *a, const ctypeb *b)
Check whether a bounding box is intersecting another bounding box (dimworld == 3).
Definition boundingboxtree.hh:372
A dynamic sparse data exchange (DSDE) of byte messages between processes.
Helpers to (de)serialize trivially-copyable values into a byte buffer (e.g. for point-to-point or col...
An intersection of two entities of distributed entity sets.
Definition distributedintersectingentities.hh:110
std::size_t targetIndex
the local index of the target entity on targetRank
Definition distributedintersectingentities.hh:118
Dune::FieldVector< ctype, dimensionworld > GlobalPosition
Definition distributedintersectingentities.hh:113
typename Dune::PromotionTraits< typename DomainEntitySet::ctype, typename TargetEntitySet::ctype >::PromotedType ctype
Definition distributedintersectingentities.hh:111
std::size_t domainIndex
the local index of the domain entity on domainRank
Definition distributedintersectingentities.hh:116
int domainRank
the rank owning the domain (first) entity
Definition distributedintersectingentities.hh:115
std::vector< GlobalPosition > corners
the corners of the (simplex) intersection geometry
Definition distributedintersectingentities.hh:119
static constexpr int dimensionworld
Definition distributedintersectingentities.hh:112
int targetRank
the rank owning the target (second) entity
Definition distributedintersectingentities.hh:117