libMesh
Loading...
Searching...
No Matches
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.
 
 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.
 
 ArbitraryHole (const Hole &orig)
 We can also construct an ArbitraryHole which just copies a hole of any other type.
 
 ArbitraryHole (const ArbitraryHole &orig)=default
 
virtual unsigned int n_points () const override
 The number of geometric points which define 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 std::vector< unsigned intsegment_indices () const override
 Starting indices of points for a hole with multiple disconnected boundaries.
 
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.
 
virtual Point midpoint (const unsigned int, const unsigned int) const
 Return the midpoint m along the side n defining 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 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.
 

Private Attributes

Point _center
 arbitrary (x,y) location inside the hole
 
std::vector< Point_points
 Reference to the vector of points which makes up the hole.
 
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 389 of file mesh_triangle_holes.C.

391 : _center(center),
392 _points(std::move(points))
393{
394 _segment_indices.push_back(0);
395 _segment_indices.push_back(_points.size());
396}
std::vector< Point > _points
Reference to the vector of points which makes up the hole.
Point _center
arbitrary (x,y) location inside the hole

References _points, and _segment_indices.

◆ ArbitraryHole() [2/5]

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

Definition at line 399 of file mesh_triangle_holes.C.

402 : _center(center),
403 _points(std::move(points)),
405{}
virtual std::vector< unsigned int > segment_indices() const override
Starting indices of points for a hole with multiple disconnected boundaries.

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

409 : _points(std::move(points))
410{
411 _segment_indices.push_back(0);
412 _segment_indices.push_back(_points.size());
414}
Point calculate_inside_point() const
Calculate an inside point based on our boundary.

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

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

418 : _center(orig.inside())
419{
420 const unsigned int np = orig.n_points();
421 _points.reserve(np);
422 for (auto i : make_range(np))
423 _points.push_back(orig.point(i));
424}
virtual Point point(const unsigned int n) const override
Return the nth point defining 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:176

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

◆ 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 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 libMesh::TriangulatorInterface::Hole::areavec(), and libMesh::TypeVector< T >::norm().

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

◆ 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 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 libMesh::TriangulatorInterface::Hole::area().

◆ calculate_inside_point()

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

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

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

Referenced by ArbitraryHole(), and set_points().

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

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.

◆ get_points()

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

Definition at line 300 of file mesh_triangle_holes.h.

301 {
302 return _points;
303 }

References _points.

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

◆ inside()

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

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

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 440 of file mesh_triangle_holes.C.

441{
442 return _center;
443}

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

428{
429 return _points.size();
430}

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

434{
435 libmesh_assert_less (n, _points.size());
436 return _points[n];
437}

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

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

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

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

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

447{
448 return _segment_indices;
449}

◆ set_points()

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

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

134 { _refine_bdy_allowed = refine_bdy_allowed; }

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

Referenced by MeshTriangulationTest::testPoly2TriHolesInteriorRefinedBase().

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


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