Hi everyone,
FEniCS generates an error while using the cofac()
function from UFL. Its a simple code where I generate a mesh, create a vector function space, create a function in the vector function space, calculate the identity tensor using the geometric dimension, create a deformation gradient tensor, and then calculate the cofactor of the deformation gradient tensor.
Here is the MWE:
from dolfin import *
from ufl import cofac
mesh = UnitCubeMesh(24, 16, 16) # Defining cubic mesh
V = VectorFunctionSpace(mesh, "Lagrange", 1) # Defining order 1 Lagrange Vector Function Space
u = Function(V) # Creating element from V
d = u.geometric_dimension() # Calculating dimension of geometry
I = Identity(d) # Identity tensor with order of geometric dimension
F = I + grad(u) # Calculating deformation gradient tensor
cofac_F = cofac(F) # Calculating cofactor of F
This generates the error:
cofac_F = cofac(F)
File "/usr/lib/python3/dist-packages/ufl/operators.py", line 218, in cofac
A = as_ufl(A)
File "/usr/lib/python3/dist-packages/ufl/constantvalue.py", line 501, in as_ufl
raise ValueError(
ValueError: Invalid type conversion: I + (grad(f_5)) can not be converted to any UFL type.
What am I doing wrong here?
Please advise.
Thanks in advance!