https://mooseframework.inl.gov
Loading...
Searching...
No Matches
XYFrontalDelaunayGenerator.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
13
14#include "XYCrossFieldSolver.h"
17
18#include "libmesh/mesh_triangle_holes.h"
19#include "libmesh/parsed_function.h"
20#include "libmesh/point_locator_base.h"
21
22#include <map>
23#include <memory>
24#include <set>
25#include <utility>
26#include <vector>
27
50{
51public:
53
55
56 std::unique_ptr<MeshBase> generate() override;
57
58protected:
63 struct FrontEdge
64 {
66 std::size_t start;
68 std::size_t end;
70 Real excess;
71 };
72
82 std::unique_ptr<MeshBase>
83 buildBackgroundMesh(const MeshBase & boundary_mesh,
84 const std::vector<std::unique_ptr<MeshBase>> & holes,
86
92 static std::map<dof_id_type, Real> boundaryTangentAngles(const MeshBase & mesh);
93
105 void appendLoop(const std::vector<Point> & loop,
106 bool refine,
107 unsigned int extra_nodes,
108 boundary_id_type bcid,
109 std::vector<Point> & points,
110 std::vector<XYIncrementalDelaunay::Segment> & segments);
111
113 Real targetArea(const Point & point) const;
114
116 Real targetSize(Real area) const;
117
119 Real targetCircumradius(Real size) const;
120
128
130 std::pair<Point, Point> localFrame(const Point & point) const;
131
133 Real metricDistance(const Point & first,
134 const Point & second,
135 const std::pair<Point, Point> & frame) const;
136
138 bool insideDomain(const Point & point) const;
139
141 std::pair<long, long> gridKey(const Point & point, Real cell) const;
142
148 void addToGrid(std::size_t vertex, const Point & point);
149
157 bool hasVertexWithin(const XYIncrementalDelaunay & delaunay,
158 const Point & point,
159 Real distance,
160 const std::pair<Point, Point> & frame) const;
161
170 bool
171 placePoint(const XYIncrementalDelaunay & delaunay, const FrontEdge & edge, Point & point) const;
172
179 std::vector<FrontEdge>
180 collectFront(const XYIncrementalDelaunay & delaunay,
181 const std::vector<XYIncrementalDelaunay::Triangle> & triangles,
182 const std::vector<bool> & inside) const;
183
190 void recordSplitBoundaryIds(const XYIncrementalDelaunay & delaunay, std::size_t vertex);
191
193 void advanceFront(XYIncrementalDelaunay & delaunay);
194
196 std::unique_ptr<MeshBase> buildTriangleMesh(const XYIncrementalDelaunay & delaunay);
197
199 std::unique_ptr<MeshBase> & _bdy_ptr;
200
202 const std::vector<std::unique_ptr<MeshBase> *> _hole_ptrs;
203
206
208 const bool _refine_bdy;
209
211 const std::vector<bool> _stitch_holes;
212
214 const std::vector<bool> _refine_holes;
215
217 const Real _desired_area;
218
220 const std::string _desired_area_func;
221
223 const std::vector<Point> _interior_points;
224
227
230
232 std::unique_ptr<libMesh::TriangulatorInterface::MeshedHole> _outer_outline;
233
235 std::vector<std::unique_ptr<libMesh::TriangulatorInterface::MeshedHole>> _hole_outlines;
236
238 std::unique_ptr<MeshBase> _background_mesh;
239
241 std::unique_ptr<libMesh::PointLocatorBase> _background_locator;
242
245
247 std::unique_ptr<libMesh::ParsedFunction<Real>> _area_function;
248
250 std::unique_ptr<XYCrossFieldSolver> _cross_field;
251
253 std::vector<std::pair<Point, Point>> _boundary_segments;
254
257
259 std::map<std::pair<long, long>, std::vector<std::size_t>> _boundary_segment_grid;
260
263
265 std::map<std::pair<long, long>, std::vector<std::size_t>> _vertex_grid;
266
268 std::map<XYIncrementalDelaunay::Segment, boundary_id_type> _segment_boundary_ids;
269
271 static constexpr Real _background_area_factor = 16.0;
272
274 static constexpr Real _size_tolerance = 1.2;
275
277 static constexpr Real _rejection_factor = 0.7;
278};
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Base class for Delaunay mesh generators applied to a surface.
Generates a triangulation in the XY plane by advancing a front, based on an input mesh defining the o...
static constexpr Real _size_tolerance
How far the circumradius of a triangle may exceed the target before the advance refines it.
const std::vector< bool > _refine_holes
Whether to allow automatically refining each hole boundary.
std::map< XYIncrementalDelaunay::Segment, boundary_id_type > _segment_boundary_ids
Boundary id of each seed segment, keyed on its two vertices with the smaller id first.
const std::string _desired_area_func
Desired triangle area as a (fparser-compatible) function of x,y.
std::unique_ptr< MeshBase > buildTriangleMesh(const XYIncrementalDelaunay &delaunay)
static constexpr Real _rejection_factor
How close to an existing vertex, as a fraction of the target size, a new point may not come.
Real _boundary_cell
Side of the buckets the boundary segments are sorted into so that the frame search stays local.
std::pair< Point, Point > localFrame(const Point &point) const
void recordSplitBoundaryIds(const XYIncrementalDelaunay &delaunay, std::size_t vertex)
Moves the boundary id recorded for the constrained segment an insertion split onto the two halves tha...
const std::vector< std::unique_ptr< MeshBase > * > _hole_ptrs
Holds pointers to the pointers to input meshes defining holes.
Real _grid_cell
Side of the buckets the vertices are sorted into so that the rejection rule stays local.
void appendLoop(const std::vector< Point > &loop, bool refine, unsigned int extra_nodes, boundary_id_type bcid, std::vector< Point > &points, std::vector< XYIncrementalDelaunay::Segment > &segments)
Adds one closed loop of the input boundary to the points the triangulation is seeded with and to the ...
static std::map< dof_id_type, Real > boundaryTangentAngles(const MeshBase &mesh)
void advanceFront(XYIncrementalDelaunay &delaunay)
Advances the front over the whole domain, inserting points into the triangulation.
std::vector< FrontEdge > collectFront(const XYIncrementalDelaunay &delaunay, const std::vector< XYIncrementalDelaunay::Triangle > &triangles, const std::vector< bool > &inside) const
bool hasVertexWithin(const XYIncrementalDelaunay &delaunay, const Point &point, Real distance, const std::pair< Point, Point > &frame) const
std::unique_ptr< MeshBase > buildBackgroundMesh(const MeshBase &boundary_mesh, const std::vector< std::unique_ptr< MeshBase > > &holes, const MeshTriangulationUtils::XYDelaunayOptions &opts)
Triangulates the domain with the existing Delaunay triangulator at _background_area_factor times the ...
Real metricDistance(const Point &first, const Point &second, const std::pair< Point, Point > &frame) const
std::map< std::pair< long, long >, std::vector< std::size_t > > _vertex_grid
Vertex ids of the triangulation, bucketed by position.
const MooseEnum _metric
Norm the target size is measured in when a point is placed ahead of the front.
const Real _desired_area
Desired (maximum) triangle area.
std::map< std::pair< long, long >, std::vector< std::size_t > > _boundary_segment_grid
Indices into _boundary_segments, bucketed by the cells each of those segments passes through.
std::vector< std::unique_ptr< libMesh::TriangulatorInterface::MeshedHole > > _hole_outlines
Outlines of the holes, which the advance stays outside.
Real targetArea(const Point &point) const
std::unique_ptr< MeshBase > _background_mesh
Coarse triangulation of the domain the cross field is solved on.
std::unique_ptr< libMesh::ParsedFunction< Real > > _area_function
Desired area as a function of position, built only when 'desired_area_func' is set.
std::unique_ptr< MeshBase > & _bdy_ptr
Input mesh defining the boundary to triangulate within.
std::unique_ptr< libMesh::TriangulatorInterface::MeshedHole > _outer_outline
Outline of the outer boundary, which the advance stays inside.
std::pair< long, long > gridKey(const Point &point, Real cell) const
void addToGrid(std::size_t vertex, const Point &point)
Records a vertex in the grid the rejection rule searches.
static constexpr Real _background_area_factor
How much coarser in area the background triangulation is than the mesh being generated.
void buildBoundarySegmentGrid()
Sorts the boundary segments into the buckets the BOUNDARY frame searches, so that a search only has t...
Real _background_mean_area
Mean area of the background elements, the target where the background locator finds nothing.
const std::vector< Point > _interior_points
Desired interior node locations.
bool placePoint(const XYIncrementalDelaunay &delaunay, const FrontEdge &edge, Point &point) const
Computes where the advance would place a point ahead of a front edge and applies the rejection rule t...
std::vector< std::pair< Point, Point > > _boundary_segments
Segments of the outer boundary and of the holes, whose tangents give the BOUNDARY frame.
const std::vector< bool > _stitch_holes
Whether to stitch to the mesh defining each hole.
std::unique_ptr< XYCrossFieldSolver > _cross_field
Cross field over the domain, built only when the LINF metric asks for the CROSS_FIELD frame.
std::unique_ptr< libMesh::PointLocatorBase > _background_locator
Locates the background element whose area is the target where no area limit was given.
const MooseEnum _orientation
Where the local frame the LINF metric measures in comes from.
bool insideDomain(const Point &point) const
const unsigned int _add_nodes_per_boundary_segment
How many more nodes to add in each outer boundary segment.
const bool _refine_bdy
Whether to allow automatically refining the outer boundary.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Constrained Delaunay triangulation of a set of points in the plane, built one point at a time.
Bundle of inputs for triangulateWithDelaunay.
An edge of the front, which separates the triangles that meet the target size from the triangles that...
std::size_t start
Vertex at the start of the edge, which has the triangle that misses the target on its left.
std::size_t end
Vertex at the end of the edge.
Real excess
Circumradius of that triangle over the target circumradius, larger being further off.