libMesh
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
libMesh::TriangulatorInterface::PolygonHole Class Reference

A concrete instantiation of the Hole class that describes polygonal (triangular, square, pentagonal, ...) holes. More...

#include <mesh_triangle_holes.h>

Inheritance diagram for libMesh::TriangulatorInterface::PolygonHole:
[legend]

Public Member Functions

 PolygonHole (const Point &center, Real radius, unsigned int n_points)
 Constructor specifying the center, radius, and number of points which comprise the hole. More...
 
virtual unsigned int n_points () const override
 The number of geometric points which define the hole. More...
 
virtual Point point (const unsigned int n) const override
 Return the nth point defining the hole. More...
 
virtual Point inside () const override
 Return an (arbitrary) point which lies inside the hole. More...
 
virtual unsigned int n_midpoints () const
 The number of geometric midpoints along each of the sides defining the hole. More...
 
virtual Point midpoint (const unsigned int, const unsigned int) const
 Return the midpoint m along the side n defining the hole. More...
 
bool contains (Point p) const
 Return true iff p lies inside the hole. More...
 
Real area () const
 Return the area of the hole. More...
 
RealGradient areavec () const
 Return a vector with right-hand-rule orientation and length of twice area() squared. More...
 
virtual std::vector< unsigned intsegment_indices () const
 Starting indices of points for a hole with multiple disconnected boundaries. More...
 
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 interior. More...
 
virtual bool refine_boundary_allowed () const
 Get whether or not the triangulation is allowed to refine the mesh boundary when refining the interior. More...
 

Protected Member Functions

std::vector< Realfind_ray_intersections (Point ray_start, Point ray_target) const
 Helper function for contains(), also useful for MeshedHole::inside() More...
 
Point calculate_inside_point () const
 Calculate an inside point based on our boundary. More...
 

Protected Attributes

bool _refine_bdy_allowed = true
 Whether to allow boundary refinement. More...
 

Private Attributes

Point _center
 (x,y) location of the center of the hole More...
 
Real _radius
 circular hole radius More...
 
unsigned int _n_points
 number of points used to describe the hole. More...
 

Detailed Description

A concrete instantiation of the Hole class that describes polygonal (triangular, square, pentagonal, ...) holes.

Definition at line 171 of file mesh_triangle_holes.h.

Constructor & Destructor Documentation

◆ PolygonHole()

libMesh::TriangulatorInterface::PolygonHole::PolygonHole ( const Point center,
Real  radius,
unsigned int  n_points 
)

Constructor specifying the center, radius, and number of points which comprise the hole.

The points will all lie on a circle of radius r.

Definition at line 323 of file mesh_triangle_holes.C.

325  :
326  _center(center),
327  _radius(radius),
328  _n_points(n_points_in)
329 {}
const Real radius
unsigned int _n_points
number of points used to describe the hole.
Point _center
(x,y) location of the center of the hole

Member Function Documentation

◆ area()

Real libMesh::TriangulatorInterface::Hole::area ( ) const
inherited

Return the area of the hole.

This method currently does not take any higher-order hole geometry into account, but treats the hole as a polygon.

Definition at line 184 of file mesh_triangle_holes.C.

References libMesh::TriangulatorInterface::Hole::areavec(), and libMesh::TypeVector< T >::norm().

Referenced by libMesh::TriangulatorInterface::MeshedHole::MeshedHole(), and MeshTriangulationTest::testTriangleHoleArea().

185 {
186  return this->areavec().norm() / 2;
187 }
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:907
RealGradient areavec() const
Return a vector with right-hand-rule orientation and length of twice area() squared.

◆ areavec()

RealGradient libMesh::TriangulatorInterface::Hole::areavec ( ) const
inherited

Return a vector with right-hand-rule orientation and length of twice area() squared.

This is useful for determining orientation of non-planar or non-counter-clockwise holes.

This method currently does not take any higher-order hole geometry into account, but treats the hole as a polygon.

Definition at line 190 of file mesh_triangle_holes.C.

References libMesh::TypeVector< T >::cross().

Referenced by libMesh::TriangulatorInterface::Hole::area().

191 {
192  const unsigned int np = this->n_points();
193 
194  if (np < 3)
195  return 0;
196 
197  const Point p0 = this->point(0);
198 
199  // Every segment (p_{i-1},p_i) from i=2 on defines a triangle w.r.t.
200  // p_0. Add up the cross products of those triangles. We'll save
201  // the division by 2 and the norm for the end.
202  //
203  // Your hole points had best be coplanar, but this should work
204  // regardless of which plane they're in. If you're in the XY plane,
205  // then the standard counter-clockwise hole point ordering gives you
206  // a positive areavec(2);
207 
208  RealGradient areavec = 0;
209 
210  for (unsigned int i=2; i != np; ++i)
211  {
212  const Point e_0im = this->point(i-1) - p0,
213  e_0i = this->point(i) - p0;
214 
215  areavec += e_0i.cross(e_0im);
216  }
217 
218  return areavec;
219 }
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Definition: type_vector.h:884
RealGradient areavec() const
Return a vector with right-hand-rule orientation and length of twice area() squared.
virtual Point point(const unsigned int n) const =0
Return the nth point defining the hole.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual unsigned int n_points() const =0
The number of geometric points which define the hole.

