Hello everyone, I am trying to extract the diagonal of the stress tensor in UFL format and form a diagonal tensor.
Here is my code:
from dolfin import *
from ufl import diag
def epsilon(u):
return sym(grad(u))
def sigma(u):
return 2.0 * mu * epsilon(u) + lmbda * tr(epsilon(u)) * Identity(2)
sigma_diag = diag(sigma(u))
The following is the error message:
Traceback (most recent call last):
File “/mnt/c/xx_files/研究生资料/课题资料/FEnics/Tensionenergyxx2.py”, line 211, in
E_phi = ( Gc(unew)l_oinner(grad(p),grad(q))+
File “/mnt/c/xx_files/研究生资料/课题资料/FEnics/Tensionenergyxx2.py”, line 162, in Gc
sigma_diag = diag(sigma(u))
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/operators.py”, line 282, in diag
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 297, in as_matrix
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 251, in as_tensor
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 203, in as_list_tensor
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 203, in
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 203, in as_list_tensor
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 203, in
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/tensors.py”, line 206, in as_list_tensor
File “/home/xx/.local/lib/python3.10/site-packages/fenics_ufl-2019.1.0-py3.10.egg/ufl/constantvalue.py”, line 471, in as_ufl
ufl.log.UFLValueError: Invalid type conversion: (({ A | A{i{58}, i{59}} = 161540.0 * (sym(grad(f_54)))[i_{58}, i_{59}] }) + ({ A | A_{i_{60}, i_{61}} = I[i_{60}, i_{61}] * 121150.0 * (tr(sym(grad(f_54)))) }))[0, 0] can not be converted to any UFL type.
The error message shows that the input to diag is not a tensor. I believe that the stress tensor is a tensor. How should I modify it? Thank you very much