Different results when reading mesh from file or directly from API
I experience some unexpected behavior when reading a mesh with the API from a .msh
file compared to reading it directly from the API (without saving it to disk).
This is how the mesh looks when reading from the .msh
file
and this is the same script, same mesh translation procedure, however without saving the mesh to as .msh
to disk
The datastructure I'm parsing to assumes that the node tag begins by one and only nodes that are part of the actual finite element mesh are stored. It seems as if the definition of the physical group is ignored, since in the bad mesh the origin point is not ignored (left-hand side bottom). I know this behavior since I included gmsh.renumberNodes()
and gmsh.renumberElements()
calls, which without ended in the same result. Is there some option that I'm missing when using the API that ignores the unused/not domain entities? It seems as if there is some hidden functionality within gmsh.write
that ignores or kicks out the entities that do not belong to a physical group.
You can see the full example here: https://github.com/Ferrite-FEM/FerriteGmsh.jl/issues/20
or here a copy paste of it:
using Gmsh, FerriteGmsh, Ferrite
# Initialize gmsh
Gmsh.initialize()
# Add the points
h = 0.05
o = gmsh.model.geo.add_point(0.0, 0.0, 0.0, h)
p1 = gmsh.model.geo.add_point(0.5, 0.0, 0.0, h)
p2 = gmsh.model.geo.add_point(1.0, 0.0, 0.0, h)
p3 = gmsh.model.geo.add_point(0.0, 1.0, 0.0, h)
p4 = gmsh.model.geo.add_point(0.0, 0.5, 0.0, h)
# Add the lines
l1 = gmsh.model.geo.add_line(p1, p2)
l2 = gmsh.model.geo.add_circle_arc(p2, o, p3)
l3 = gmsh.model.geo.add_line(p3, p4)
l4 = gmsh.model.geo.add_circle_arc(p4, o, p1)
# Create the closed curve loop and the surface
loop = gmsh.model.geo.add_curve_loop([l1, l2, l3, l4])
surf = gmsh.model.geo.add_plane_surface([loop])
# Synchronize the model
gmsh.model.geo.synchronize()
# Create the physical domains
gmsh.model.add_physical_group(1, [l1], -1, "right")
gmsh.model.add_physical_group(1, [l2], -1, "outer")
gmsh.model.add_physical_group(1, [l3], -1, "left")
gmsh.model.add_physical_group(1, [l4], -1, "inner")
gmsh.model.add_physical_group(2, [surf])
# Generate a 2D mesh
gmsh.model.mesh.generate(2)
# Convert the mesh to Ferrite Grid
grid_bad = FerriteGmsh.togrid()
vtk_save(vtk_grid("grid_bad", grid_bad))
grid_good = mktempdir() do dir
path = joinpath(dir, "mesh.msh")
gmsh.write(path)
togrid(path)
end
vtk_save(vtk_grid("grid_good", grid_good))
Note here, FerriteGmsh
is the translation package, Ferrite
is used to write the Ferrite
Mesh datastructure to vtk visualization and Gmsh
is just the package that ships the gmsh binary, api etc.