◆ calculate_inside_point()

Point libMesh::TriangulatorInterface::Hole::calculate_inside_point ( ) const
protectedinherited

Calculate an inside point based on our boundary.

Definition at line 248 of file mesh_triangle_holes.C.

References libMesh::make_range(), and libMesh::Real.

Referenced by libMesh::TriangulatorInterface::ArbitraryHole::ArbitraryHole(), and libMesh::TriangulatorInterface::ArbitraryHole::set_points().

249 {
250  // Start with the vertex average
251 
252  // Turns out "I'm a fully compliant C++17 compiler!" doesn't
253  // mean "I have a full C++17 standard library!"
254  // inside = std::reduce(points.begin(), points.end());
255  Point inside = 0;
256  for (auto i : make_range(this->n_points()))
257  inside += this->point(i);
258 
259  inside /= this->n_points();
260 
261  // Count the number of intersections with a ray to the right,
262  // keep track of how far they are
263  Point ray_target = inside + Point(1);
264  std::vector<Real> intersection_distances =
265  this->find_ray_intersections(inside, ray_target);
266 
267  // The vertex average isn't on the interior, and we found no
268  // intersections to the right? Try looking to the left.
269  if (!intersection_distances.size())
270  {
271  ray_target = inside - Point(1);
272  intersection_distances =
273  this->find_ray_intersections(inside, ray_target);
274  }
275 
276  // I'd make this an assert, but I'm not 100% confident we can't
277  // get here via some kind of FP error on a weird hole shape.
278  libmesh_error_msg_if
279  (!intersection_distances.size(),
280  "Can't find a center for a MeshedHole!");
281 
282  if (intersection_distances.size() % 2)
283  return inside;
284 
285  // The vertex average is outside. So go from the vertex average to
286  // the closest edge intersection, then halfway to the next-closest.
287 
288  // Find the nearest first.
289  Real min_distance = std::numeric_limits<Real>::max(),
290  second_distance = std::numeric_limits<Real>::max();
291  for (Real d : intersection_distances)
292  if (d < min_distance)
293  {
294  second_distance = min_distance;
295  min_distance = d;
296  }
297 
298  const Point ray = ray_target - inside;
299  inside += ray * (min_distance + second_distance)/2;
300 
301  return inside;
302 }
std::vector< Real > find_ray_intersections(Point ray_start, Point ray_target) const
Helper function for contains(), also useful for MeshedHole::inside()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
virtual Point point(const unsigned int n) const =0
Return the nth point defining 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.

◆ contains()

bool libMesh::TriangulatorInterface::Hole::contains ( Point  p) const
inherited

Return true iff p lies inside the hole.

This method currently does not take any higher-order hole geometry into account, but treats the hole as a polygon.

Definition at line 305 of file mesh_triangle_holes.C.

Referenced by libMesh::TriangulatorInterface::verify_holes().

306 {
307  // Count the number of intersections with a ray to the right,
308  // keep track of how far they are
309  Point ray_target = p + Point(1);
310  std::vector<Real> intersection_distances =
311  this->find_ray_intersections(p, ray_target);
312 
313  // Odd number of intersections == we're inside
314  // Even number == we're outside
315  return intersection_distances.size() % 2;
316 }
std::vector< Real > find_ray_intersections(Point ray_start, Point ray_target) const
Helper function for contains(), also useful for MeshedHole::inside()
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ find_ray_intersections()

std::vector< Real > libMesh::TriangulatorInterface::Hole::find_ray_intersections ( Point  ray_start,
Point  ray_target 
) const
protectedinherited

Helper function for contains(), also useful for MeshedHole::inside()

Definition at line 224 of file mesh_triangle_holes.C.

References libMesh::make_range(), and libMesh::Real.

