from future import print_function
from dolfin import *
from fenics import *
import time
variables
E=7109 #Young modulus
nu=0.33 #Poisson coefficient
rho=2700 #Density
lamda=6*109 #Lame coefficient
mu = 510**9
Time stepping
Time =2 # final time
steps=50 # numb of steps
dt=Time/steps # time step size
dolfin-convert plaque.msh plaque.xml
import os
os.system ('dolfin-convert plaque.msh plaque.xml')
Generate mesh
mesh=Mesh("plaque.xml")
create mesh
mesh = UnitSquareMesh(8, 8)
Define function space
V=VectorFunctionSpace(mesh,'Lagrange',2)
Define initial Values
u0=Constant ((0,0))
u1=Constant ((0,0))
define boundary condition
def left(x, on_boundary):
return x[0]<0.0001 and on_boundary
bc_left=DirichletBC(V, u0,left)
def free(x,on_boundary):
return x[0]>0.0001 and on_boundary
bc_free=DirichletBC(V,u1 ,free)
bcs=[bc_left,bc_free]
u_prev0=project(u0,V)
u_prev1=project(u1,V)
Define strain and stress
def epsilon(u):
return 0.5*(nabla_grad(u)+ nabla_grad(u).T)
def sigma(u):
return lamdanabla_div(u)Identity(len(u)) + 2muepsilon(u)
u = TrialFunction(V)
v = TestFunction(V)
d = u.geometric_dimension() #dimension space
f = Constant((0,0)) #body forces=0
traction = Constant((0,1))
a = inner(u,v)dx
L = inner (u_prev1,v)dx + 2inner(u_prev0,v)dx + ((dt**2)/2)inner(sigma(u_prev0),epsilon(v))dx+ inner (traction,v)*ds
for t in range (steps):
u = Function(V)
t += dt
solve (a == L, u, bcs)
Save to file and plot solution
vtkfile << (u, t)
plot(u)
Update previous solution
u_prev0.assign(u)
u_prev1.assign(u_prev0)
Hold plot
interactive()