Hi,
All you need to do is assigning the physical tags automatically. For example, we have a cube.
We need to import that cube into gmsh model as a step file.
import sys
import numpy as np
import gmsh
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 0)
gmsh.model.add("cubes")
gmsh.option.setString('Geometry.OCCTargetUnit', 'M')
gmsh.model.occ.importShapes('cube.step')
gmsh.model.occ.synchronize()
gmsh.model.occ.removeAllDuplicates()
gmsh.model.occ.synchronize()
Now, we have our model in gmsh environment. We need to start assigning physical tags for surfaces and volumes. As we have only one volume (one cube), we can start with volume;
gmsh.model.addPhysicalGroup(3, [1], tag=1)
Then, we can assign tags to each surface randomly;
surfaces = gmsh.model.occ.getEntities(dim=2)
for surface in surfaces:
gmsh.model.addPhysicalGroup(surface[0], [surface[1]])
gmsh.model.occ.synchronize()
Now, we can mesh the geometry;
lc = 0.005
gmsh.option.setNumber("Mesh.MeshSizeMin", 0.005)
gmsh.option.setNumber("Mesh.Algorithm", 6)
gmsh.option.setNumber("Mesh.Algorithm3D", 10)#10
gmsh.option.setNumber("Mesh.Optimize", 1)
gmsh.option.setNumber("Mesh.OptimizeNetgen", 0)
gmsh.model.mesh.generate(3)
gmsh.option.setNumber("Mesh.SaveAll", 0)
gmsh.write("{}.msh".format("cube_mesh"))
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
This will output this view;
Using the same procedure, you can assign the surface tags for your geometry, and you can manually track the tag you are interested in.
You can find the full script here.
I hope that helps.