I want to make a code bend test using phase field method for brittle fracture. This is the code I am making, following the idea of the paper (Hirshikesh et al):
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
import math
# Mesh
vertices=[Point(0,0.4),Point(0.1,0),Point(4,0),Point(4,2),Point(-4,2),Point(-4,0),Point(-0.1,0)]
domain=Polygon(vertices)
mesh=generate_mesh(domain, 100)
# Define Space
V = FunctionSpace(mesh, 'CG', 1)
W = VectorFunctionSpace(mesh, 'CG', 1)
WW = FunctionSpace(mesh, 'DG', 0)
p, q = TrialFunction(V), TestFunction(V)
u, v = TrialFunction(W), TestFunction(W)
# Introduce manually the material parameters
Gc = 0.54
l = 2*mesh.hmin()
lmbda =12e3
mu = 8e3
# Constituive functions
def epsilon(u):
return sym(grad(u))
def sigma(u):
return 2.0*mu*epsilon(u)+lmbda*tr(epsilon(u))*Identity(len(u))
def psi(u):
return 0.5*(lmbda+mu)*(0.5*(tr(epsilon(u))+abs(tr(epsilon(u)))))**2+mu*inner(dev(epsilon(u)),dev(epsilon(u)))
def H(uold,unew,Hold):
return conditional(lt(psi(uold),psi(unew)),psi(unew),Hold)
# Boundary conditions
class top(SubDomain):
def inside(self, x, on_boundary):
return near(x[0],0,1e-2) and near(x[1],2,1e-2)
def bot1(x,on_boundary):
return on_boundary and near(x[0],-4) and near(x[1],0)
def bot2(x,on_boundary):
return on_boundary and near(x[0],4) and near(x[1],0)
load = Expression("t", t = 0.0, degree=1)
bcbot1= DirichletBC(W, Constant((0,0)), bot1)
bcbot2= DirichletBC(W, Constant((0,0)), bot2)
bctop = DirichletBC(W.sub(1), load, top)
bc_u = [bcbot1, bcbot2, bctop]
bc_phi = []
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
top.mark(boundaries,2)
ds = Measure("ds")(subdomain_data=boundaries)
n = FacetNormal(mesh)
# Variational form
unew, uold = Function(W), Function(W)
pnew, pold, Hold = Function(V), Function(V), Function(V)
E_du = ((1.0-pold)**2)*inner(grad(v),sigma(u))*dx
E_phi = (Gc*l*inner(grad(p),grad(q))+((Gc/l)+2.0*H(uold,unew,Hold))\
*inner(p,q)-2.0*H(uold,unew,Hold)*q)*dx
p_disp = LinearVariationalProblem(lhs(E_du), rhs(E_du), unew, bc_u)
p_phi = LinearVariationalProblem(lhs(E_phi), rhs(E_phi), pnew, bc_phi)
solver_disp = LinearVariationalSolver(p_disp)
solver_phi = LinearVariationalSolver(p_phi)
# Initialization of the iterative procedure and output requests
t = 0
u_r = 0.001
deltaT = 0.1
tol = 1e-3
conc_f = File ("./Bend_Test/phi.pvd")
fname = open('ForcevsDisp_Bend_Test.txt', 'w')
x=[]
y=[]
# Staggered scheme
while t<=5:
t += deltaT
load.t=t*u_r
iter = 0
err = 1
while err > tol:
iter += 1
solver_disp.solve()
solver_phi.solve()
err_u = errornorm(unew,uold,norm_type = 'l2',mesh = None)
err_phi = errornorm(pnew,pold,norm_type = 'l2',mesh = None)
err = max(err_u,err_phi)
uold.assign(unew)
pold.assign(pnew)
Hold.assign(project(psi(unew), WW))
if err < tol:
print ('Iterations:', iter, ', Total time', t)
if round(t*1e4) % 10 == 0:
conc_f << pnew
Traction = dot(sigma(unew),n)
fy = Traction[1]*ds(1)
fname.write(str(t*u_r) + "\t")
fname.write(str(assemble(fy)) + "\n")
x.append(str(t*u_r))
y.append(str(round(assemble(fy)*1e-3,1)))
print("Force:", str(round(assemble(fy)*1e-3,1)),'kN')
print("Displacement:",str(t*u_r),'mm')
fname.close()
print ('Simulation completed')
And this is the mesh, with different restrictions for the bottom:
So I got an error with the bctop:
RuntimeError: Invalid argument
Can anyone help me?