libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::TriangulatorInterface::AffineHole Class Reference

A way to translate and/or rotate an existing hole; perhaps to tile it in many places or to put it at an angle that the underlying hole doesn't support. More...

#include <mesh_triangle_holes.h>

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

Public Member Functions

 AffineHole (const Hole &underlying, Real angle, const Point &shift)
 Constructor specifying the underlying hole, and the rotation angle (in radians, done first) and translation (done second) with which to transform it.
 
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 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 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.
 

Private Member Functions

Point transform (const Point &p) const
 Rotate-and-shift equations.
 

Private Attributes

const Hole_underlying
 Hole to transform.
 
Real _angle
 Angle to rotate (counter-clockwise) by.
 
Point _shift
 (x,y) location to shift (0,0) to
 

Detailed Description

A way to translate and/or rotate an existing hole; perhaps to tile it in many places or to put it at an angle that the underlying hole doesn't support.

Definition at line 213 of file mesh_triangle_holes.h.

Constructor & Destructor Documentation

◆ AffineHole()

libMesh::TriangulatorInterface::AffineHole::AffineHole ( const Hole underlying,
Real  angle,
const Point shift 
)
inline

Constructor specifying the underlying hole, and the rotation angle (in radians, done first) and translation (done second) with which to transform it.

Definition at line 221 of file mesh_triangle_holes.h.

222 : _underlying(underlying), _angle(angle), _shift(shift) {}
Real _angle
Angle to rotate (counter-clockwise) by.
Point _shift
(x,y) location to shift (0,0) to

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

◆ inside()

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

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

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 371 of file mesh_triangle_holes.C.

372{
373 return this->transform(_underlying.inside());
374}
Point transform(const Point &p) const
Rotate-and-shift equations.

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

virtual unsigned int libMesh::TriangulatorInterface::AffineHole::n_points ( ) const
inlineoverridevirtual

The number of geometric points which define the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 224 of file mesh_triangle_holes.h.

225 { return _underlying.n_points(); }

References _underlying, and libMesh::TriangulatorInterface::Hole::n_points().

◆ point()

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

Return the nth point defining the hole.

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 365 of file mesh_triangle_holes.C.

366{
367 return this->transform(_underlying.point(n));
368}

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

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.

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

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

◆ transform()

Point libMesh::TriangulatorInterface::AffineHole::transform ( const Point p) const
private

Rotate-and-shift equations.

Definition at line 377 of file mesh_triangle_holes.C.

378{
379 const Real cos_a = std::cos(_angle);
380 const Real sin_a = std::sin(_angle);
381 return Point(p(0)*cos_a-p(1)*sin_a + _shift(0),
382 p(1)*cos_a+p(1)*sin_a + _shift(1));
383}

References libMesh::Real.

Member Data Documentation

◆ _angle

Real libMesh::TriangulatorInterface::AffineHole::_angle
private

Angle to rotate (counter-clockwise) by.

Definition at line 245 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().

◆ _shift

Point libMesh::TriangulatorInterface::AffineHole::_shift
private

(x,y) location to shift (0,0) to

Definition at line 250 of file mesh_triangle_holes.h.

◆ _underlying

const Hole& libMesh::TriangulatorInterface::AffineHole::_underlying
private

Hole to transform.

Definition at line 240 of file mesh_triangle_holes.h.

Referenced by n_points().


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