Deepcopy of meshes

Consider the following:

from dolfinx.mesh import create_unit_square, CellType, Mesh
from mpi4py import MPI
import numpy as np
comm = MPI.COMM_WORLD

no_elem = 5
mesh_II = create_unit_square(comm, no_elem, no_elem, CellType.triangle)

mesh_I = Mesh(mesh_II.comm, mesh_II.topology, mesh_II.geometry, mesh_II.ufl_domain())
mesh_I.geometry.x[:, 0] += 1
geom_II = mesh_II.geometry.x.copy()
geom_II[:, 0] += 1
assert(np.allclose(geom_II, mesh_I.geometry.x))
print(np.isclose(mesh_II.geometry.x, mesh_I.geometry.x))
print(mesh_II.geometry.x, mesh_I.geometry.x)

Is there a specific reason you would like to deepcopy your mesh?

1 Like