def METHOD_NAME(tempdir, d, n, codim, ghost_mode, encoding, dtype):
    mesh = mesh_factory(d, n, ghost_mode, dtype=dtype)
    edim = d - codim
    entities = locate_entities(mesh, edim, lambda x: x[0] > 0.4999)
    submesh = create_submesh(mesh, edim, entities)[0]
    # Check writing the mesh doesn't cause a segmentation fault
    filename = Path(tempdir, "submesh.xdmf")
    with XDMFFile(mesh.comm, filename, "w", encoding=encoding) as xdmf:
        xdmf.write_mesh(submesh)