libMesh
mesh_triangle_holes.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 #ifndef LIBMESH_MESH_TRIANGLE_HOLES_H
19 #define LIBMESH_MESH_TRIANGLE_HOLES_H
20 
21 #include "libmesh/libmesh_config.h"
22 
23 // Local includes
24 #include "libmesh/boundary_info.h" // invalid_id
25 #include "libmesh/point.h"
26 #include "libmesh/triangulator_interface.h"
27 #include "libmesh/vector_value.h"
28 
29 // C++ includes
30 
31 namespace libMesh
32 {
33 
49 {
50 public:
54  Hole() = default;
55 
59  virtual ~Hole() = default;
60 
64  virtual unsigned int n_points() const = 0;
65 
69  virtual Point point(const unsigned int n) const = 0;
70 
74  virtual Point inside() const = 0;
75 
79  bool contains(Point p) const;
80 
84  Real area() const;
85 
91  RealGradient areavec() const;
92 
96  virtual std::vector<unsigned int> segment_indices() const
97  {
98  // default to only one enclosing boundary
99  std::vector<unsigned int> seg;
100  seg.push_back(0);
101  seg.push_back(n_points());
102  return seg;
103  }
104 
111  virtual void set_refine_boundary_allowed (bool refine_bdy_allowed)
112  { _refine_bdy_allowed = refine_bdy_allowed; }
113 
118  virtual bool refine_boundary_allowed () const
119  { return _refine_bdy_allowed; }
120 
121 protected:
122 
126  std::vector<Real> find_ray_intersections(Point ray_start,
127  Point ray_target) const;
128 
133 
138  bool _refine_bdy_allowed = true;
139 };
140 
141 
142 
143 
144 
150 {
151 public:
157  PolygonHole(const Point & center, Real radius, unsigned int n_points);
158 
159  virtual unsigned int n_points() const override;
160 
161  virtual Point point(const unsigned int n) const override;
162 
163  virtual Point inside() const override;
164 
165 private:
170 
175 
181  unsigned int _n_points;
182 };
183 
184 
185 
192 {
193 public:
199  AffineHole(const Hole & underlying, Real angle, const Point & shift)
200  : _underlying(underlying), _angle(angle), _shift(shift) {}
201 
202  virtual unsigned int n_points() const override
203  { return _underlying.n_points(); }
204 
205  virtual Point point(const unsigned int n) const override;
206 
207  virtual Point inside() const override;
208 
209 private:
213  Point transform(const Point & p) const;
214 
218  const Hole & _underlying;
219 
224 
229 };
230 
231 
232 
233 
234 
243 {
244 public:
250  ArbitraryHole(const Point & center,
251  std::vector<Point> points);
252 
253  ArbitraryHole(const Point & center,
254  std::vector<Point> points,
255  std::vector<unsigned int> segment_indices);
256 
260  ArbitraryHole(std::vector<Point> points);
261 
266  ArbitraryHole(const Hole & orig);
267 
268  ArbitraryHole(const ArbitraryHole & orig) = default;
269 
270  virtual unsigned int n_points() const override;
271 
272  virtual Point point(const unsigned int n) const override;
273 
274  virtual Point inside() const override;
275 
276  virtual std::vector<unsigned int> segment_indices() const override;
277 
278  const std::vector<Point> & get_points() const
279  {
280  return _points;
281  }
282 
283  void set_points(std::vector<Point> points)
284  {
285  _points = std::move(points);
287  }
288 
289 private:
294 
299  std::vector<Point> _points;
300 
301  std::vector<unsigned int> _segment_indices;
302 };
303 
304 
305 
322 {
323 public:
328  MeshedHole(const MeshBase & mesh,
329  std::set<std::size_t> ids = {});
330 
331  virtual unsigned int n_points() const override;
332 
333  virtual Point point(const unsigned int n) const override;
334 
335  virtual Point inside() const override;
336 
337 private:
343  mutable Point _center;
344 
348  std::vector<Point> _points;
349 };
350 
351 
352 
353 
354 
355 
360 {
361 public:
365  Region(const Point & center,
366  Real attribute = 0,
367  Real max_area = -std::numeric_limits<Real>::max())
368  : _center(center),
370  _max_area(max_area) {}
371 
372  Point inside() const { return _center; }
373 
374  Real attribute() const { return _attribute; }
375 
376  Real max_area() const { return _max_area; }
377 
378 private:
382  const Point _center;
383 
389 
395 };
396 
397 } // namespace libMesh
398 
399 #endif // LIBMESH_MESH_TRIANGLE_HOLES_H
bool _refine_bdy_allowed
Whether to allow boundary refinement.
AffineHole(const Hole &underlying, Real angle, const Point &shift)
Constructor specifying the underlying hole, and the rotation angle (in radians, done first) and trans...
virtual Point point(const unsigned int n) const override
Return the nth point defining the hole.
std::vector< Point > _points
The sorted vector of points which makes up the hole.
const Real radius
virtual unsigned int n_points() const override
The number of geometric points which define the hole.
An abstract class for defining a 2-dimensional hole.
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
ArbitraryHole(const Point &center, std::vector< Point > points)
The fastest constructor requires a point which lies in the interior of the hole and a reference to a ...
unsigned int _n_points
number of points used to describe the hole.
std::vector< Real > find_ray_intersections(Point ray_start, Point ray_target) const
Helper function for contains(), also useful for MeshedHole::inside()
Real area() const
Return the area of the hole.
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
virtual unsigned int n_points() const override
The number of geometric points which define the hole.
virtual Point inside() const override
Return an (arbitrary) point which lies inside the hole.
MeshedHole(const MeshBase &mesh, std::set< std::size_t > ids={})
The constructor requires a mesh defining the hole, and optionally boundary+subdomain ids restricting ...
This is the MeshBase class.
Definition: mesh_base.h:74
virtual Point inside() const override
Return an (arbitrary) point which lies inside the hole.
Point transform(const Point &p) const
Rotate-and-shift equations.
A way to translate and/or rotate an existing hole; perhaps to tile it in many places or to put it at ...
virtual unsigned int n_points() const override
The number of geometric points which define the hole.
Region(const Point &center, Real attribute=0, Real max_area=-std::numeric_limits< Real >::max())
Constructor.
const Point _center
Arbitrary (x,y) location inside the region.
const std::vector< Point > & get_points() const
void set_points(std::vector< Point > points)
virtual unsigned int n_points() const override
The number of geometric points which define the hole.
Point calculate_inside_point() const
Calculate an inside point based on our boundary.
const Hole & _underlying
Hole to transform.
virtual bool refine_boundary_allowed() const
Get whether or not the triangulation is allowed to refine the mesh boundary when refining the interio...
virtual std::vector< unsigned int > segment_indices() const override
Starting indices of points for a hole with multiple disconnected boundaries.
Real _attribute
Attribute of the region Default value for attribute is zero.
Real _max_area
Maximum area that is allowed for all triangles in this region Default negative maximum area means tha...
bool contains(Point p) const
Return true iff p lies inside the hole.
Point _center
(x,y) location of the center of the hole
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Point point(const unsigned int n) const override
Return the nth point defining the hole.
A class for defining a 2-dimensional region for Triangle.
Another concrete instantiation of the hole, as general as ArbitraryHole, but based on an existing 1D ...
virtual void set_refine_boundary_allowed(bool refine_bdy_allowed)
Set whether or not a triangulator is allowed to refine the hole boundary when refining the mesh inter...
Real _angle
Angle to rotate (counter-clockwise) by.
virtual Point inside() const override
Return an (arbitrary) point which lies inside the hole.
A concrete instantiation of the Hole class that describes polygonal (triangular, square, pentagonal, ...) holes.
virtual Point point(const unsigned int n) const override
Return the nth point defining the hole.
virtual Point inside() const override
Return an (arbitrary) point which lies inside the hole.
virtual Point point(const unsigned int n) const override
Return the nth point defining the hole.
Another concrete instantiation of the hole, this one should be sufficiently general for most non-poly...
RealGradient areavec() const
Return a vector with right-hand-rule orientation and length of twice area() squared.
virtual ~Hole()=default
Destructor.
Point _center
arbitrary (x,y) location inside the hole
Point _shift
(x,y) location to shift (0,0) to
virtual std::vector< unsigned int > segment_indices() const
Starting indices of points for a hole with multiple disconnected boundaries.
virtual Point point(const unsigned int n) const =0
Return the nth point defining the hole.
PolygonHole(const Point &center, Real radius, unsigned int n_points)
Constructor specifying the center, radius, and number of points which comprise the hole...
Point _center
An (x,y) location inside the hole.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual Point inside() const =0
Return an (arbitrary) point which lies inside the hole.
virtual unsigned int n_points() const =0
The number of geometric points which define the hole.