How to export mesh for each physical group separately?
I've got a STP file with multiple volumes which I would like to mesh and then export using the GMSH python API. Specifically, I would like to export a mesh of each volume in the STP file seperately. I thought this was done by using physical groups but I've not been able to make it work. Attached is a sample (very simple) STP file with a couple different volumes. Here is the python code that I've got so far:
gmsh.merge("multi_body.stp")
volumes = gmsh.model.getEntities(3)
bounds = np.zeros((2 * len(volumes), 3))
for i in range(0, len(volumes)):
bbox = gmsh.model.getBoundingBox(volumes[i][0], volumes[i][1])
bounds[2*i + 0] = [bbox[0], bbox[1], bbox[2]]
bounds[2*i + 1] = [bbox[3], bbox[4], bbox[5]]
diagonal = (bounds.max(0) - bounds.min(0))
mesh_size = np.linalg.norm(diagonal) * 0.10
# add physical group
gmsh.model.addPhysicalGroup(3, volumes[i], name=f"pgroup_{volumes[i][0]}_{volumes[i][1]}")
gmsh.model.mesh.generate(2)
# gmsh.option.setNumber("Mesh.SaveAll", 1)
gmsh.write(f"mesh_out_{i}.stl")
The idea is to loop over the volumes in the STP file, create the 2D (or 3D) mesh for that volume and then write out the mesh file. Any ideas would be most appreciated!