Hello,
I recently found a code for the cantilever beam with uniform distributed load problem. It works well with CG element type. I want it run with quadratic element type. So I tried to edit some codes inside.
The code is here:
from future import print_function
from dolfin import *
from fenics import *
import matplotlib.pyplot as plt
import mathL = 25.
H = 1.
Nx = 250
Ny = 10
mesh = RectangleMesh(Point(0., 0.), Point(L, H), Nx, Ny, “crossed”)def eps(v):
return sym(grad(v))E = Constant(1e5)
nu = Constant(0.3)lmbda = Enu/(1+nu)/(1-2nu)
mu = E/2/(1+nu)
lmbda = 2mulmbda/(lmbda+2*mu)def sigma(v):
return lmbdatr(eps(v))Identity(2) + 2.0mueps(v)rho_g = 1e-3
f = Constant((0, -rho_g))fe = VectorElement(“Quadrature”, cell=mesh.ufl_cell(), degree = 1, quad_scheme = “default”)
V = VectorFunctionSpace(mesh, fe, degree = 1)
du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du), eps(u_))*dx
l = inner(f, u_)*dxdef left(x, on_boundary):
return near(x[0],0.)bc = DirichletBC(V, Constant((0.,0.)), left)
u = Function(V, name=“Displacement”)
solve(a == l, u, bc)plot(1e3*u, mode=“displacement”)
plt.title(“2D elastic bending model”)
plt.xlabel(“length”)
plt.ylabel(“bending”)
plt.show()print(“Maximal deflection:”, -u(L,H/2.)[1])
print(“Beam theory deflection:”, float(3rho_gL4/2/E/H3))Vsig = TensorFunctionSpace(mesh, “DG”, degree=0)
sig = Function(Vsig, name=“Stress”)
sig.assign(project(sigma(u), Vsig))
print(“Stress at (0,H):”, sig(0, H))error = abs(-u(L,H/2.)[1] - float(3rho_gL4/2/E/H3))
print(error)
But the an err occurred:
runcell(0, ‘/Users/pigdtt12345/Desktop/Bill/FEniCS/Training/2D_elasticity_simple.py’)
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Symmetric part of tensor with rank != 2 is undefined.
Traceback (most recent call last):File “/Users/pigdtt12345/Desktop/Bill/FEniCS/Training/2D_elasticity_simple.py”, line 34, in
a = inner(sigma(du), eps(u_))*dxFile “/Users/pigdtt12345/Desktop/Bill/FEniCS/Training/2D_elasticity_simple.py”, line 25, in sigma
return lmbdatr(eps(v))Identity(2) + 2.0mueps(v)File “/Users/pigdtt12345/Desktop/Bill/FEniCS/Training/2D_elasticity_simple.py”, line 14, in eps
return sym(grad(v))File “/Users/pigdtt12345/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/operators.py”, line 318, in sym
return Sym(A)File “/Users/pigdtt12345/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/tensoralgebra.py”, line 457, in new
error(“Symmetric part of tensor with rank != 2 is undefined.”)File “/Users/pigdtt12345/opt/anaconda3/envs/fenicsproject/lib/python3.8/site-packages/ufl/log.py”, line 172, in error
raise self._exception_type(self._format_raw(*message))UFLException: Symmetric part of tensor with rank != 2 is undefined.
Could some please help me with it? I just want it work with “Quadrature” element type. I am sorry if I make some format error here. I am a new member with this qa forum.
Thanks a lot in advance.