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

Private Member Functions

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

Private Attributes

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

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) {}
const Hole & _underlying
Hole to transform.
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 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 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
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.

◆ inside()

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

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

Implements libMesh::TriangulatorInterface::Hole.

Definition at line 365 of file mesh_triangle_holes.C.

366 {
367  return this->transform(_underlying.inside());
368 }
Point transform(const Point &p) const
Rotate-and-shift equations.
const Hole & _underlying
Hole to transform.
virtual Point inside() const =0
Return an (arbitrary) point which lies 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()

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.

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

225  { return _underlying.n_points(); }
const Hole & _underlying
Hole to transform.
virtual unsigned int n_points() const =0
The number of geometric points which define the hole.

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

360 {
361  return this->transform(_underlying.point(n));
362 }
Point transform(const Point &p) const
Rotate-and-shift equations.
const Hole & _underlying
Hole to transform.
virtual Point point(const unsigned int n) const =0
Return the nth point defining 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()

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.

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

◆ transform()

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

Rotate-and-shift equations.

Definition at line 371 of file mesh_triangle_holes.C.

References libMesh::Real.

372 {
373  const Real cos_a = std::cos(_angle);
374  const Real sin_a = std::sin(_angle);
375  return Point(p(0)*cos_a-p(1)*sin_a + _shift(0),
376  p(1)*cos_a+p(1)*sin_a + _shift(1));
377 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _angle
Angle to rotate (counter-clockwise) by.
Point _shift
(x,y) location to shift (0,0) to
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

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: