I'm using the x7.py example to learn how to create internal faces/edges with the Gmsh API, but when i plot the 2D elements labels on Gmsh GUI, i'm getting overlapped tags. How can i remove the overlapped tags? I already tried the gmsh.model.occ.removeAllDuplicates(), but it didn't work.
The full code is
import sys
import gmsh
gmsh.initialize(sys.argv)
gmsh.model.add("x7")
gmsh.model.occ.addBox(0, 0, 0, 1, 1, 1)
gmsh.model.occ.synchronize()
gmsh.option.setNumber("Mesh.MeshSizeMin", 2.)
gmsh.model.mesh.generate(3)
elementType = gmsh.model.mesh.getElementType("tetrahedron", 1)
edgeNodes = gmsh.model.mesh.getElementEdgeNodes(elementType)
faceNodes = gmsh.model.mesh.getElementFaceNodes(elementType, 3)
gmsh.model.mesh.createEdges()
gmsh.model.mesh.createFaces()
edgeTags, edgeOrientations = gmsh.model.mesh.getEdges(edgeNodes)
faceTags, faceOrientations = gmsh.model.mesh.getFaces(3, faceNodes)
elementTags, elementNodeTags = gmsh.model.mesh.getElementsByType(elementType)
edges2Elements = {}
faces2Elements = {}
for i in range(len(edgeTags)): # 6 edges per tetrahedron
if not edgeTags[i] in edges2Elements:
edges2Elements[edgeTags[i]] = [elementTags[i // 6]]
else:
edges2Elements[edgeTags[i]].append(elementTags[i // 6])
for i in range(len(faceTags)): # 4 faces per tetrahedron
if not faceTags[i] in faces2Elements:
faces2Elements[faceTags[i]] = [elementTags[i // 4]]
else:
faces2Elements[faceTags[i]].append(elementTags[i // 4])
s = gmsh.model.addDiscreteEntity(2)
gmsh.fltk.run()
maxElementTag = gmsh.model.mesh.getMaxElementTag()
uniqueFaceTags = set()
tagsForTriangles = []
faceNodesForTriangles = []
for i in range(len(faceTags)):
if faceTags[i] not in uniqueFaceTags:
uniqueFaceTags.add(faceTags[i])
tagsForTriangles.append(faceTags[i] + maxElementTag)
faceNodesForTriangles.append(faceNodes[3 * i])
faceNodesForTriangles.append(faceNodes[3 * i + 1])
faceNodesForTriangles.append(faceNodes[3 * i + 2])
elementType2D = gmsh.model.mesh.getElementType("triangle", 1)
gmsh.model.mesh.addElementsByType(s, elementType2D, tagsForTriangles,
faceNodesForTriangles)
for t in tagsForTriangles:
print("triangle " + str(int(t)) + " is connected to tetrahedra " +
str(faces2Elements[t - maxElementTag]))
edgeTags, edgeNodes = gmsh.model.mesh.getAllEdges()
faceTags, faceNodes = gmsh.model.mesh.getAllFaces(3)
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
Here is a screenshot that shows the overlapping tags:
I've already tried the gmsh.model.occ.removeAllDuplicates(),gmsh.model.mesh.createEdges(),gmsh.model.mesh.createFaces() and gmsh.model.occ.synchronize() functions in hope that Gmsh would remove the overlapped tags by eliminating duplicated entities, or by creating new Faces and Edge tags to every face/edge, but it also didn't work.