libMesh
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
libMesh::TriangulatorInterface::Hole Class Referenceabstract

An abstract class for defining a 2-dimensional hole. More...

#include <mesh_triangle_holes.h>

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

Public Member Functions

 Hole ()=default
 Constructor. More...
 
virtual ~Hole ()=default
 Destructor. More...
 
virtual unsigned int n_points () const =0
 The number of geometric points which define 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 point (const unsigned int n) const =0
 Return the nth point 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...
 
virtual Point inside () const =0
 Return an (arbitrary) point which lies inside 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...
 

Detailed Description

An abstract class for defining a 2-dimensional hole.

We assume that the connectivity of the hole is implicit in the numbering of the points, controlled by segment_indices vector. The size of segment_indices is equal to the number of segments plus one. Each segment has segment_indices[i+1]-segment_indices[i] connected points, with node segment_indices[i] is connected to node segment_indices[i+1], node segment_indices[i+1] is connected to node segment_indices[i+2], etc, and the last node "wraps around" to connect back to node segment_indices[i].

Author
John W. Peterson
Date
2011 Class for parameterizing 2D holes to be meshed with Triangle.

Definition at line 48 of file mesh_triangle_holes.h.

Constructor & Destructor Documentation

◆ Hole()

libMesh::TriangulatorInterface::Hole::Hole ( )
default

Constructor.

◆ ~Hole()

virtual libMesh::TriangulatorInterface::Hole::~Hole ( )
virtualdefault

Destructor.

Member Function Documentation

◆ area()

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

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 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

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 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
protected

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

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
protected

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()

virtual Point libMesh::TriangulatorInterface::Hole::inside ( ) const
pure virtual

◆ midpoint()

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

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
inlinevirtual

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()

virtual unsigned int libMesh::TriangulatorInterface::Hole::n_points ( ) const
pure virtual

◆ point()

virtual Point libMesh::TriangulatorInterface::Hole::point ( const unsigned int  n) const
pure virtual

◆ refine_boundary_allowed()

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

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 _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
inlinevirtual

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 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)
inlinevirtual

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 _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

◆ _refine_bdy_allowed

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

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 refine_boundary_allowed(), and set_refine_boundary_allowed().


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