22#ifndef DUMUX_INTERSECTING_ENTITIES_HH
23#define DUMUX_INTERSECTING_ENTITIES_HH
29#include <dune/common/fvector.hh>
44template<
int dimworld,
class CoordTypeA,
class CoordTypeB = CoordTypeA>
48 using ctype =
typename Dune::PromotionTraits<CoordTypeA, CoordTypeB>::PromotedType;
52 template<
class Corners>
56 , corners_(c.begin(), c.end())
68 std::vector<GlobalPosition>
corners()
const
75 bool cornersMatch(
const std::vector<GlobalPosition>& otherCorners)
const
77 if (otherCorners.size() != corners_.size())
80 const auto eps = 1.5e-7*(corners_[1] - corners_[0]).two_norm();
81 for (
int i = 0; i < corners_.size(); ++i)
82 if ((corners_[i] - otherCorners[i]).two_norm() > eps)
90 std::vector<GlobalPosition> corners_;
97template<
class EntitySet,
class ctype,
int dimworld>
98inline std::vector<std::size_t>
101 bool isCartesianGrid =
false)
104 std::vector<std::size_t> entities;
113template<
class EntitySet,
class ctype,
int dimworld>
117 std::vector<std::size_t>& entities,
118 bool isCartesianGrid =
false)
128 else if (tree.
isLeaf(bBox, node))
130 const std::size_t entityIdx = bBox.child1;
133 entities.push_back(entityIdx);
136 const auto geometry = tree.
entitySet().entity(entityIdx).geometry();
139 entities.push_back(entityIdx);
155template<
class Geometry,
class EntitySet>
156inline std::vector<IntersectionInfo<Geometry::coorddimension, typename Geometry::ctype, typename EntitySet::ctype>>
161 static_assert(int(Geometry::coorddimension) == int(EntitySet::dimensionworld),
162 "Can only intersect geometry and bounding box tree of same world dimension");
165 std::vector<IntersectionInfo<Geometry::coorddimension, typename Geometry::ctype, typename EntitySet::ctype>> intersections;
167 static constexpr int dimworld = Geometry::coorddimension;
170 std::array<ctype, 2*Geometry::coorddimension> bBox;
171 ctype* xMin = bBox.data(); ctype* xMax = xMin + Geometry::coorddimension;
174 auto corner = geometry.corner(0);
175 for (std::size_t dimIdx = 0; dimIdx < dimworld; ++dimIdx)
176 xMin[dimIdx] = xMax[dimIdx] = corner[dimIdx];
179 for (std::size_t cornerIdx = 1; cornerIdx < geometry.corners(); ++cornerIdx)
181 corner = geometry.corner(cornerIdx);
182 for (std::size_t dimIdx = 0; dimIdx < dimworld; ++dimIdx)
186 xMin[dimIdx] = min(xMin[dimIdx], corner[dimIdx]);
187 xMax[dimIdx] = max(xMax[dimIdx], corner[dimIdx]);
196 return intersections;
203template<
class Geometry,
class EntitySet>
206 const std::array<typename Geometry::ctype, 2*Geometry::coorddimension>& bBox,
209 typename Geometry::ctype,
210 typename EntitySet::ctype>>& intersections)
213 static constexpr int dimworld = Geometry::coorddimension;
221 if (tree.
isLeaf(bBoxNode, nodeIdx))
224 const auto eIdxA = 0;
225 const auto eIdxB = bBoxNode.child1;
227 const auto geometryTree = tree.
entitySet().entity(eIdxB).geometry();
228 using GeometryTree = std::decay_t<
decltype(geometryTree)>;
231 using Intersection =
typename IntersectionAlgorithm::Intersection;
232 Intersection intersection;
234 if (IntersectionAlgorithm::intersection(geometry, geometryTree, intersection))
236 static constexpr int dimIntersection = Policy::dimIntersection;
237 if (dimIntersection >= 2)
239 const auto triangulation = triangulate<dimIntersection, dimworld>(intersection);
240 for (
unsigned int i = 0; i < triangulation.size(); ++i)
241 intersections.emplace_back(eIdxA, eIdxB, std::move(triangulation[i]));
244 intersections.emplace_back(eIdxA, eIdxB, intersection);
260template<
class EntitySet0,
class EntitySet1>
261inline std::vector<IntersectionInfo<EntitySet0::dimensionworld, typename EntitySet0::ctype, typename EntitySet1::ctype>>
266 static_assert(int(EntitySet0::dimensionworld) == int(EntitySet1::dimensionworld),
267 "Can only intersect bounding box trees of same world dimension");
270 std::vector<IntersectionInfo<EntitySet0::dimensionworld, typename EntitySet0::ctype, typename EntitySet1::ctype>> intersections;
278 return intersections;
285template<
class EntitySet0,
class EntitySet1>
288 std::size_t nodeA, std::size_t nodeB,
290 typename EntitySet0::ctype,
291 typename EntitySet1::ctype>>& intersections)
298 static constexpr int dimworld = EntitySet0::dimensionworld;
304 const bool isLeafA = treeA.
isLeaf(bBoxA, nodeA);
305 const bool isLeafB = treeB.
isLeaf(bBoxB, nodeB);
308 if (isLeafA && isLeafB)
310 const auto eIdxA = bBoxA.child1;
311 const auto eIdxB = bBoxB.child1;
313 const auto geometryA = treeA.
entitySet().entity(eIdxA).geometry();
314 const auto geometryB = treeB.
entitySet().entity(eIdxB).geometry();
316 using GeometryA = std::decay_t<
decltype(geometryA)>;
317 using GeometryB = std::decay_t<
decltype(geometryB)>;
320 using Intersection =
typename IntersectionAlgorithm::Intersection;
321 Intersection intersection;
323 if (IntersectionAlgorithm::intersection(geometryA, geometryB, intersection))
325 static constexpr int dimIntersection = Policy::dimIntersection;
327 if (dimIntersection >= 2)
329 const auto triangulation = triangulate<dimIntersection, dimworld>(intersection);
330 for (
unsigned int i = 0; i < triangulation.size(); ++i)
331 intersections.emplace_back(eIdxA, eIdxB, std::move(triangulation[i]));
334 intersections.emplace_back(eIdxA, eIdxB, intersection);
354 else if (nodeA > nodeB)
An axis-aligned bounding box volume hierarchy for dune grids.
Detect if a point intersects a geometry.
Functionality to triangulate point clouds.
A class for collision detection of two geometries and computation of intersection corners.
Define some often used mathematical functions.
bool intersectsPointGeometry(const Dune::FieldVector< ctype, dimworld > &point, const Geometry &g)
Find out whether a point is inside a three-dimensional geometry.
Definition: intersectspointgeometry.hh:38
std::vector< std::size_t > intersectingEntities(const Dune::FieldVector< ctype, dimworld > &point, const BoundingBoxTree< EntitySet > &tree, bool isCartesianGrid=false)
Compute all intersections between entities and a point.
Definition: intersectingentities.hh:99
bool intersectsPointBoundingBox(const Dune::FieldVector< ctype, dimworld > &point, const ctype *b)
Check whether a point is intersectin a bounding box (dimworld == 3)
Definition: boundingboxtree.hh:304
typename DefaultPolicyChooser< Geometry1, Geometry2 >::type DefaultPolicy
Helper alias to define the default intersection policy.
Definition: geometryintersection.hh:114
An axis-aligned bounding box volume tree implementation.
Definition: boundingboxtree.hh:66
const ctype * getBoundingBoxCoordinates(std::size_t nodeIdx) const
Get an existing bounding box for a given node.
Definition: boundingboxtree.hh:145
bool isLeaf(const BoundingBoxNode &node, std::size_t nodeIdx) const
Definition: boundingboxtree.hh:154
const EntitySet & entitySet() const
the entity set this tree was built with
Definition: boundingboxtree.hh:133
std::size_t numBoundingBoxes() const
Get the number of bounding boxes currently in the tree.
Definition: boundingboxtree.hh:149
const BoundingBoxNode & getBoundingBoxNode(std::size_t nodeIdx) const
Interface to be used by other bounding box trees.
Definition: boundingboxtree.hh:141
A class for geometry collision detection and intersection calculation The class can be specialized fo...
Definition: geometryintersection.hh:217
An intersection object resulting from the intersection of two primitives in an entity set.
Definition: intersectingentities.hh:46
static constexpr int dimensionworld
Definition: intersectingentities.hh:49
bool cornersMatch(const std::vector< GlobalPosition > &otherCorners) const
Check if the corners of this intersection match with the given corners.
Definition: intersectingentities.hh:75
IntersectionInfo(std::size_t a, std::size_t b, Corners &&c)
Definition: intersectingentities.hh:53
Dune::FieldVector< ctype, dimworld > GlobalPosition
Definition: intersectingentities.hh:50
std::vector< GlobalPosition > corners() const
Get the corners of the intersection geometry.
Definition: intersectingentities.hh:68
std::size_t second() const
Get the index of the intersecting entity belonging to the other grid.
Definition: intersectingentities.hh:64
std::size_t first() const
Get the index of the intersecting entity belonging to this grid.
Definition: intersectingentities.hh:60
typename Dune::PromotionTraits< CoordTypeA, CoordTypeB >::PromotedType ctype
Definition: intersectingentities.hh:48