Skip to content

Commit

Permalink
generate mesh for tetrahedron
Browse files Browse the repository at this point in the history
  • Loading branch information
lvchien committed Oct 18, 2024
1 parent b5bce7b commit 604531c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1500,3 +1500,52 @@ function meshopenbook(angle, nbofpages, h)
rm(fno)
return m
end



"""
meshuniformtetrahedron(edgelength, h)
Create a mesh of a uniform tetrahedron with edge length `egdelength`. The four vertices are: (1, 1, 1), (-1, -1, 1), (-1, 1, -1) and (1, -1, -1) (rescaled).
The target edge size is `h`.
"""
function meshuniformtetrahedron(edgelength, h)

fno = tempname() * ".msh"
gmsh.initialize()
gmsh.model.add("tetrhedron")

c = edgelength/22
gmsh.model.geo.addPoint(c, c, c, h, 1)
gmsh.model.geo.addPoint(-c, -c, c, h, 2)
gmsh.model.geo.addPoint(-c, c, -c, h, 3)
gmsh.model.geo.addPoint(c, -c, -c, h, 4)

gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(1, 3, 2)
gmsh.model.geo.addLine(1, 4, 3)
gmsh.model.geo.addLine(2, 3, 4)
gmsh.model.geo.addLine(2, 4, 5)
gmsh.model.geo.addLine(3, 4, 6)

gmsh.model.geo.addCurveLoop([-1, -4, 2], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.geo.addCurveLoop([-2, -6, 3], 2)
gmsh.model.geo.addPlaneSurface([2], 2)
gmsh.model.geo.addCurveLoop([-3, 5, 1], 3)
gmsh.model.geo.addPlaneSurface([3], 3)
gmsh.model.geo.addCurveLoop([4, -5, 6], 4)
gmsh.model.geo.addPlaneSurface([4], 4)

gmsh.model.geo.synchronize()
gmsh.option.setNumber("Mesh.MshFileVersion",2)
gmsh.model.mesh.generate(2)
gmsh.write(fno)
gmsh.finalize()

m = CompScienceMeshes.read_gmsh_mesh(fno)
rm(fno)
return m
end

0 comments on commit 604531c

Please sign in to comment.