Hi! I am a beginner to this environment. In my project, especially in learning, I am facing an error in finding sym(grad(v)) value. I am using an example which is done by using FEniCSx mesh but i replaced the mesh part with my gmsh’s .msh file using meshio. Here I provide my code and error. It will be great if you help me in this learning. My dolfinx version is 0.8.0 and Python version is 3.11.7.
<
E = fem.Constant(domain, 210e3)
nu = fem.Constant(domain, 0.3)
lmbda = E * nu / (1 + nu) / (1 - 2 * nu)
mu = E / 2 / (1 + nu)
def epsilon(v):
return sym(grad(v))
def sigma(v):
return lmbda * tr(epsilon(v)) * Identity(dim) + 2 * mu * epsilon(v)
print(“mu (UFL):\n”, mu)
print(“epsilon (UFL):\n”, epsilon(u_sol))
print(“sigma (UFL):\n”, sigma(u_sol))
<
The error i get is :
ValueError Traceback (most recent call last)
Cell In[33], line 2
1 print(“mu (UFL):\n”, mu)
----> 2 print(“epsilon (UFL):\n”, epsilon(u_sol))
3 print(“sigma (UFL):\n”, sigma(u_sol))
Cell In[32], line 9, in epsilon(v)
8 def epsilon(v):
----> 9 return sym(grad(v))
File ~/anaconda3/envs/fenicsx/lib/python3.12/site-packages/ufl/operators.py:337, in sym(A)
335 “”“Take the symmetric part of A.”“”
336 A = as_ufl(A)
→ 337 return Sym(A)
File ~/anaconda3/envs/fenicsx/lib/python3.12/site-packages/ufl/tensoralgebra.py:544, in Sym.new(cls, A)
542 raise ValueError(“Symmetric part of tensor with rank != 2 is undefined.”)
543 if sh[0] != sh[1]:
→ 544 raise ValueError(
545 f"Cannot take symmetric part of rectangular matrix with dimensions {sh}."
546 )
547 if Afi:
548 raise ValueError(“Not expecting free indices in Sym.”)
ValueError: Cannot take symmetric part of rectangular matrix with dimensions (2, 3).
Please refer images for more clarity.