Thank you for your reply! Due to my lack of familiarity with forum usage, I apologize for any inconvenience caused. I would like to reiterate my question: I need to extract the diagonal part of the stress tensor (that is, extract the diagonal elements of the stress tensor as a diagonal matrix) during relevant mathematical calculations
But since the tensor storage in Fenics is in UFL format, I cannot use numpy to extract diagonal lines. What method should I use to achieve my goal?
Here is the code and error reports
from dolfin import*
import ufl
a = Identity(2)
b = ufl.diag(a)
Traceback (most recent call last):
File “”, line 1, in
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: 1 can not be converted to any UFL type.