libMesh
Loading...
Searching...
No Matches
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.
 
virtual ~Hole ()=default
 Destructor.
 
virtual unsigned int n_points () const =0
 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.
 
virtual Point point (const unsigned int n) const =0
 Return the nth point defining the hole.
 
virtual Point midpoint (const unsigned int, const unsigned int) const
 Return the midpoint m along the side n defining the hole.
 
virtual Point inside () const =0
 Return an (arbitrary) point which lies inside the hole.
 
bool contains (Point p) const
 Return true iff p lies inside the hole.
 
Real area () const
 Return the area of the hole.
 
RealGradient areavec () const
 Return a vector with right-hand-rule orientation and length of twice area() squared.
 
virtual std::vector< unsigned intsegment_indices () const
 Starting indices of points for a hole with multiple disconnected boundaries.
 
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.
 
virtual bool refine_boundary_allowed () const
 Get whether or not the triangulation is allowed to refine the mesh boundary when refining the interior.
 

Protected Member Functions

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

Protected Attributes

bool _refine_bdy_allowed = true
 Whether to allow boundary refinement.
 

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 190 of file mesh_triangle_holes.C.

191{
192 return this->areavec().norm() / 2;
193}
RealGradient areavec() const
Return a vector with right-hand-rule orientation and length of twice area() squared.
auto norm() const

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

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

◆ 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 196 of file mesh_triangle_holes.C.

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

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

Referenced by area().

◆ calculate_inside_point()

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

Calculate an inside point based on our boundary.

Definition at line 254 of file mesh_triangle_holes.C.

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

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

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

◆ 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 311 of file mesh_triangle_holes.C.

312{
313 // Count the number of intersections with a ray to the right,
314 // keep track of how far they are
315 Point ray_target = p + Point(1);
316 std::vector<Real> intersection_distances =
317 this->find_ray_intersections(p, ray_target);
318
319 // Odd number of intersections == we're inside
320 // Even number == we're outside
321 return intersection_distances.size() % 2;
322}

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

◆ 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 230 of file mesh_triangle_holes.C.

232{
233 const auto np = this->n_points();
234
235 std::vector<Real> intersection_distances;
236
237 for (auto i : make_range(np))
238 {
239 const Point & p0 = this->point(i),
240 & p1 = this->point((i+1)%np),
241 & p2 = this->point((i+2)%np);
242 const Real intersection_distance =
243 find_intersection(ray_start, ray_target, p0, p1, p2);
244 if (intersection_distance >= 0)
245 intersection_distances.push_back
246 (intersection_distance);
247 }
248
249 return intersection_distances;
250}

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

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

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

References _refine_bdy_allowed.

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

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

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 }

References n_points().

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

134 { _refine_bdy_allowed = refine_bdy_allowed; }

References _refine_bdy_allowed.

Referenced by MeshTriangulationTest::testPoly2TriHolesInteriorRefinedBase().

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: