DistMesh.jl
DistMesh.jl implements simplex refinement on signed distance functions, or anything that has a sign, distance, and called like a function. The algorithm was first presented in 2004 by Per-Olof Persson, and was initially a port of the corresponding Matlab Code.
What is Simplex Refinement?
In layman's terms, a simplex is either a triangle in the 2D case, or a tetrahedra in the 3D case.
When simulating, you other want a few things from a mesh of simplices: - Accurate approximation of boundaries and features - Adaptive mesh sizes to improve accuracy - Near-Regular Simplicies
DistMesh is designed to address the above.
Algorithm Overview
The basic processes is as follows:
Comparison to other refinements
DistMesh generally has a very low memory footprint, and can refine without additional memory allocation. Similarly, since the global state of simplex qualities is accounted for in each refinement iteration, this leads to very high quality meshes.
Aside from the above, since DistMesh works on signed distance functions it can handle complex and varied input data that are not in the form of surface meshes (Piecewise Linear Complicies).
Difference from the MatLab implementation
Given the same parameters, the Julia implementation of DistMesh will generally perform 4-60 times faster than the MatLab implementation. Delaunay Triangulation in MatLab uses QHull, whereas DistMesh.jl uses TetGen.
How do I get a Signed Distance Function?
Here are some libraries that turn gridded and level set data into an approximate signed distance function:
- Interpolations.jl
- AdaptiveDistanceFields.jl
DistMesh.DistMeshQualityDistMesh.DistMeshResultDistMesh.DistMeshSetupDistMesh.DistMeshStatisticsDistMesh.HUniformDistMesh.dihedral_anglesDistMesh.distmeshDistMesh.hilbertsort!DistMesh.min_dihedral_anglesDistMesh.retriangulate!DistMesh.tet_to_edges!DistMesh.tets_to_tris!DistMesh.triqualDistMesh.volume_edge_extremaDistMesh.volume_edge_ratioDistMesh.volume_edge_stats
DistMesh.DistMeshQuality — TypeDistMeshQualityUse Tetrahedral quality analysis to control the meshing process
iso (default: 0): Value of which to extract the iso surface, inside negative
deltat (default: 0.1): the fraction of edge displacement to apply each iterationDistMesh.DistMeshResult — TypeDistMeshResultA struct returned from the distmesh function that includes point, simplex, and interation statistics.
DistMesh.DistMeshSetup — TypeDistMeshSetupTakes Keyword arguments as follows:
iso (default: 0): Value of which to extract the isosurface, inside surface is negative
deltat (default: 0.1): the fraction of edge displacement to apply each iteration
sort (default:false): If true and no fixed points, sort points using a hilbert sort.
sort_interval (default:20) Use hilbert sort after the specified retriangulations
distribution (default: :regular) Initial point distribution, either :regular or :packed.DistMesh.DistMeshStatistics — TypeDistMeshStatistics
Statistics about the convergence between iterationsDistMesh.HUniform — TypeUniform edge length function.
DistMesh.dihedral_angles — MethodCompute dihedral angles within a tetrahedra
radiansDistMesh.distmesh — Methoddistmesh
3D Mesh Generator using Signed Distance Functions.
Arguments:
fdist: Distance function
fh: Edge length function
h: Smallest edge length
Returns:
p: Node positions
t: Triangle indices
Example: Unit ball
d(p) = sqrt(sum(p.^2))-1
p,t = distmeshnd(d,huniform,0.2)DistMesh.hilbertsort! — FunctionHilbert Sorting. If carry is specified, this array will be permuted in line with the specified array.
DistMesh.min_dihedral_angles — MethodCompute the minimum dihedral angle within a tetrahedra
radiansDistMesh.retriangulate! — Methodretriangulate!Given a point set, generate a delaunay triangulation, and other requirements. This includes: - Spatial sorting of points - Delaunay triangulation - Filtering of invalid tetrahedra outside the boundary
DistMesh.tet_to_edges! — MethodDecompose tets to edges, using a pre-allocated array and set.
Set ensures uniqueness, and result will be sorted.DistMesh.tets_to_tris! — Methodconvert tets to tris, returned sorted and unique
DistMesh.triqual — MethodDetermine the quality of a triangle given 3 points.
Points must be 3D.
DistMesh.volume_edge_extrema — Methodreturns the extrema elements (min, max) of the sampled qualities
DistMesh.volume_edge_ratio — MethodComputes the volume and edge-length ratio from four given pointsDistMesh.volume_edge_stats — Methodreturns the (min, avg, max) of the sampled qualities