# Getting an Attribute Error : 'Mesh' object has no attribute 'ufl\_cell'

**URL:** <https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211>\
**Category:** mesh\
**Created:** [September 5, 2022, 8:40am UTC](https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211 "2022-09-05T08:40:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarvesh\_Sontakke](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sarvesh_sontakke/32/4092_2.png) [@Sarvesh\_Sontakke](https://fenicsproject.discourse.group/u/Sarvesh_Sontakke)\
**Post date:** [September 5, 2022, 8:40am UTC](https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211/1 "2022-09-05T08:40:18Z")

</div>

My code is as follows

```auto
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.

---

<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:** [September 5, 2022, 9:19am UTC](https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211/2 "2022-09-05T09:19:38Z")

</div>

> [@Sarvesh\_Sontakke](#):
>
> ```auto
> 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))
> 
> ```

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](https://jorgensd.github.io/dolfinx-tutorial/chapter3/subdomains.html?highlight=read_mesh#convert-msh-files-to-xdmf-using-meshio)

---

<div class="post-metadata">

**Author:** ![Sarvesh\_Sontakke](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sarvesh_sontakke/32/4092_2.png) [@Sarvesh\_Sontakke](https://fenicsproject.discourse.group/u/Sarvesh_Sontakke)\
**Post date:** [September 5, 2022, 9:50am UTC](https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211/3 "2022-09-05T09:50:25Z")

</div>

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.

```auto
> <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>

```

```auto
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

---

<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:** [September 5, 2022, 11:10am UTC](https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211/4 "2022-09-05T11:10:35Z")

</div>

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

> [@Sarvesh\_Sontakke](#):
>
> Unknown value: mixed

on the forum.  
An appropriate `create_mesh` function is also created at [Defining subdomains for different materials — FEniCSx tutorial](https://jorgensd.github.io/dolfinx-tutorial/chapter3/subdomains.html?highlight=read_mesh#convert-msh-files-to-xdmf-using-meshio)  
which I already referred you to.

---

<div class="post-metadata">

**Author:** ![Sarvesh\_Sontakke](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/sarvesh_sontakke/32/4092_2.png) [@Sarvesh\_Sontakke](https://fenicsproject.discourse.group/u/Sarvesh_Sontakke)\
**Post date:** [September 5, 2022, 11:18am UTC](https://fenicsproject.discourse.group/t/getting-an-attribute-error-mesh-object-has-no-attribute-ufl-cell/9211/5 "2022-09-05T11:18:48Z")

</div>

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