Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup Geometry | ||
10 | * \brief Detect if a point intersects a geometry | ||
11 | */ | ||
12 | #ifndef DUMUX_GEOMETRY_INTERSECTS_POINT_GEOMETRY_HH | ||
13 | #define DUMUX_GEOMETRY_INTERSECTS_POINT_GEOMETRY_HH | ||
14 | |||
15 | #include <cmath> | ||
16 | #include <dune/common/exceptions.hh> | ||
17 | #include <dune/common/fvector.hh> | ||
18 | |||
19 | #include <dumux/geometry/intersectspointsimplex.hh> | ||
20 | |||
21 | namespace Dumux { | ||
22 | |||
23 | /*! | ||
24 | * \ingroup Geometry | ||
25 | * \brief Find out whether a point is inside a three-dimensional geometry | ||
26 | */ | ||
27 | template <class ctype, int dimworld, class Geometry, typename std::enable_if_t<(Geometry::mydimension == 3), int> = 0> | ||
28 | 610392 | bool intersectsPointGeometry(const Dune::FieldVector<ctype, dimworld>& point, const Geometry& g) | |
29 | { | ||
30 | // get the g type | ||
31 |
2/2✓ Branch 0 taken 24751 times.
✓ Branch 1 taken 20188 times.
|
610392 | const auto type = g.type(); |
32 | |||
33 | // if it's a tetrahedron we can check directly | ||
34 |
2/3✓ Branch 0 taken 18188 times.
✓ Branch 1 taken 26031 times.
✗ Branch 2 not taken.
|
609672 | if (type.isTetrahedron()) |
35 | 24878 | return intersectsPointSimplex(point, g.corner(0), g.corner(1), g.corner(2), g.corner(3)); | |
36 | |||
37 | // split hexahedrons into five tetrahedrons | ||
38 |
2/2✓ Branch 0 taken 1052 times.
✓ Branch 1 taken 960 times.
|
552238 | else if (type.isHexahedron()) |
39 | { | ||
40 |
5/5✓ Branch 5 taken 25956 times.
✓ Branch 6 taken 21860 times.
✓ Branch 1 taken 39186 times.
✓ Branch 2 taken 284270 times.
✓ Branch 4 taken 4007 times.
|
2079203 | if (intersectsPointSimplex(point, g.corner(0), g.corner(1), g.corner(3), g.corner(5))) return true; |
41 |
5/5✓ Branch 5 taken 20260 times.
✓ Branch 6 taken 17439 times.
✓ Branch 1 taken 38982 times.
✓ Branch 2 taken 245288 times.
✓ Branch 4 taken 4173 times.
|
1820935 | if (intersectsPointSimplex(point, g.corner(0), g.corner(5), g.corner(6), g.corner(4))) return true; |
42 |
5/5✓ Branch 5 taken 14836 times.
✓ Branch 6 taken 13999 times.
✓ Branch 1 taken 39492 times.
✓ Branch 2 taken 205796 times.
✓ Branch 4 taken 4443 times.
|
1581127 | if (intersectsPointSimplex(point, g.corner(5), g.corner(3), g.corner(6), g.corner(7))) return true; |
43 |
5/5✓ Branch 5 taken 10600 times.
✓ Branch 6 taken 10455 times.
✓ Branch 1 taken 38436 times.
✓ Branch 2 taken 167360 times.
✓ Branch 4 taken 4340 times.
|
1347602 | if (intersectsPointSimplex(point, g.corner(0), g.corner(3), g.corner(2), g.corner(6))) return true; |
44 |
5/5✓ Branch 5 taken 3556 times.
✓ Branch 6 taken 6899 times.
✓ Branch 1 taken 59417 times.
✓ Branch 2 taken 107943 times.
✓ Branch 4 taken 7056 times.
|
1125672 | if (intersectsPointSimplex(point, g.corner(5), g.corner(3), g.corner(0), g.corner(6))) return true; |
45 | return false; | ||
46 | } | ||
47 | |||
48 | // split pyramids into two tetrahedrons | ||
49 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 960 times.
|
984 | else if (type.isPyramid()) |
50 | { | ||
51 |
2/3✓ Branch 5 taken 640 times.
✓ Branch 6 taken 400 times.
✗ Branch 4 not taken.
|
1040 | if (intersectsPointSimplex(point, g.corner(0), g.corner(1), g.corner(2), g.corner(4))) return true; |
52 |
2/3✓ Branch 5 taken 160 times.
✓ Branch 6 taken 240 times.
✗ Branch 4 not taken.
|
400 | if (intersectsPointSimplex(point, g.corner(1), g.corner(3), g.corner(2), g.corner(4))) return true; |
53 | return false; | ||
54 | } | ||
55 | |||
56 | // split prisms into three tetrahedrons | ||
57 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
24 | else if (type.isPrism()) |
58 | { | ||
59 |
3/3✓ Branch 5 taken 486 times.
✓ Branch 6 taken 480 times.
✓ Branch 4 taken 6 times.
|
984 | if (intersectsPointSimplex(point, g.corner(0), g.corner(1), g.corner(2), g.corner(4))) return true; |
60 |
3/3✓ Branch 5 taken 160 times.
✓ Branch 6 taken 320 times.
✓ Branch 4 taken 6 times.
|
492 | if (intersectsPointSimplex(point, g.corner(3), g.corner(0), g.corner(2), g.corner(4))) return true; |
61 |
2/3✓ Branch 5 taken 160 times.
✓ Branch 6 taken 160 times.
✗ Branch 4 not taken.
|
320 | if (intersectsPointSimplex(point, g.corner(2), g.corner(5), g.corner(3), g.corner(4))) return true; |
62 | return false; | ||
63 | } | ||
64 | |||
65 | else | ||
66 | ✗ | DUNE_THROW(Dune::NotImplemented, | |
67 | "Intersection for point and geometry type " | ||
68 | << type << " in " << dimworld << "-dimensional world."); | ||
69 | } | ||
70 | |||
71 | /*! | ||
72 | * \ingroup Geometry | ||
73 | * \brief Find out whether a point is inside a two-dimensional geometry | ||
74 | */ | ||
75 | template <class ctype, int dimworld, class Geometry, typename std::enable_if_t<(Geometry::mydimension == 2), int> = 0> | ||
76 | 1977406 | bool intersectsPointGeometry(const Dune::FieldVector<ctype, dimworld>& point, const Geometry& g) | |
77 | { | ||
78 | // get the g type | ||
79 |
2/2✓ Branch 0 taken 286225 times.
✓ Branch 1 taken 10164 times.
|
1977406 | const auto type = g.type(); |
80 | |||
81 | // if it's a triangle we can check directly | ||
82 |
1/3✓ Branch 1 taken 10168 times.
✗ Branch 2 not taken.
✗ Branch 0 not taken.
|
1910518 | if (type.isTriangle()) |
83 | 347489 | return intersectsPointSimplex(point, g.corner(0), g.corner(1), g.corner(2)); | |
84 | |||
85 | // split quadrilaterals into two triangles | ||
86 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
1618213 | else if (type.isQuadrilateral()) |
87 | { | ||
88 |
6/6✓ Branch 2 taken 43628 times.
✓ Branch 3 taken 113 times.
✓ Branch 0 taken 415721 times.
✓ Branch 1 taken 1151447 times.
✓ Branch 4 taken 7016 times.
✓ Branch 5 taken 3156 times.
|
4770269 | if (intersectsPointSimplex(point, g.corner(0), g.corner(1), g.corner(3))) return true; |
89 |
6/6✓ Branch 2 taken 40299 times.
✓ Branch 3 taken 44 times.
✓ Branch 0 taken 230215 times.
✓ Branch 1 taken 922036 times.
✓ Branch 4 taken 1952 times.
✓ Branch 5 taken 5028 times.
|
3510801 | if (intersectsPointSimplex(point, g.corner(0), g.corner(3), g.corner(2))) return true; |
90 | return false; | ||
91 | } | ||
92 | |||
93 | else | ||
94 | ✗ | DUNE_THROW(Dune::NotImplemented, | |
95 | "Intersection for point and geometry type " | ||
96 | << type << " in " << dimworld << "-dimensional world."); | ||
97 | } | ||
98 | |||
99 | /*! | ||
100 | * \ingroup Geometry | ||
101 | * \brief Find out whether a point is inside a one-dimensional geometry | ||
102 | */ | ||
103 | template <class ctype, int dimworld, class Geometry, typename std::enable_if_t<(Geometry::mydimension == 1), int> = 0> | ||
104 |
1/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
261844 | bool intersectsPointGeometry(const Dune::FieldVector<ctype, dimworld>& point, const Geometry& g) |
105 | { | ||
106 |
1/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
261844 | return intersectsPointSimplex(point, g.corner(0), g.corner(1)); |
107 | } | ||
108 | |||
109 | } // end namespace Dumux | ||
110 | |||
111 | #endif | ||
112 |