Getting an Attribute Error : 'Mesh' object has no attribute 'ufl_cell'

My code is as follows

import dolfinx
import meshio
def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    # This line needs to get cell data from what ever the markers have been called in the vtk file.
    # Expore this by printing mesh.cell_data
    # cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    if prune_z:
         points = mesh.points[:,:2] 
    else:
         points = mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells})
    #, cell_data={"name_to_read":[cell_data]})
    return out_mesh

domain = meshio.read("testrve.xdmf")
import numpy as np
from mpi4py import MPI
from dolfinx.cpp.mesh import CellType
from dolfinx.io import (XDMFFile)
from dolfinx import mesh, fem, plot, io
from dolfinx.fem import FunctionSpace
V = dolfinx.fem.FunctionSpace(domain, ("CG", 2))

I am using the gmshModel API to create my mesh file. I am using the docker image of the Jupyter notebook for using FeniCSx. I was using the create_mesh function provided on this forum, but I think that is no longer required since I am directly using an xdmf file.

You cannot read in the xdmf file with meshio , and use it in DOLFINx.
You need to use the dolfinx.io.XDMFFile interface to read in such meshes, see for instance: Defining subdomains for different materials — FEniCSx tutorial

Yes, that worked. However now there is another issue, I get a RuntimeError: Cannot recognise cell type. Unknown value: mixed. I believe this has to do with the .xdmf file. I have pasted what I see in Notepad++ when I open the .xdmf file.

> <Xdmf Version="3.0">
> <Domain><Grid Name="Grid">
> <Geometry GeometryType="XYZ">
> <DataItem DataType="Float" Dimensions="4151 3" Format="HDF" Precision="8">testrve.h5:/data0</DataItem>
> </Geometry><Topology TopologyType="Mixed" NumberOfElements="8130">
> <DataItem DataType="Int" Dimensions="32520" Format="HDF" Precision="4">testrve.h5:/data1</DataItem>
> </Topology><Attribute Name="gmsh:dim_tags" AttributeType="Vector" Center="Node">
> <DataItem DataType="Int" Dimensions="4151 2" Format="HDF" Precision="4">testrve.h5:/data2</DataItem></Attribute>
> <Attribute Name="gmsh:physical" AttributeType="Scalar" Center="Cell">
> <DataItem DataType="Int" Dimensions="8130" Format="HDF" Precision="4">testrve.h5:/data3</DataItem>
> </Attribute><Attribute Name="gmsh:geometrical" AttributeType="Scalar" Center="Cell">
> <DataItem DataType="Int" Dimensions="8130" Format="HDF" Precision="4">testrve.h5:/data4</DataItem>
> </Attribute>
> </Grid>
> </Domain>
> </Xdmf>
import dolfinx
from dolfinx.io import (XDMFFile)
import numpy as np
from mpi4py import MPI
from dolfinx.cpp.mesh import CellType

from dolfinx import mesh, fem, plot, io
from dolfinx.fem import FunctionSpace
def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    # This line needs to get cell data from what ever the markers have been called in the vtk file.
    # Expore this by printing mesh.cell_data
    # cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    if prune_z:
         points = mesh.points[:,:2] 
    else:
         points = mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells})
    #, cell_data={"name_to_read":[cell_data]})
    return out_mesh

with XDMFFile(MPI.COMM_WORLD, "testrve.xdmf", "r") as xdmf:
    domain = xdmf.read_mesh(name="Grid")
print(domain)
V = dolfinx.fem.FunctionSpace(domain, ("CG", 1))

This is my new code

This has been covered in various other topics, which you can find by searching for

on the forum.
An appropriate create_mesh function is also created at Defining subdomains for different materials — FEniCSx tutorial
which I already referred you to.

Actually it was a problem caused by my modification of the API code, I believe I have rectified it.
Thank You