1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2020 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19 #include "libmesh/libmesh_config.h"
20
21 #ifdef LIBMESH_HAVE_TRIANGLE
22
23 // Local includes
24 #include "libmesh/mesh_triangle_holes.h"
25
26 namespace libMesh
27 {
28
29 //
30 // PolygonHole member functions
31 //
PolygonHole(const Point & center,Real radius,unsigned int n_points_in)32 TriangleInterface::PolygonHole::PolygonHole(const Point & center,
33 Real radius,
34 unsigned int n_points_in) :
35 _center(center),
36 _radius(radius),
37 _n_points(n_points_in)
38 {}
39
40
n_points()41 unsigned int TriangleInterface::PolygonHole::n_points() const
42 {
43 return _n_points;
44 }
45
point(const unsigned int n)46 Point TriangleInterface::PolygonHole::point(const unsigned int n) const
47 {
48 // The nth point lies at the angle theta = 2 * pi * n / _n_points
49 const Real theta = static_cast<Real>(n) * 2.0 * libMesh::pi / static_cast<Real>(_n_points);
50
51 return Point(_center(0) + _radius*std::cos(theta), // x=r*cos(theta)
52 _center(1) + _radius*std::sin(theta), // y=r*sin(theta)
53 0.);
54 }
55
inside()56 Point TriangleInterface::PolygonHole::inside() const
57 {
58 // The center of the hole is definitely inside.
59 return _center;
60 }
61
62
63 //
64 // ArbitraryHole member functions
65 //
ArbitraryHole(const Point & center,const std::vector<Point> & points)66 TriangleInterface::ArbitraryHole::ArbitraryHole(const Point & center,
67 const std::vector<Point> & points)
68 : _center(center),
69 _points(points)
70 {
71 _segment_indices.push_back(0);
72 _segment_indices.push_back(points.size());
73 }
74
ArbitraryHole(const Point & center,const std::vector<Point> & points,const std::vector<unsigned int> & segment_indices)75 TriangleInterface::ArbitraryHole::ArbitraryHole(const Point & center,
76 const std::vector<Point> & points,
77 const std::vector<unsigned int> & segment_indices)
78 : _center(center),
79 _points(points),
80 _segment_indices(segment_indices)
81 {}
82
n_points()83 unsigned int TriangleInterface::ArbitraryHole::n_points() const
84 {
85 return _points.size();
86 }
87
88
point(const unsigned int n)89 Point TriangleInterface::ArbitraryHole::point(const unsigned int n) const
90 {
91 libmesh_assert_less (n, _points.size());
92 return _points[n];
93 }
94
95
inside()96 Point TriangleInterface::ArbitraryHole::inside() const
97 {
98 return _center;
99 }
100
segment_indices()101 std::vector<unsigned int> TriangleInterface::ArbitraryHole::segment_indices() const
102 {
103 return _segment_indices;
104 }
105
106 } // namespace libMesh
107
108
109 #endif // LIBMESH_HAVE_TRIANGLE
110