Hi,
I am a beginner in fenics, i would like to simulate the compression of a box, i did the simulation but resulats (using paraview) was illogical especially for the Von Mises. Can you find the mistakes made in my code:
from fenics import *
from ufl import nabla_div
rho = 1500e-9
E = 3000.2
nu = 0.38
mu = E/(2*(1+nu))
lambda_ = (nu*E)/((1+nu)*(1-2*nu))
tol=1E-9
mesh = BoxMesh(Point(0,0,0),Point(100,100,100),20,20,20)
class BoundaryBottom(SubDomain):
def inside(self, x, on_boundary):
return x[2]<0+tol
class BoundaryTop(SubDomain):
def inside(self, x, on_boundary):
return x[2]>100-tol
sub_domains = MeshFunction('size_t', mesh, mesh.topology().dim())
sub_domains.set_all(0)
boundaryBottom = BoundaryBottom()
boundaryBottom.mark(sub_domains, 1)
boundaryTop = BoundaryTop()
boundaryTop.mark(sub_domains, 2)
V = VectorFunctionSpace(mesh, 'P', 1)
u = TrialFunction(V)
v = TestFunction(V)
bc1= DirichletBC(V, Constant((0,0,0)), boundaryBottom)
bc2= DirichletBC(V, Constant((0,0,-30)), boundaryTop)
bc=[bc1,bc2]
d = u.geometric_dimension()
def epsilon(u):
return sym(grad(u))
def sigma(u):
return 2*mu*epsilon(u) + lambda_*nabla_div(u)*Identity(d)
a = inner(sigma(u), epsilon(v))*dx
f= Constant((0,0,0))
L = dot(f,v)*ds
u=Function(V)
solve(a==L, u, bc)
vtkfile = File('u.pvd')
vtkfile << u
s = sigma(u) - (1./3)*tr(sigma(u))*Identity(d)
W = FunctionSpace(mesh, 'CG', 0)
von_Mises = project(sqrt (3/2.* inner (s, s) ), W)
vtkfile = File('s.pvd')
vtkfile << von_Mises
Thanks in advance for your help!