How to solve module 'dolfin.mesh' has no attribute 'ufl_cell' problem

I’m getting "module ‘dolfin.mesh’ has no attribute ‘ufl_cell’ " error while analyzing a 3D structure for linear elasticity. The error expression is like this:


AttributeError Traceback (most recent call last)
in ()
12 return lp_f
13
—> 14 V0 = TensorFunctionSpace(mesh, “DG”, 0)
15 stress_2 = local_project(stress, V0)
16

/usr/local/lib/python3.7/dist-packages/dolfin/function/functionspace.py in TensorFunctionSpace(mesh, family, degree, shape, symmetry, constrained_domain, restriction)
251
252 # Create UFL element
→ 253 element = ufl.TensorElement(family, mesh.ufl_cell(), degree,
254 shape, symmetry)
255

AttributeError: module ‘dolfin.mesh’ has no attribute ‘ufl_cell’

I’m very new to FEniCS, so as far as I understand, it is not possible to change a “mesh.ufl_cell()” in a built-in function. Might there be another reason of this error?

The quickest way for me to reproduce this error message is:

from dolfin import *
mesh.ufl_cell()

Notice that the variable mesh was never defined as a DOLFIN Mesh object, e.g.,

mesh = UnitIntervalMesh(8)

before being invoked. If you run

from dolfin import *
print(type(mesh))

you can see that it is a module that gets imported with dolfin, whereas if you run

from dolfin import *
mesh = UnitIntervalMesh(8)
print(type(mesh))
print(isinstance(mesh,Mesh))

it is a dolfin.cpp.generation.UnitIntervalMesh, which is an instance of Mesh. The code

from dolfin import *
mesh = UnitIntervalMesh(8)
mesh.ufl_cell()

runs without error.

3 Likes

I’d used pymgsh to generate mesh. I think the problem occured during importing the mesh into the dolfin. After your instructions, I controlled the type and being instance of Mesh function. After that, I could find out the problem. Thanks!