Is the matrix dimension calculated by the stress and strain functions here 2 * 2?
Why did I output the :np. shape of these two matrices during the calculation process and get () - an empty parenthesis
And I would like to ask what is the difference between Identity (2) and np. identity (2)? It seems to be related to the dimensionality of the matrix.
The reason for asking this question is because I want to extract the diagonal of the stress tensor through np. diagonal (sigma), but it has been unsuccessful.
Make a minimal reproducible example, i.e. a code that people can run and reproduce your output. Usually, it is common to use one of the “built-in” meshes, such as an interval, square or cube mesh.
Note that FEniCS uses UFL for the syntax of the variational form, thus you would have to use something along the lines of ufl package — Unified Form Language (UFL) 2021.1.0 documentation and project/interpolate this into an appropriate space, depending on what version of dolfin you are using (legacy or DOLFINx).
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.