226 {
227  const auto np = this->n_points();
228 
229  std::vector<Real> intersection_distances;
230 
231  for (auto i : make_range(np))
232  {
233  const Point & p0 = this->point(i),
234  & p1 = this->point((i+1)%np),
235  & p2 = this->point((i+2)%np);
236  const Real intersection_distance =
237  find_intersection(ray_start, ray_target, p0, p1, p2);
238  if (intersection_distance >= 0)
239  intersection_distances.push_back
240  (intersection_distance);
241  }
242 
243  return intersection_distances;
244 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
virtual Point point(const unsigned int n) const =0
Return the nth point defining the hole.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual unsigned int n_points() const =0
The number of geometric points which define the hole.

◆ inside()

Point libMesh::TriangulatorInterface::PolygonHole::inside ( ) const
overridevirtual

Return an (arbitrary) point which lies inside the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 349 of file mesh_triangle_holes.C.

350 {
351  // The center of the hole is definitely inside.
352  return _center;
353 }
Point _center
(x,y) location of the center of the hole

◆ midpoint()

virtual Point libMesh::TriangulatorInterface::Hole::midpoint ( const unsigned int  ,
const unsigned int   
) const
inlinevirtualinherited

Return the midpoint m along the side n defining the hole.

Reimplemented in libMesh::TriangulatorInterface::MeshedHole.

Definition at line 80 of file mesh_triangle_holes.h.

82  { libmesh_error(); /* by default holes are polygonal */ }

◆ n_midpoints()

virtual unsigned int libMesh::TriangulatorInterface::Hole::n_midpoints ( ) const
inlinevirtualinherited

The number of geometric midpoints along each of the sides defining the hole.

Reimplemented in libMesh::TriangulatorInterface::MeshedHole.

Definition at line 70 of file mesh_triangle_holes.h.

70 { return 0; }

◆ n_points()

unsigned int libMesh::TriangulatorInterface::PolygonHole::n_points ( ) const
overridevirtual

The number of geometric points which define the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 332 of file mesh_triangle_holes.C.

333 {
334  return _n_points;
335 }
unsigned int _n_points
number of points used to describe the hole.

◆ point()

Point libMesh::TriangulatorInterface::PolygonHole::point ( const unsigned int  n) const
overridevirtual

Return the nth point defining the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 338 of file mesh_triangle_holes.C.

References libMesh::pi, and libMesh::Real.

339 {
340  // The nth point lies at the angle theta = 2 * pi * n / _n_points
341  const Real theta = static_cast<Real>(n) * 2.0 * libMesh::pi / static_cast<Real>(_n_points);
342 
343  return Point(_center(0) + _radius*std::cos(theta), // x=r*cos(theta)
344  _center(1) + _radius*std::sin(theta), // y=r*sin(theta)
345  0.);
346 }
unsigned int _n_points
number of points used to describe the hole.
Point _center
(x,y) location of the center of the hole
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
const Real pi
.
Definition: libmesh.h:299

◆ refine_boundary_allowed()

virtual bool libMesh::TriangulatorInterface::Hole::refine_boundary_allowed ( ) const
inlinevirtualinherited

Get whether or not the triangulation is allowed to refine the mesh boundary when refining the interior.

True by default.

Definition at line 140 of file mesh_triangle_holes.h.

References libMesh::TriangulatorInterface::Hole::_refine_bdy_allowed.

Referenced by libMesh::Poly2TriTriangulator::is_refine_boundary_allowed(), and MeshTriangulationTest::testPoly2TriHolesInteriorRefinedBase().

141  { return _refine_bdy_allowed; }
bool _refine_bdy_allowed
Whether to allow boundary refinement.

◆ segment_indices()

virtual std::vector<unsigned int> libMesh::TriangulatorInterface::Hole::segment_indices ( ) const
inlinevirtualinherited

Starting indices of points for a hole with multiple disconnected boundaries.

Reimplemented in libMesh::TriangulatorInterface::ArbitraryHole.

Definition at line 118 of file mesh_triangle_holes.h.

References libMesh::TriangulatorInterface::Hole::n_points().

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  }
virtual unsigned int n_points() const =0
The number of geometric points which define the hole.

◆ set_refine_boundary_allowed()

virtual void libMesh::TriangulatorInterface::Hole::set_refine_boundary_allowed ( bool  refine_bdy_allowed)
inlinevirtualinherited

Set whether or not a triangulator is allowed to refine the hole boundary when refining the mesh interior.

This is true by default, but may be set to false to make the hole boundary more predictable (and so easier to stitch to other meshes) later.

Definition at line 133 of file mesh_triangle_holes.h.

References libMesh::TriangulatorInterface::Hole::_refine_bdy_allowed.

Referenced by MeshTriangulationTest::testPoly2TriHolesInteriorRefinedBase().

134  { _refine_bdy_allowed = refine_bdy_allowed; }
bool _refine_bdy_allowed
Whether to allow boundary refinement.

Member Data Documentation

◆ _center

Point libMesh::TriangulatorInterface::PolygonHole::_center
private

(x,y) location of the center of the hole

Definition at line 191 of file mesh_triangle_holes.h.

◆ _n_points

unsigned int libMesh::TriangulatorInterface::PolygonHole::_n_points
private

number of points used to describe the hole.

The actual points can be generated knowing the center and radius. For example, n_points=3 would generate a triangular hole.

Definition at line 203 of file mesh_triangle_holes.h.

◆ _radius

Real libMesh::TriangulatorInterface::PolygonHole::_radius
private

circular hole radius

Definition at line 196 of file mesh_triangle_holes.h.

◆ _refine_bdy_allowed

bool libMesh::TriangulatorInterface::Hole::_refine_bdy_allowed = true
protectedinherited

Whether to allow boundary refinement.

True by default; specified here so we can use the default constructor.

Definition at line 160 of file mesh_triangle_holes.h.

Referenced by libMesh::TriangulatorInterface::Hole::refine_boundary_allowed(), and libMesh::TriangulatorInterface::Hole::set_refine_boundary_allowed().


The documentation for this class was generated from the following files: