Error message: ‘Mesh’ object has no attribute ‘geometric_dimension’

Hello!

I am getting an error when trying to calculate the strain of a finite element displacement. The final error message is: ‘Mesh’ object has no attribute ‘geometric_dimension’.
I read others topics in this discourse group about the same issue, but I still could not solve it.
My code is as follows:

from dolfinx import fem, io, mesh, plot
import ufl

from mpi4py import MPI
# from petsc4py import PETSc

def eps(u):
   return ufl.sym(ufl.grad(u))

msh = mesh.create_rectangle(
   comm=MPI.COMM_WORLD,
   points=((0.0, 0.0), (2.0, 1.0)),
   n=(32, 16),
   cell_type=mesh.CellType.triangle,
)
element = ufl.VectorElement("Lagrange","triangle",2)
V = ufl.FunctionSpace(msh, element)

v = ufl.TestFunction(V)
print(eps(v)) # just to see if eps(v) is computed

Any suggestion is welcome.

You should use dolfinx.fem.FunctionSpace (dolfinx.fem.functionspace if you are on main branch), and not ufl.FunctionSpace when you are using the DOLFINx Python interface.