libMesh
Loading...
Searching...
No Matches
triangulator_interface.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
35namespace libMesh
36{
37
38// Forward Declarations
39class UnstructuredMesh;
40template <unsigned int KDDim>
41class InverseDistanceInterpolation;
42enum ElemType : int;
43
44// Helper function for auto area calculation
45class AutoAreaFunction : public FunctionBase<Real>
46{
47public:
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
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
81private:
83 const unsigned int _num_nearest_pts;
84 const unsigned int _power;
87 std::unique_ptr<InverseDistanceInterpolation<3>> _auto_area_mfi;
88};
89
91{
92public:
99 explicit
101
105 virtual ~TriangulatorInterface() = default;
106
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
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
274
276
290 std::vector<std::pair<unsigned int, unsigned int>> segments;
291
298 std::vector<Point> segment_midpoints;
299
306 std::vector<Point> segment_midpoints_keys;
307
313 void attach_boundary_marker(const std::vector<int> * markers) { _markers = markers; }
314
319 void attach_region_list(const std::vector<Region*> * regions) { _regions = regions; }
320
340 const unsigned int num_nearest_pts,
341 const unsigned int power,
342 const Real background_value,
343 const Real background_eff_dist);
344
348 bool has_auto_area_function() {return _auto_area_function != nullptr;}
349
354
360 void calculate_auto_desired_area_samples(std::vector<Point> & function_points,
361 std::vector<Real> & function_sizes,
362 const Real & area_factor = 1.5);
363
370 void set_outer_boundary_ids(std::set<std::size_t> bdy_ids) { _bdy_ids = std::move(bdy_ids); }
371 const std::set<std::size_t> & get_outer_boundary_ids() const { return _bdy_ids; }
372
373protected:
379 void elems_to_segments();
380
385 void nodes_to_segments(dof_id_type max_node_id);
386
392
399
407
416
420 void verify_holes(const Hole & outer_bdy);
421
425 unsigned int total_hole_points();
426
431
436 const std::vector<Hole*> * _holes;
437
441 const std::vector<int> * _markers;
442
447 const std::vector<Region*> * _regions;
448
452 std::set<std::size_t> _bdy_ids;
453
459
464
469
476
486
492
498
502 bool _quiet;
503
508
514
518 std::unique_ptr<AutoAreaFunction> _auto_area_function;
519};
520
521} // namespace libMesh
522
523#endif // ifndef LIBMESH_MESH_TRIANGULATOR_INTERFACE_H
void ErrorVector unsigned int
void init_mfi(const std::vector< Point > &input_pts, const std::vector< Real > &input_vals)
AutoAreaFunction & operator=(const AutoAreaFunction &)
std::unique_ptr< InverseDistanceInterpolation< 3 > > _auto_area_mfi
const Parallel::Communicator & _comm
virtual Real operator()(const Point &p, const Real) override
AutoAreaFunction(const AutoAreaFunction &)
virtual std::unique_ptr< FunctionBase< Real > > clone() const override
AutoAreaFunction(AutoAreaFunction &&)=delete
Defines a dense vector for use in Finite Element-type computations.
void resize(const unsigned int n)
Resize the vector.
Base class for functors that can be evaluated at a point and (optionally) time.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
void increase_triangle_order()
Helper function to upconvert Tri3 to any higher order triangle type if requested via _elem_type.
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...
bool _verify_hole_boundaries
Flag which tells if we want to check hole geometry.
virtual void set_desired_area_function(FunctionBase< Real > *)
Set a function giving desired triangle area as a function of position.
ElemType _elem_type
The type of elements to generate.
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...
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,...
std::set< std::size_t > _bdy_ids
A set of ids to allow on the outer boundary loop.
void elems_to_segments()
Helper function to create PSLG segments from our other boundary-defining options (1D mesh edges,...
Real & minimum_angle()
Sets and/or gets the minimum desired angle.
void attach_boundary_marker(const std::vector< int > *markers)
Attaches boundary markers.
bool _smooth_after_generating
Flag which tells whether we should smooth the mesh after it is generated.
TriangulationType & triangulation_type()
Sets and/or gets the desired triangulation type.
virtual void triangulate()=0
This is the main public interface for this function.
Real _desired_area
The desired area for the elements in the resulting mesh.
void fixup_tri7_center_nodes()
Helper called at the end of increase_triangle_order() for TRI7 to reposition the interior node to the...
bool & quiet()
Whether not to silence internal messages to stdout.
int _interpolate_boundary_points
Flag which tells how many additional nodes should be inserted between each pair of original mesh poin...
Real _minimum_angle
Minimum angle in triangles.
virtual ~TriangulatorInterface()=default
Empty destructor.
void insert_any_extra_boundary_points()
Helper function to add extra points (midpoints of initial segments) to a PSLG triangulation.
unsigned int total_hole_points()
Helper function to count points in and verify holes.
TriangulationType
The TriangulationType is used with the general triangulate function defined below.
@ PSLG
Triangulate the interior of a Planar Straight Line Graph, which is defined implicitly by the order of...
@ INVALID_TRIANGULATION_TYPE
Does nothing, used as a "null" value.
@ GENERATE_CONVEX_HULL
First generate a convex hull from the set of points passed in, and then triangulate this set of point...
bool & smooth_after_generating()
Sets/gets flag which tells whether to do two steps of Laplace mesh smoothing after generating the gri...
virtual bool refine_boundary_allowed() const
Get whether or not the triangulation is allowed to refine the mesh boundary when refining the interio...
void set_verify_hole_boundaries(bool v)
Verifying that hole boundaries don't cross the outer boundary or each other is something like O(N_bdy...
const std::vector< Hole * > * _holes
A pointer to a vector of Hole*s.
const std::vector< int > * _markers
Boundary markers.
bool _fixup_tri7_center_nodes
Flag which tells if we want to relocate TRI7 interior nodes to the curved-mapping centroid after snap...
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 ...
bool has_auto_area_function()
Whether or not an auto area function has been set.
const std::vector< Region * > * _regions
A pointer to a vector of Regions*s.
UnstructuredMesh & _mesh
Reference to the mesh which is to be created by triangle.
const std::set< std::size_t > & get_outer_boundary_ids() const
int get_interpolate_boundary_points() const
Complicated getter, for compatibility with insert_extra_points()
bool & insert_extra_points()
Sets and/or gets the flag for inserting add'l points.
void verify_holes(const Hole &outer_bdy)
Helper function to check holes for intersections if requested.
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 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.
void attach_hole_list(const std::vector< Hole * > *holes)
Attaches a vector of Hole* pointers which will be meshed around.
Real & desired_area()
Sets and/or gets the desired triangle area.
ElemType & elem_type()
Sets and/or gets the desired element type.
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...
std::vector< Point > segment_midpoints
When constructing a second-order triangulation from a second-order boundary, we may do the triangulat...
TriangulationType _triangulation_type
The type of triangulation to perform: choices are: convex hull PSLG.
std::vector< Point > segment_midpoints_keys
When saving the midpoint location data, we need to save the corresponding segment information too.
void verify_quadratic_elements()
Helper called at the end of increase_triangle_order() to verify that no boundary-midpoint snap has ta...
std::unique_ptr< AutoAreaFunction > _auto_area_function
The auto area function based on the spacing of boundary points.
bool _insert_extra_points
Flag which tells whether or not to insert additional nodes before triangulation.
bool _quiet
Flag which tells if we want to suppress stdout outputs.
void set_fixup_tri7_center_nodes(bool v)
For TRI7 elements, after boundary mid-edge nodes have been snapped to a curved boundary in increase_t...
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.
FunctionBase< Real > * get_auto_area_function()
Get the auto area function.
void set_interpolate_boundary_points(int n_points)
Complicated setter, for compatibility with insert_extra_points()
The UnstructuredMesh class is derived from the MeshBase class.
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real