Merging Different .msh files
Hi there,
I am trying to generate mesh for very complex geometry which has multiple connected parts. I have started with the most easiest case, by merging cube and cylinder. I am attaching the scripts and mesh images below; Script for the cube;
import gmsh
import sys
gmsh.initialize()
L = 1
W = 1
H = 1
gdim = 3
cube = gmsh.model.occ.addBox(0,0,0, L, W, H, tag=1)
gmsh.model.occ.synchronize()
volumes = gmsh.model.getEntities(dim=gdim)
gmsh.model.addPhysicalGroup(volumes[0][0], [volumes[0][1]], 1)
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.1)
gmsh.model.mesh.generate(gdim)
gmsh.write("{}.msh".format("cube"))
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
Mesh of the cube;
Script for the cylinder;
import gmsh
import sys
gmsh.initialize()
L = 1
W = 1
H = 1
R = 0.25
gdim = 3
cube = gmsh.model.occ.addCylinder(L,W/2,H/2, L, 0, 0, R, tag=1)
gmsh.model.occ.synchronize()
volumes = gmsh.model.getEntities(dim=gdim)
gmsh.model.addPhysicalGroup(volumes[0][0], [volumes[0][1]], 1)
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.1)
gmsh.model.mesh.generate(gdim)
gmsh.write("{}.msh".format("cylinder"))
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
Mesh of the cylinder becomes;
Now, I am merging these two meshes;
import gmsh
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 0)
gmsh.merge("cube.msh")
gmsh.merge("cylinder.msh")
gmsh.model.occ.synchronize()
surfaces = gmsh.model.getEntities(dim=2)
print("Surfaces:", surfaces)
volumes = gmsh.model.getEntities(dim=3)
print("Volumes:", volumes)
gmsh.write("{}.msh".format("merged"))
gmsh.fltk.run()
gmsh.finalize()
Gives;
However, even if it has 1 merged volume,it gives only 6 surfaces;
Surfaces: [(2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6)]
Volumes: [(3, 1)]
My questions are;
- Apparently, I should have 8 surfaces total, and intersecting surface should be extracted from the merged mesh, right? How it is possible?
- The element nodes are not matching in intersection plane (cylindrical section between cube and cylinder base) and this is of course problem for my FEM simulation. How can I match these nodes, when I merge multiple different meshes? Is it possible?
Many thanks for your answer in advance.