The link
I suggested didnt suggest adding a physical tag, but using the embed command, as follows:
import gmsh
from mpi4py import MPI
from dolfinx.io.gmshio import model_to_mesh
from dolfinx.io import XDMFFile
# https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_gmsh.py
rank = MPI.COMM_WORLD.rank
gmsh.initialize()
R = 1
gdim = 2 # Geometric dimension of the mesh
model_rank = 0
mesh_comm = MPI.COMM_WORLD
if mesh_comm.rank == model_rank:
# Define geometry for background
background = gmsh.model.occ.addDisk(0, 0, 0, R, R)
gmsh.model.occ.synchronize()
# Define geometry for center
center = gmsh.model.occ.addPoint(0, 0, 0)
gmsh.model.occ.synchronize()
gmsh.model.mesh.embed(0, [center], 2, background)
background_domain = gmsh.model.addPhysicalGroup(gdim, [background], 1)
# Generate mesh
gmsh.model.mesh.field.add("Distance", 1)
gmsh.model.mesh.field.add("Threshold", 2)
gmsh.model.mesh.field.setNumber(2, "IField", 1)
gmsh.model.mesh.field.setNumber(2, "LcMin", 0.01)
gmsh.model.mesh.field.setNumber(2, "LcMax", 0.1)
gmsh.model.mesh.field.setNumber(2, "DistMin", 0.2)
gmsh.model.mesh.field.setNumber(2, "DistMax", 0.7)
gmsh.model.mesh.field.add("Min", 5)
gmsh.model.mesh.field.setNumbers(5, "FieldsList", [2])
gmsh.model.mesh.field.setAsBackgroundMesh(5)
gmsh.model.mesh.generate(gdim)
gmsh.model.mesh.optimize("Netgen")
domain, ct, _ = model_to_mesh(gmsh.model, mesh_comm, model_rank, gdim)
gmsh.finalize()
with XDMFFile(MPI.COMM_WORLD, "mt.xdmf", "w") as xdmf:
xdmf.write_mesh(domain)
xdmf.write_meshtags(ct)
import numpy as np
from dolfinx.mesh import locate_entities
print(locate_entities(domain, 0, lambda x: np.isclose(x[0],0) & np.isclose(x[1], 0)))
Please read through the links I post before asking a question.