3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
distancefield.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_GEOMETRY_DISTANCE_FIELD_HH
25#define DUMUX_GEOMETRY_DISTANCE_FIELD_HH
26
27#include <memory>
28#include <vector>
29#include <utility>
30
34
35namespace Dumux {
36
43template<class Geometry>
45{
46 using Point = typename Geometry::GlobalCoordinate;
47 using Scalar = typename Geometry::ctype;
50
51 class PointGeometry
52 {
53 public:
54 static constexpr int mydimension = 0;
55 static constexpr int coorddimension = Geometry::coorddimension;
56 using ctype = typename Geometry::ctype;
57
58 PointGeometry(Point&& point) : point_(std::move(point)) {}
59 const Point& corner(std::size_t i) const { assert(i == 0); return point_; }
60 std::size_t corners() const { return 1; }
61 private:
62 Point point_;
63 };
64
67
68public:
73 AABBDistanceField(const std::vector<Geometry>& geometries)
74 : tree_(std::make_unique<AABBTree>(std::make_shared<GeoSet>(geometries)))
75 {
76 std::vector<PointGeometry> points;
77 points.reserve(geometries.size());
78 for (const auto& geo : geometries)
79 {
80 auto center = geo.center();
81 points.emplace_back(std::move(center));
82 }
83
84 pointTree_ = std::make_unique<AABBTreeMidPoints>(
85 std::make_shared<PointGeoSet>(std::move(points))
86 );
87 }
88
94 std::pair<Scalar, std::size_t> distanceAndIndex(const Point& p) const
95 { return distanceAndIndex_(p); }
96
101 Scalar distance(const Point& p) const
102 { return distanceAndIndex_(p).first; }
103
104private:
105 std::pair<Scalar, std::size_t> distanceAndIndex_(const Point& p) const
106 {
107 // find a good first guess by checking the mid point tree
108 const auto minSquaredDistanceEstimate = squaredDistance(p, *pointTree_);
109
110 // find actual entity and distance to the entity's geometry
111 // we choose the distance estimate a bit larger in case it actually is already the minimum distance
112 const auto [squaredDistance, index] = closestEntity(p, *tree_, minSquaredDistanceEstimate*1.00001);
113
114 using std::sqrt;
115 return { sqrt(squaredDistance), index };
116 }
117
118 std::unique_ptr<AABBTree> tree_;
119 std::unique_ptr<AABBTreeMidPoints> pointTree_;
120};
121
128template<class Geometry>
130
131} // end namespace Dumux
132
133#endif
Helper functions for distance queries.
An axis-aligned bounding box volume hierarchy for dune grids.
An interface for a set of geometric entities.
static ctype squaredDistance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest squared distance between two points.
Definition: distance.hh:303
std::pair< ctype, std::size_t > closestEntity(const Dune::FieldVector< ctype, dimworld > &point, const BoundingBoxTree< EntitySet > &tree, ctype minSquaredDistance=std::numeric_limits< ctype >::max())
Compute the closest entity in an AABB tree to a point (index and shortest squared distance)
Definition: distance.hh:506
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition: center.hh:36
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
An axis-aligned bounding box volume tree implementation.
Definition: boundingboxtree.hh:68
Class to calculate the closest distance from a point to a given set of geometries describing the doma...
Definition: distancefield.hh:45
std::pair< Scalar, std::size_t > distanceAndIndex(const Point &p) const
Returns the distance from a point to the closest geometry on the domain's boundary,...
Definition: distancefield.hh:94
Scalar distance(const Point &p) const
Returns the distance from a point to the closest geometry on the domain's boundary.
Definition: distancefield.hh:101
AABBDistanceField(const std::vector< Geometry > &geometries)
The constructor.
Definition: distancefield.hh:73
An interface for a set of geometric entities.
Definition: geometricentityset.hh:121