Hello everyone,
I’m currently redo the example 2D linear elasticity from this link “2D linear elasticity — Numerical tours of continuum mechanics using FEniCS master documentation” in which they use dolfin.
When i try to rewrite the code in dolfinx, i got the error as below:
Symmetric part of tensor with rank !=2 is undefined.
My code:
from mpi4py import MPI
from dolfinx import mesh, fem, plot
from dolfinx.fem.petsc import LinearProblem
from ufl import sym, grad, tr, Identity, TrialFunction, TestFunction, inner, dx
L, H, Nx, Ny = 25., 1., 250, 10
domain = mesh.create_rectangle(MPI.COMM_WORLD,
[[0.0, 0.0], [L, H]],
[Nx, Ny],
mesh.CellType.quadrilateral,
)
def eps(v):
return sym(grad(v))
E = fem.Constant(domain, 1e5)
nu = fem.Constant(domain, 0.3)
model = “plane_stress”
mu = E/2/(1+nu)
lmbda = Enu/(1+nu)/(1-2nu)
if model ==“plane_stress”:
lmbda = 2mulmbda/(lmbda+2*mu)
def sigma(v):
return lmbda*tr(eps(v))Identity(2) + 2.0 * muesp(v)
rho_g = 1e-3
f = fem.Constant(domain, (0, -rho_g))
V = fem.functionspace(domain, (“Lagrange”, 2))
du= TrialFunction(V)
u_= TestFunction(V)
a = inner (sigma(du), eps(u_)) *dx
L = inner(f, u_)*dx
def left(x, on_boundary):
return x[0] < fem.DOLFINX_EPS
bc = fem.DirichletBC(V, fem.Constant((0.,0.)), left)
u = fem.Function(V, name=“Displacement”)
problem = LinearProblem(a, L, bcs=[bc], petsc_options={“ksp_type”: “preonly”, “pc_type”: “lu”})
uh = problem.solve()
plot(1e3uh, mode=“displacement”)
print(“Maximal deflection:”, -uh(L,H/2.)[1])
print(“Beam theory deflection:”, float(3rho_g*L4/2/E/H3))
If you experienced or had the solution, please share me.
Thank you so much for your reading!