libMesh
triangulator_interface.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef LIBMESH_MESH_TRIANGULATOR_INTERFACE_H
20 #define LIBMESH_MESH_TRIANGULATOR_INTERFACE_H
21 
22 
23 #include "libmesh/libmesh_config.h"
24 
25 // Local Includes
26 #include "libmesh/libmesh.h"
27 #include "libmesh/point.h"
28 
29 #include "libmesh/function_base.h"
30 
31 // C++ includes
32 #include <set>
33 #include <vector>
34 
35 namespace libMesh
36 {
37 
38 // Forward Declarations
39 class UnstructuredMesh;
40 template <unsigned int KDDim>
42 enum ElemType : int;
43 
44 // Helper function for auto area calculation
45 class AutoAreaFunction : public FunctionBase<Real>
46 {
47 public:
49  const unsigned int num_nearest_pts,
50  const unsigned int power,
51  const Real background_value,
52  const Real background_eff_dist);
53 
56 
57  AutoAreaFunction (AutoAreaFunction &&) = delete;
59  virtual ~AutoAreaFunction ();
60 
61  void init_mfi (const std::vector<Point> & input_pts,
62  const std::vector<Real> & input_vals);
63 
64  virtual Real operator() (const Point & p,
65  const Real /*time*/) override;
66 
67  virtual void operator() (const Point & p,
68  const Real time,
69  DenseVector<Real> & output) override
70  {
71  output.resize(1);
72  output(0) = (*this)(p,time);
73  return;
74  }
75 
76  virtual std::unique_ptr<FunctionBase<Real>> clone() const override
77  {
78  return std::make_unique<AutoAreaFunction>(_comm, _num_nearest_pts, _power, _background_value, _background_eff_dist);
79  }
80 
81 private:
83  const unsigned int _num_nearest_pts;
84  const unsigned int _power;
87  std::unique_ptr<InverseDistanceInterpolation<3>> _auto_area_mfi;
88 };
89 
91 {
92 public:
99  explicit
101 
105  virtual ~TriangulatorInterface() = default;
106 
112  {
119 
130  PSLG = 1,
131 
136  };
137 
143  class Hole;
144  class AffineHole;
145  class PolygonHole;
146  class ArbitraryHole;
147  class MeshedHole;
148 
154  class Region;
155 
159  virtual void triangulate() = 0;
160 
165 
178 
187  { libmesh_not_implemented(); }
188 
194  { return nullptr; }
195 
201 
206 
211 
215  void set_interpolate_boundary_points (int n_points);
216 
220  int get_interpolate_boundary_points () const;
221 
230  virtual void set_refine_boundary_allowed (bool)
231  { libmesh_not_implemented(); }
232 
237  virtual bool refine_boundary_allowed () const
238  { return true; }
239 
245 
249  bool & quiet() {return _quiet;}
250 
255  void attach_hole_list(const std::vector<Hole*> * holes) {_holes = holes;}
256 
263 
265 
279  std::vector<std::pair<unsigned int, unsigned int>> segments;
280 
287  std::vector<Point> segment_midpoints;
288 
294  void attach_boundary_marker(const std::vector<int> * markers) { _markers = markers; }
295 
300  void attach_region_list(const std::vector<Region*> * regions) { _regions = regions; }
301 
321  const unsigned int num_nearest_pts,
322  const unsigned int power,
323  const Real background_value,
324  const Real background_eff_dist);
325 
329  bool has_auto_area_function() {return _auto_area_function != nullptr;}
330 
335 
341  void calculate_auto_desired_area_samples(std::vector<Point> & function_points,
342  std::vector<Real> & function_sizes,
343  const Real & area_factor = 1.5);
344 
351  void set_outer_boundary_ids(std::set<std::size_t> bdy_ids) { _bdy_ids = std::move(bdy_ids); }
352  const std::set<std::size_t> & get_outer_boundary_ids() const { return _bdy_ids; }
353 
354 protected:
360  void elems_to_segments();
361 
366  void nodes_to_segments(dof_id_type max_node_id);
367 
373 
380 
384  void verify_holes(const Hole & outer_bdy);
385 
389  unsigned int total_hole_points();
390 
395 
400  const std::vector<Hole*> * _holes;
401 
405  const std::vector<int> * _markers;
406 
411  const std::vector<Region*> * _regions;
412 
416  std::set<std::size_t> _bdy_ids;
417 
423 
428 
433 
440 
450 
456 
462 
466  bool _quiet;
467 
472 
476  std::unique_ptr<AutoAreaFunction> _auto_area_function;
477 };
478 
479 } // namespace libMesh
480 
481 #endif // ifndef LIBMESH_MESH_TRIANGULATOR_INTERFACE_H
TriangulationType
The TriangulationType is used with the general triangulate function defined below.
FunctionBase< Real > * get_auto_area_function()
Get the auto area function.
ElemType
Defines an enum for geometric element types.
bool _verify_hole_boundaries
Flag which tells if we want to check hole geometry.
void init_mfi(const std::vector< Point > &input_pts, const std::vector< Real > &input_vals)
virtual bool refine_boundary_allowed() const
Get whether or not the triangulation is allowed to refine the mesh boundary when refining the interio...
Inverse distance interpolation.
bool _insert_extra_points
Flag which tells whether or not to insert additional nodes before triangulation.
virtual void triangulate()=0
This is the main public interface for this function.
const Parallel::Communicator & _comm
std::set< std::size_t > _bdy_ids
A set of ids to allow on the outer boundary loop.
void insert_any_extra_boundary_points()
Helper function to add extra points (midpoints of initial segments) to a PSLG triangulation.
virtual FunctionBase< Real > * get_desired_area_function()
Get the function giving desired triangle area as a function of position, or nullptr if no such functi...
void set_verify_hole_boundaries(bool v)
Verifying that hole boundaries don&#39;t cross the outer boundary or each other is something like O(N_bdy...
virtual Real operator()(const Point &p, const Real) override
const std::vector< int > * _markers
Boundary markers.
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:396
Real _minimum_angle
Minimum angle in triangles.
const std::vector< Region * > * _regions
A pointer to a vector of Regions*s.
MeshBase & mesh
void set_interpolate_boundary_points(int n_points)
Complicated setter, for compatibility with insert_extra_points()
int _interpolate_boundary_points
Flag which tells how many additional nodes should be inserted between each pair of original mesh poin...
UnstructuredMesh & _mesh
Reference to the mesh which is to be created by triangle.
void set_outer_boundary_ids(std::set< std::size_t > bdy_ids)
A set of ids to allow on the outer boundary loop: interpreted as boundary ids of 2D elements and/or s...
The libMesh namespace provides an interface to certain functionality in the library.
void attach_region_list(const std::vector< Region *> *regions)
Attaches regions for using attribute to set subdomain IDs and better controlling the triangle sizes w...
ElemType & elem_type()
Sets and/or gets the desired element type.
Real _desired_area
The desired area for the elements in the resulting mesh.
bool & insert_extra_points()
Sets and/or gets the flag for inserting add&#39;l points.
virtual std::unique_ptr< FunctionBase< Real > > clone() const override
virtual ~TriangulatorInterface()=default
Empty destructor.
TriangulationType & triangulation_type()
Sets and/or gets the desired triangulation type.
void elems_to_segments()
Helper function to create PSLG segments from our other boundary-defining options (1D mesh edges...
ElemType _elem_type
The type of elements to generate.
void calculate_auto_desired_area_samples(std::vector< Point > &function_points, std::vector< Real > &function_sizes, const Real &area_factor=1.5)
The external boundary and all hole boundaries are collected.
bool _quiet
Flag which tells if we want to suppress stdout outputs.
void attach_hole_list(const std::vector< Hole *> *holes)
Attaches a vector of Hole* pointers which will be meshed around.
The UnstructuredMesh class is derived from the MeshBase class.
Real & minimum_angle()
Sets and/or gets the minimum desired angle.
virtual void set_desired_area_function(FunctionBase< Real > *)
Set a function giving desired triangle area as a function of position.
const std::vector< Hole * > * _holes
A pointer to a vector of Hole*s.
bool has_auto_area_function()
Whether or not an auto area function has been set.
std::unique_ptr< InverseDistanceInterpolation< 3 > > _auto_area_mfi
virtual void set_refine_boundary_allowed(bool)
Set whether or not the triangulation is allowed to refine the mesh boundary when refining the interio...
void increase_triangle_order()
Helper function to upconvert Tri3 to any higher order triangle type if requested via _elem_type...
const std::set< std::size_t > & get_outer_boundary_ids() const
First generate a convex hull from the set of points passed in, and then triangulate this set of point...
unsigned int total_hole_points()
Helper function to count points in and verify holes.
std::vector< Point > segment_midpoints
When constructing a second-order triangulation from a second-order boundary, we may do the triangulat...
Real & desired_area()
Sets and/or gets the desired triangle area.
TriangulatorInterface(UnstructuredMesh &mesh)
The constructor.
Triangulate the interior of a Planar Straight Line Graph, which is defined implicitly by the order of...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::pair< unsigned int, unsigned int > > segments
When constructing a PSLG, if the node numbers do not define the desired boundary segments implicitly ...
void nodes_to_segments(dof_id_type max_node_id)
Helper function to create PSLG segments from our node ordering, up to the maximum node id...
const unsigned int _num_nearest_pts
bool _smooth_after_generating
Flag which tells whether we should smooth the mesh after it is generated.
int get_interpolate_boundary_points() const
Complicated getter, for compatibility with insert_extra_points()
std::unique_ptr< AutoAreaFunction > _auto_area_function
The auto area function based on the spacing of boundary points.
void attach_boundary_marker(const std::vector< int > *markers)
Attaches boundary markers.
AutoAreaFunction(const Parallel::Communicator &comm, const unsigned int num_nearest_pts, const unsigned int power, const Real background_value, const Real background_eff_dist)
void verify_holes(const Hole &outer_bdy)
Helper function to check holes for intersections if requested.
Defines a dense vector for use in Finite Element-type computations.
Definition: dof_map.h:74
AutoAreaFunction & operator=(const AutoAreaFunction &)
void set_auto_area_function(const Parallel::Communicator &comm, const unsigned int num_nearest_pts, const unsigned int power, const Real background_value, const Real background_eff_dist)
Generate an auto area function based on spacing of boundary points.
Base class for functors that can be evaluated at a point and (optionally) time.
TriangulationType _triangulation_type
The type of triangulation to perform: choices are: convex hull PSLG.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
bool & quiet()
Whether not to silence internal messages to stdout.
bool & smooth_after_generating()
Sets/gets flag which tells whether to do two steps of Laplace mesh smoothing after generating the gri...
uint8_t dof_id_type
Definition: id_types.h:67