22#ifndef DUMUX_GEOMETRY_DISTANCE_HH
23#define DUMUX_GEOMETRY_DISTANCE_HH
25#include <dune/common/fvector.hh>
26#include <dune/geometry/quadraturerules.hh>
34template<
class Geometry>
35inline typename Geometry::ctype
37 const Geometry& geometry,
38 std::size_t integrationOrder = 2)
40 typename Geometry::ctype avgDist = 0.0;
41 const auto& quad = Dune::QuadratureRules<typename Geometry::ctype, Geometry::mydimension>::rule(geometry.type(), integrationOrder);
42 for (
const auto& qp : quad)
43 avgDist += (geometry.global(qp.position())-p).two_norm()*qp.weight()*geometry.integrationElement(qp.position());
44 return avgDist/geometry.volume();
52inline typename Point::value_type
55 const auto ab = b - a;
56 const auto t = (p - a)*ab/ab.two_norm2();
59 return (proj - p).two_norm();
68template<
class Geometry>
69inline typename Geometry::ctype
72 static_assert(Geometry::mydimension == 1,
"Geometry has to be a line");
73 const auto& a = geometry.corner(0);
74 const auto& b = geometry.corner(1);
83inline typename Point::value_type
86 const auto ab = b - a;
90 return (a - p).two_norm();
92 const auto lengthSq = ab.two_norm2();
94 return (b - p).two_norm();
97 proj.axpy(t/lengthSq, ab);
98 return (proj - p).two_norm();
105template<
class Geometry>
106inline typename Geometry::ctype
109 static_assert(Geometry::mydimension == 1,
"Geometry has to be a segment");
110 const auto& a = geometry.corner(0);
111 const auto& b = geometry.corner(1);
119template<
class Geometry>
120inline typename Geometry::ctype
122 const typename Geometry::GlobalCoordinate& b,
123 const Geometry& geometry,
124 std::size_t integrationOrder = 2)
126 typename Geometry::ctype avgDist = 0.0;
127 const auto& quad = Dune::QuadratureRules<typename Geometry::ctype, Geometry::mydimension>::rule(geometry.type(), integrationOrder);
128 for (
const auto& qp : quad)
129 avgDist +=
distancePointSegment(geometry.global(qp.position()), a, b)*qp.weight()*geometry.integrationElement(qp.position());
130 return avgDist/geometry.volume();
137template<
class ctype,
int dimWorld>
138inline ctype
distance(
const Dune::FieldVector<ctype, dimWorld>& a,
139 const Dune::FieldVector<ctype, dimWorld>& b)
140{
return (a-b).two_norm(); }
147template<
class Geo1,
class Geo2,
148 int dimWorld = Geo1::coorddimension,
149 int dim1 = Geo1::mydimension,
int dim2 = Geo2::mydimension>
152 static_assert(Geo1::coorddimension == Geo2::coorddimension,
"Geometries have to have the same coordinate dimensions");
153 static auto distance(
const Geo1& geo1,
const Geo2& geo2)
155 DUNE_THROW(Dune::NotImplemented,
"Geometry distance computation not implemented for dimworld = "
156 << dimWorld <<
", dim1 = " << dim1 <<
", dim2 = " << dim2);
161template<
class Geo1,
class Geo2,
int dimWorld>
164 static_assert(Geo1::coorddimension == Geo2::coorddimension,
"Geometries have to have the same coordinate dimensions");
165 static auto distance(
const Geo1& geo1,
const Geo2& geo2)
170template<
class Geo1,
class Geo2,
int dimWorld>
173 static_assert(Geo1::coorddimension == Geo2::coorddimension,
"Geometries have to have the same coordinate dimensions");
174 static auto distance(
const Geo1& geo1,
const Geo2& geo2)
179template<
class Geo1,
class Geo2,
int dimWorld>
182 static_assert(Geo1::coorddimension == Geo2::coorddimension,
"Geometries have to have the same coordinate dimensions");
183 static auto distance(
const Geo1& geo1,
const Geo2& geo2)
193template<
class Geo1,
class Geo2>
194inline auto distance(
const Geo1& geo1,
const Geo2& geo2)
Geometry::ctype averageDistanceSegmentGeometry(const typename Geometry::GlobalCoordinate &a, const typename Geometry::GlobalCoordinate &b, const Geometry &geometry, std::size_t integrationOrder=2)
Compute the average distance from a segment to a geometry by integration.
Definition: geometry/distance.hh:121
Geometry::ctype averageDistancePointGeometry(const typename Geometry::GlobalCoordinate &p, const Geometry &geometry, std::size_t integrationOrder=2)
Compute the average distance from a point to a geometry by integration.
Definition: geometry/distance.hh:36
Point::value_type distancePointLine(const Point &p, const Point &a, const Point &b)
Compute the distance from a point to a line through the points a and b.
Definition: geometry/distance.hh:53
Point::value_type distancePointSegment(const Point &p, const Point &a, const Point &b)
Compute the distance from a point to the segment connecting the points a and b.
Definition: geometry/distance.hh:84
ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: geometry/distance.hh:138
Definition: geometry/distance.hh:151
static auto distance(const Geo1 &geo1, const Geo2 &geo2)
Definition: geometry/distance.hh:153
static auto distance(const Geo1 &geo1, const Geo2 &geo2)
Definition: geometry/distance.hh:165
static auto distance(const Geo1 &geo1, const Geo2 &geo2)
Definition: geometry/distance.hh:174
static auto distance(const Geo1 &geo1, const Geo2 &geo2)
Definition: geometry/distance.hh:183