# Mesh.create\_mesh runtime error: A facet is connected to more than two cells

**URL:** <https://fenicsproject.discourse.group/t/mesh-create-mesh-runtime-error-a-facet-is-connected-to-more-than-two-cells/14905>\
**Category:** dolfinx\
**Tags:** dolfinx, error\
**Created:** [June 6, 2024, 8:46am UTC](https://fenicsproject.discourse.group/t/mesh-create-mesh-runtime-error-a-facet-is-connected-to-more-than-two-cells/14905 "2024-06-06T08:46:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenyongxin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chenyongxin/32/6501_2.png) [@chenyongxin](https://fenicsproject.discourse.group/u/chenyongxin)\
**Post date:** [June 6, 2024, 8:46am UTC](https://fenicsproject.discourse.group/t/mesh-create-mesh-runtime-error-a-facet-is-connected-to-more-than-two-cells/14905/1 "2024-06-06T08:46:19Z")

</div>

I tried to use `dolfinx.mesh.create_mesh` to copy a mesh (from `mesh0` to `mesh1`). Consider the following in v0.8.0:

```auto
from mpi4py import MPI
from dolfinx import mesh

comm = MPI.COMM_WORLD
mesh0 = mesh.create_unit_square(comm, 4, 4)
mesh1 = mesh.create_mesh(comm, mesh0.geometry.dofmap, mesh0.geometry.x, mesh0.ufl_domain())

```

Run with multiple processes and runtime error occured: A facet is connected to more than two cells. I guess it is due to ghosts included?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 6, 2024, 9:09am UTC](https://fenicsproject.discourse.group/t/mesh-create-mesh-runtime-error-a-facet-is-connected-to-more-than-two-cells/14905/2 "2024-06-06T09:09:52Z")

</div>

To re-create a mesh in parallel, you would need to map the geometry to its global indices (and probably send in a custom partitioner keeping the mesh partitioning the same).

---

<div class="post-metadata">

**Author:** ![chenyongxin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chenyongxin/32/6501_2.png) [@chenyongxin](https://fenicsproject.discourse.group/u/chenyongxin)\
**Post date:** [June 6, 2024, 9:42am UTC](https://fenicsproject.discourse.group/t/mesh-create-mesh-runtime-error-a-facet-is-connected-to-more-than-two-cells/14905/3 "2024-06-06T09:42:29Z")

</div>

Looks complicated, and any advice on the implementation?

In my case, I have a original mesh `mesh0`. In every time step, I need to copy `mesh0` to `mesh_current` where the nodes are moved and functionspaces are built. I usually use save & load method, but it is expensive when mesh is large:

```auto
# Pseudo code

# Save, with `mesh0` is ready
io.XDMFFile(MPI.COMM_WORLD, filename, "w").write_mesh(mesh0)

while t < t_end:
        
        # Load
        mesh_current = io.XDMFFile(MPI.COMM_WORLD, filename, "r").read_mesh()

        # Move mesh
        mesh_current.geometry.x[:, :tdim] += disp.x.array.reshape((-1, tdim))

        V = fem.functionspace(mesh_current, ("Lagrange", 1, (tdim,)))

```

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [June 6, 2024, 9:56am UTC](https://fenicsproject.discourse.group/t/mesh-create-mesh-runtime-error-a-facet-is-connected-to-more-than-two-cells/14905/4 "2024-06-06T09:56:56Z")

</div>

Why is it that you need to copy the mesh at all?

If all you need to have is the ability to go back to the original mesh after deformation, the only thing you need to save is the coordinates of its vertices with `mesh.geometry.x.copy()` before you deform it.
