libMesh
mesh_triangle_holes.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
70  virtual unsigned int n_midpoints() const { return 0; }
71 
75  virtual Point point(const unsigned int n) const = 0;
76 
80  virtual Point midpoint(const unsigned int /* m */,
81  const unsigned int /* n */) const
82  { libmesh_error(); /* by default holes are polygonal */ }
83 
87  virtual Point inside() const = 0;
88 
95  bool contains(Point p) const;
96 
103  Real area() const;
104 
113  RealGradient areavec() const;
114 
118  virtual std::vector<unsigned int> segment_indices() const
119  {
120  // default to only one enclosing boundary
121  std::vector<unsigned int> seg;
122  seg.push_back(0);
123  seg.push_back(n_points());
124  return seg;
125  }
126 
133  virtual void set_refine_boundary_allowed (bool refine_bdy_allowed)
134  { _refine_bdy_allowed = refine_bdy_allowed; }
135 
140  virtual bool refine_boundary_allowed () const
141  { return _refine_bdy_allowed; }
142 
143 protected:
144 
148  std::vector<Real> find_ray_intersections(Point ray_start,
149  Point ray_target) const;
150 
155 
160  bool _refine_bdy_allowed = true;
161 };
162 
163 
164 
165 
166 
172 {
173 public:
179  PolygonHole(const Point & center, Real radius, unsigned int n_points);
180 
181  virtual unsigned int n_points() const override;
182 
183  virtual Point point(const unsigned int n) const override;
184 
185  virtual Point inside() const override;
186 
187 private:
192 
197 
203  unsigned int _n_points;
204 };
205 
206 
207 
214 {
215 public:
221  AffineHole(const Hole & underlying, Real angle, const Point & shift)
222  : _underlying(underlying), _angle(angle), _shift(shift) {}
223 
224  virtual unsigned int n_points() const override
225  { return _underlying.n_points(); }
226 
227  virtual Point point(const unsigned int n) const override;
228 
229  virtual Point inside() const override;
230 
231 private:
235  Point transform(const Point & p) const;
236 
240  const Hole & _underlying;
241 
246 
251 };
252 
253 
254 
255 
256 
265 {
266 public:
272  ArbitraryHole(const Point & center,
273  std::vector<Point> points);
274 
275  ArbitraryHole(const Point & center,
276  std::vector<Point> points,
277  std::vector<unsigned int> segment_indices);
278 
282  ArbitraryHole(std::vector<Point> points);
283 
288  ArbitraryHole(const Hole & orig);
289 
290  ArbitraryHole(const ArbitraryHole & orig) = default;
291 
292  virtual unsigned int n_points() const override;
293 
294  virtual Point point(const unsigned int n) const override;
295 
296  virtual Point inside() const override;
297 
298  virtual std::vector<unsigned int> segment_indices() const override;
299 
300  const std::vector<Point> & get_points() const
301  {
302  return _points;
303  }
304 
305  void set_points(std::vector<Point> points)
306  {
307  _points = std::move(points);
309  }
310 
311 private:
316 
321  std::vector<Point> _points;
322 
323  std::vector<unsigned int> _segment_indices;
324 };
325 
326 
327 
344 {
345 public:
350  MeshedHole(const MeshBase & mesh,
351  std::set<std::size_t> ids = {});
352 
353  virtual unsigned int n_points() const override;
354 
355  virtual unsigned int n_midpoints() const override;
356 
357  virtual Point point(const unsigned int n) const override;
358 
359  virtual Point midpoint(const unsigned int m,
360  const unsigned int n) const override;
361 
362  virtual Point inside() const override;
363 
364 private:
370  mutable Point _center;
371 
375  std::vector<Point> _points;
376 
383  std::vector<Point> _midpoints;
384 };
385 
386 
387 
388 
389 
390 
395 {
396 public:
400  Region(const Point & center,
401  Real attribute = 0,
402  Real max_area = -std::numeric_limits<Real>::max())
403  : _center(center),
405  _max_area(max_area) {}
406 
407  Point inside() const { return _center; }
408 
409  Real attribute() const { return _attribute; }
410 
411  Real max_area() const { return _max_area; }
412 
413 private:
417  const Point _center;
418 
424 
430 };
431 
432 } // namespace libMesh
433 
434 #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.
virtual unsigned int n_midpoints() const
The number of geometric midpoints along each of the sides defining 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
virtual Point midpoint(const unsigned int, const unsigned int) const
Return the midpoint m along the side n defining the hole.
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:75
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_midpoints() const override
The number of geometric midpoints along each of the sides defining the hole.
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.
std::vector< Point > _midpoints
The sorted vector of midpoints in between points along the edges of the hole.
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.
virtual Point midpoint(const unsigned int m, const unsigned int n) const override
Return the midpoint m along the side n defining the hole.
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.