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

Another concrete instantiation of the hole, this one should be sufficiently general for most non-polygonal purposes. More...

#include <mesh_triangle_holes.h>

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

Public Member Functions

 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 vector of Points defining the hole. More...
 
 ArbitraryHole (const Point &center, std::vector< Point > points, std::vector< unsigned int > segment_indices)
 
 ArbitraryHole (std::vector< Point > points)
 If we don't know a center a priori then we can calculate one. More...
 
 ArbitraryHole (const Hole &orig)
 We can also construct an ArbitraryHole which just copies a hole of any other type. More...
 
 ArbitraryHole (const ArbitraryHole &orig)=default
 
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 std::vector< unsigned intsegment_indices () const override
 Starting indices of points for a hole with multiple disconnected boundaries. More...
 
const std::vector< Point > & get_points () const
 
void set_points (std::vector< Point > points)
 
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 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
 arbitrary (x,y) location inside the hole More...
 
std::vector< Point_points
 Reference to the vector of points which makes up the hole. More...
 
std::vector< unsigned int_segment_indices
 

Detailed Description

Another concrete instantiation of the hole, this one should be sufficiently general for most non-polygonal purposes.

The user supplies, at the time of construction, a reference to a vector of Points which defines the hole (in order of connectivity) and an arbitrary Point which lies inside the hole.

Definition at line 264 of file mesh_triangle_holes.h.

Constructor & Destructor Documentation

◆ ArbitraryHole() [1/5]

libMesh::TriangulatorInterface::ArbitraryHole::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 vector of Points defining the hole.

Definition at line 383 of file mesh_triangle_holes.C.

References _points, and _segment_indices.

385  : _center(center),
386  _points(std::move(points))
387 {
388  _segment_indices.push_back(0);
389  _segment_indices.push_back(_points.size());
390 }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
Point _center
arbitrary (x,y) location inside the hole

◆ ArbitraryHole() [2/5]

libMesh::TriangulatorInterface::ArbitraryHole::ArbitraryHole ( const Point center,
std::vector< Point points,
std::vector< unsigned int segment_indices 
)

Definition at line 393 of file mesh_triangle_holes.C.

396  : _center(center),
397  _points(std::move(points)),
399 {}
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
virtual std::vector< unsigned int > segment_indices() const override
Starting indices of points for a hole with multiple disconnected boundaries.
Point _center
arbitrary (x,y) location inside the hole

◆ ArbitraryHole() [3/5]

libMesh::TriangulatorInterface::ArbitraryHole::ArbitraryHole ( std::vector< Point points)

If we don't know a center a priori then we can calculate one.

Definition at line 402 of file mesh_triangle_holes.C.

References _center, _points, _segment_indices, and libMesh::TriangulatorInterface::Hole::calculate_inside_point().

403  : _points(std::move(points))
404 {
405  _segment_indices.push_back(0);
406  _segment_indices.push_back(_points.size());
408 }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
Point calculate_inside_point() const
Calculate an inside point based on our boundary.
Point _center
arbitrary (x,y) location inside the hole

◆ ArbitraryHole() [4/5]

libMesh::TriangulatorInterface::ArbitraryHole::ArbitraryHole ( const Hole orig)

We can also construct an ArbitraryHole which just copies a hole of any other type.

Definition at line 411 of file mesh_triangle_holes.C.

References _points, libMesh::make_range(), libMesh::TriangulatorInterface::Hole::n_points(), and libMesh::TriangulatorInterface::Hole::point().

412  : _center(orig.inside())
413 {
414  const unsigned int np = orig.n_points();
415  _points.reserve(np);
416  for (auto i : make_range(np))
417  _points.push_back(orig.point(i));
418 }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
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
Point _center
arbitrary (x,y) location inside the hole

◆ ArbitraryHole() [5/5]

libMesh::TriangulatorInterface::ArbitraryHole::ArbitraryHole ( const ArbitraryHole orig)
default

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

◆ get_points()

const std::vector<Point>& libMesh::TriangulatorInterface::ArbitraryHole::get_points ( ) const
inline

Definition at line 300 of file mesh_triangle_holes.h.

References _points.

Referenced by libMesh::Poly2TriTriangulator::insert_refinement_points().

301  {
302  return _points;
303  }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.

◆ inside()

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

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

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 434 of file mesh_triangle_holes.C.

435 {
436  return _center;
437 }
Point _center
arbitrary (x,y) location inside 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::ArbitraryHole::n_points ( ) const
overridevirtual

The number of geometric points which define the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 421 of file mesh_triangle_holes.C.

422 {
423  return _points.size();
424 }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.

◆ point()

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

Return the nth point defining the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 427 of file mesh_triangle_holes.C.

428 {
429  libmesh_assert_less (n, _points.size());
430  return _points[n];
431 }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.

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

std::vector< unsigned int > libMesh::TriangulatorInterface::ArbitraryHole::segment_indices ( ) const
overridevirtual

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

Reimplemented from libMesh::TriangulatorInterface::Hole.

Definition at line 440 of file mesh_triangle_holes.C.

441 {
442  return _segment_indices;
443 }

◆ set_points()

void libMesh::TriangulatorInterface::ArbitraryHole::set_points ( std::vector< Point points)
inline

Definition at line 305 of file mesh_triangle_holes.h.

References _center, _points, and libMesh::TriangulatorInterface::Hole::calculate_inside_point().

Referenced by libMesh::Poly2TriTriangulator::insert_refinement_points().

306  {
307  _points = std::move(points);
309  }
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
Point calculate_inside_point() const
Calculate an inside point based on our boundary.
Point _center
arbitrary (x,y) location inside 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::ArbitraryHole::_center
private

arbitrary (x,y) location inside the hole

Definition at line 315 of file mesh_triangle_holes.h.

Referenced by ArbitraryHole(), and set_points().

◆ _points

std::vector<Point> libMesh::TriangulatorInterface::ArbitraryHole::_points
private

Reference to the vector of points which makes up the hole.

Definition at line 321 of file mesh_triangle_holes.h.

Referenced by ArbitraryHole(), get_points(), and set_points().

◆ _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().

◆ _segment_indices

std::vector<unsigned int> libMesh::TriangulatorInterface::ArbitraryHole::_segment_indices
private

Definition at line 323 of file mesh_triangle_holes.h.

Referenced by ArbitraryHole().


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