version 3.11-dev
Loading...
Searching...
No Matches
distributedintersectionentityset.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_GEOMETRY_DISTRIBUTED_INTERSECTION_ENTITY_SET_HH
13#define DUMUX_GEOMETRY_DISTRIBUTED_INTERSECTION_ENTITY_SET_HH
14
15#include <algorithm>
16#include <memory>
17#include <utility>
18#include <vector>
19
20#include <dune/common/timer.hh>
21#include <dune/common/iteratorrange.hh>
22#include <dune/common/iteratorfacades.hh>
23#include <dune/geometry/affinegeometry.hh>
24#include <dune/geometry/type.hh>
25
28
29namespace Dumux {
30
44template<class DomainEntitySet, class TargetEntitySet>
46{
50
51public:
52 using ctype = typename Info::ctype;
53 static constexpr int dimensionworld = Info::dimensionworld;
55
56private:
57 static constexpr int dimDomain = DomainEntitySet::Entity::Geometry::mydimension;
58 static constexpr int dimTarget = TargetEntitySet::Entity::Geometry::mydimension;
59 static constexpr int dimIs = std::min(dimDomain, dimTarget);
60
61public:
63 using Geometry = Dune::AffineGeometry<ctype, dimIs, dimensionworld>;
64
69 {
70 public:
72 : set_(set), info_(info) {}
73
76 { return Geometry(Dune::GeometryTypes::simplex(dimIs), info_.corners); }
77
79 int domainRank() const { return info_.domainRank; }
81 std::size_t domainIndex() const { return info_.domainIndex; }
83 int targetRank() const { return info_.targetRank; }
85 std::size_t targetIndex() const { return info_.targetIndex; }
86
88 typename DomainEntitySet::Entity domainEntity() const
89 { return set_.domainTree_->entitySet().entity(info_.domainIndex); }
90
92 bool targetIsLocal() const
93 { return info_.targetRank == set_.targetTree_->rank(); }
94
96 typename TargetEntitySet::Entity targetEntity() const
97 { return set_.targetTree_->entitySet().entity(info_.targetIndex); }
98
99 private:
101 const Info& info_;
102 };
103
109 : public Dune::ForwardIteratorFacade<IntersectionIterator, const IntersectionEntity, IntersectionEntity>
110 {
111 using InfoIterator = typename std::vector<Info>::const_iterator;
112 public:
114 : set_(&set), it_(it) {}
115
117 { return IntersectionEntity(*set_, *it_); }
118
119 bool equals(const IntersectionIterator& other) const
120 { return it_ == other.it_; }
121
122 void increment() { ++it_; }
123
124 private:
126 InfoIterator it_;
127 };
128
130
133
138 void build(std::shared_ptr<const DomainEntitySet> domainSet,
139 std::shared_ptr<const TargetEntitySet> targetSet)
140 {
141 build(std::make_shared<DomainTree>(domainSet), std::make_shared<TargetTree>(targetSet));
142 }
143
148 void build(std::shared_ptr<const DomainTree> domainTree,
149 std::shared_ptr<const TargetTree> targetTree)
150 {
151 domainTree_ = domainTree;
152 targetTree_ = targetTree;
153
154 Dune::Timer timer;
155 intersections_ = intersectingEntities(*domainTree_, *targetTree_);
156
157 const auto& comm = domainTree_->comm();
158 const std::size_t globalSize = comm.sum(intersections_.size());
159 if (comm.rank() == 0)
160 std::cout << "Computed " << globalSize << " distributed intersection entities in "
161 << timer.elapsed() << " seconds." << std::endl;
162 }
163
165 std::size_t size() const
166 { return intersections_.size(); }
167
169 IntersectionIterator ibegin() const
170 { return IntersectionIterator(*this, intersections_.begin()); }
171
173 IntersectionIterator iend() const
174 { return IntersectionIterator(*this, intersections_.end()); }
175
180 friend Dune::IteratorRange<EntityIterator> intersections(const DistributedIntersectionEntitySet& set)
181 { return {set.ibegin(), set.iend()}; }
182
183private:
184 std::vector<Info> intersections_;
185 std::shared_ptr<const DomainTree> domainTree_;
186 std::shared_ptr<const TargetTree> targetTree_;
187};
188
189} // end namespace Dumux
190
191#endif
An MPI-parallel axis-aligned bounding box volume tree.
Definition distributedboundingboxtree.hh:61
A view on a single intersection entity.
Definition distributedintersectionentityset.hh:69
std::size_t targetIndex() const
the local index of the target entity on its owner rank
Definition distributedintersectionentityset.hh:85
IntersectionEntity(const DistributedIntersectionEntitySet &set, const Info &info)
Definition distributedintersectionentityset.hh:71
int targetRank() const
the rank owning the target (second) entity (possibly remote)
Definition distributedintersectionentityset.hh:83
DomainEntitySet::Entity domainEntity() const
the domain entity (always local to this process)
Definition distributedintersectionentityset.hh:88
Geometry geometry() const
the intersection geometry
Definition distributedintersectionentityset.hh:75
std::size_t domainIndex() const
the local index of the domain entity on its owner rank
Definition distributedintersectionentityset.hh:81
bool targetIsLocal() const
whether the target entity is owned by this process
Definition distributedintersectionentityset.hh:92
TargetEntitySet::Entity targetEntity() const
the target entity (only valid if targetIsLocal())
Definition distributedintersectionentityset.hh:96
int domainRank() const
the rank owning the domain (first) entity (always this process)
Definition distributedintersectionentityset.hh:79
An iterator over the intersection entities.
Definition distributedintersectionentityset.hh:110
bool equals(const IntersectionIterator &other) const
Definition distributedintersectionentityset.hh:119
IntersectionIterator(const DistributedIntersectionEntitySet &set, InfoIterator it)
Definition distributedintersectionentityset.hh:113
IntersectionEntity dereference() const
Definition distributedintersectionentityset.hh:116
void increment()
Definition distributedintersectionentityset.hh:122
typename Info::ctype ctype
Definition distributedintersectionentityset.hh:52
Dune::AffineGeometry< ctype, dimIs, dimensionworld > Geometry
the geometry of an intersection (always a simplex)
Definition distributedintersectionentityset.hh:63
DistributedIntersectionEntitySet()=default
Default constructor.
IntersectionIterator ibegin() const
begin iterator over the (process-local) intersections
Definition distributedintersectionentityset.hh:169
IntersectionIterator iend() const
end iterator over the (process-local) intersections
Definition distributedintersectionentityset.hh:173
std::size_t size() const
the number of (process-local) intersections
Definition distributedintersectionentityset.hh:165
friend Dune::IteratorRange< EntityIterator > intersections(const DistributedIntersectionEntitySet &set)
Range generator to iterate with range-based for loops over all intersections as follows: for (const a...
Definition distributedintersectionentityset.hh:180
IntersectionIterator EntityIterator
Definition distributedintersectionentityset.hh:129
void build(std::shared_ptr< const DomainEntitySet > domainSet, std::shared_ptr< const TargetEntitySet > targetSet)
Build the intersections from two distributed entity sets.
Definition distributedintersectionentityset.hh:138
void build(std::shared_ptr< const DomainTree > domainTree, std::shared_ptr< const TargetTree > targetTree)
Build the intersections from two distributed bounding box trees.
Definition distributedintersectionentityset.hh:148
typename Info::GlobalPosition GlobalPosition
Definition distributedintersectionentityset.hh:54
A distributed (MPI-parallel) axis-aligned bounding box volume hierarchy.
Algorithms that find which geometric entities intersect across processes using a distributed (MPI-par...
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
Definition adapt.hh:17
An intersection of two entities of distributed entity sets.
Definition distributedintersectingentities.hh:110
Dune::FieldVector< ctype, dimensionworld > GlobalPosition
Definition distributedintersectingentities.hh:113
typename Dune::PromotionTraits< typename DomainEntitySet::ctype, typename TargetEntitySet::ctype >::PromotedType ctype
Definition distributedintersectingentities.hh:111
static constexpr int dimensionworld
Definition distributedintersectingentities.hh:112