I am trying to do some changes in my mesh. Therefore i have to change some connections of the cells. First i wanted to create a mesh and meshtag out of the existing mesh without changes.
The mesh was initially created with gmsh and is loaded with following command:
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, filename, "r") as xdmf:
self.mesh = xdmf.read_mesh(name="Grid")
self.subdomains = xdmf.read_meshtags(msh, name='Grid')
From the connections and meshtag information i wanted to create the same mesh again:
cells = self.subdomains.topology.connectivity(2, 0)
con_vec = []
entity_vec = []
value_vec = []
# Get dof layout for each cell
num_entities = self.mesh.topology.index_map(2).size_local + self.mesh.topology.index_map(2).num_ghosts
for entity in range(num_entities):
entities = cells.links(entity)
con_vec.append(entities)
ind = self.subdomains.indices[entity]
entity_vec.append(ind)
value_vec.append(self.subdomains.values[ind])
entity_vec = np.array(entity_vec, dtype=np.int32)
con_vec = np.array(con_vec, dtype=np.int64)
xpos = []
for i, xi in enumerate(self.mesh.geometry.x[:]):
xpos.append([xi[0], xi[1]])
self.mesh = create_mesh(MPI.COMM_WORLD, con_vec, xpos, self.mesh._ufl_domain)
self.subdomains = meshtags(self.mesh, 2, entity_vec, value_vec)
The mesh itself looks good and identical to before. But the meshtag are not connected to the right cell positions.
I am sure i am doing something wrong, but can’t understand what and why it is not working. Sry in the case i am doing something complete wrong, Still a beginner in this topics
I am using DOLFINx version: 0.7.2