22#ifndef DUMUX_TRIANGULATION_HH
23#define DUMUX_TRIANGULATION_HH
30#include <dune/common/exceptions.hh>
31#include <dune/common/fvector.hh>
36namespace TriangulationPolicy {
45template<
int dim,
int dimWorld>
51template<
int dim,
int dimWorld,
class ctype>
52using Triangulation = std::vector< std::array<Dune::FieldVector<ctype, dimWorld>, dim+1> >;
65template<
int dim,
int dimWorld,
class Policy = TriangulationPolicy::DefaultPolicy<dim, dimWorld>,
66 class RandomAccessContainer,
67 std::enable_if_t< std::is_same<Policy, TriangulationPolicy::M
idPo
intPolicy>::value
68 && dim == 2,
int> = 0 >
72 using ctype =
typename RandomAccessContainer::value_type::value_type;
73 using Point = Dune::FieldVector<ctype, dimWorld>;
74 using Triangle = std::array<Point, 3>;
76 static_assert(std::is_same<typename RandomAccessContainer::value_type, Point>::value,
77 "Triangulation expects Dune::FieldVector as point type");
79 if (convexHull.size() < 3)
80 DUNE_THROW(Dune::InvalidStateException,
"Try to triangulate point cloud with less than 3 points!");
82 if (convexHull.size() == 3)
83 return std::vector<Triangle>(1, {convexHull[0], convexHull[1], convexHull[2]});
86 for (
const auto p : convexHull)
88 midPoint /= convexHull.size();
90 std::vector<Triangle> triangulation;
91 triangulation.reserve(convexHull.size());
93 for (std::size_t i = 0; i < convexHull.size()-1; ++i)
94 triangulation.emplace_back(Triangle{midPoint, convexHull[i], convexHull[i+1]});
96 triangulation.emplace_back(Triangle{midPoint, convexHull[convexHull.size()-1], convexHull[0]});
111template<
int dim,
int dimWorld,
class Policy = TriangulationPolicy::DefaultPolicy<dim, dimWorld>,
112 class RandomAccessContainer,
113 std::enable_if_t< std::is_same<Policy, TriangulationPolicy::DelaunayPolicy>::value
114 && dim == 1,
int> = 0 >
115inline Triangulation<dim, dimWorld, typename RandomAccessContainer::value_type::value_type>
118 using ctype =
typename RandomAccessContainer::value_type::value_type;
119 using Point = Dune::FieldVector<ctype, dimWorld>;
121 static_assert(std::is_same<typename RandomAccessContainer::value_type, Point>::value,
122 "Triangulation expects Dune::FieldVector as point type");
124 if (points.size() == 2)
125 return Triangulation<dim, dimWorld, ctype>({ {points[0], points[1]} });
128 assert(points.size() > 1);
129 DUNE_THROW(Dune::NotImplemented,
"1d triangulation for point cloud size > 2");
Define some often used mathematical functions.
Triangulation< dim, dimWorld, typename RandomAccessContainer::value_type::value_type > triangulate(const RandomAccessContainer &convexHull)
Triangulate area given points of a convex hull.
Definition: triangulation.hh:70
std::vector< std::array< Dune::FieldVector< ctype, dimWorld >, dim+1 > > Triangulation
The data type to store triangulations.
Definition: triangulation.hh:52
std::conditional_t< dim >=2, MidPointPolicy, DelaunayPolicy > DefaultPolicy
Definition: triangulation.hh:46
Definition: triangulation.hh:40
Delaunay-type triangulations.
Definition: triangulation.hh:43