2D examples of DistMesh.jl or other simple mesh generator?

Hi everyone.
I am looking to generate some simple 2D meshes (triangles filling a big rectangle with some smaller square holes). I used for years the DistMesh for Matlab. Now I am trying to use the Julia port. There are several that do not seem to be updated or to have all the functionality (e.g. Distmesh2d.jl does not output the connectivity of the elements).
I am looking for some examples of DistMesh.jl in 2D or other mesh generator.
Any help?
Kind regards.
M.

Are you aware that Meshes.jl can discretize geometries like Box? Check the docs and search for discretize or simplexify

1 Like

DelaunayTriangulation.jl doesn’t work exactly the same as DistMesh.jl, but if you wanted to triangulate for example (as you say) a rectangle with holes, you could use it like

using DelaunayTriangulation, CairoMakie
outer = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)]
inner_1 = [(0.2, 0.2), (0.2, 0.5), (0.5, 0.5), (0.5, 0.2), (0.2, 0.2)]
inner_2 = [(0.7, 0.2), (0.7, 0.5), (0.9, 0.5), (0.9, 0.2), (0.7, 0.2)]
boundary = [[outer], [inner_1], [inner_2]]
boundary_nodes, points = convert_boundary_points_to_indices(boundary)
tri = triangulate(points; boundary_nodes)

# Unrefined 
fig = Figure()
ax = Axis(fig[1, 1], width = 400, height = 400, title = "Unrefined")
triplot!(ax, tri)

# Refined 
refine!(tri; max_area = 0.01) # you can also do custom constraints with the custom_constraint keyword 
ax = Axis(fig[1, 2], width = 400, height = 400, title = "Unrefined")
triplot!(ax, tri)
resize_to_layout!(fig)
fig

The docs give plenty of examples of working with the tri output (e.g. working with the connectivities)