 # NonlinearVariationalProblem not working

Hello Everyone,
I am trying to extend the Phasefield modeling from brittle fracture to cohesive fracture. Therefore, my advection-diffusion equation needs to solve using nonlinear variational formulation. I am extending the code to cohesive fracture. Can anyone show me how to implement it using nonlinear problem. At this point there’s no change in constitutive equation. Here is the code:

``````# Preliminaries and mesh
from dolfin import *
import mshr
dom1 = mshr.Rectangle(Point(-0.50, -0.5), Point(0.5, 0.50))
dom2 = mshr.Rectangle(Point(-0.5, 0.0-1e-05), Point(0.0, 0.0+0.0+1e-05))
dom = dom1 - dom2
mesh = mshr.generate_mesh(dom, 40)

# Define Space
V = FunctionSpace(mesh, 'CG', 1)
W = VectorFunctionSpace(mesh, 'CG', 1)
WW = FunctionSpace(mesh, 'DG', 0)
p, q = Function(V), TestFunction(V)
u, v = TrialFunction(W), TestFunction(W)

# Introduce manually the material parameters
Gc =  2.7
l = 0.015
lmbda = 121.1538e3
mu = 80.7692e3

# Constituive functions
def epsilon(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
top = CompiledSubDomain("near(x, 0.5) && on_boundary")
bot = CompiledSubDomain("near(x, -0.5) && on_boundary")
def Crack(x):
return abs(x) < 1e-03 and x <= 0.0
load = Expression("t", t = 0.0, degree=1)
bcbot= DirichletBC(W, Constant((0.0,0.0)), bot)
bc_u = [bcbot, bctop]
bc_phi = [DirichletBC(V, Constant(1.0), Crack)]
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
top.mark(boundaries,1)
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)
*inner(p,q)-2.0*H(uold,unew,Hold)*q)*dx
J = derivative(E_phi, pnew)

p_disp = LinearVariationalProblem(lhs(E_du), rhs(E_du), unew, bc_u)
p_phi = NonlinearVariationalProblem(E_phi, pnew, bc_phi, J=J)
solver_disp = LinearVariationalSolver(p_disp)
solver_phi = NonlinearVariationalSolver(p_phi)

# Initialization of the iterative procedure and output requests
t = 0
u_r = 0.007
deltaT  = 0.1
tol = 1e-3
conc_f = File ("./ResultsDir/phi.pvd")
fname = open('ForcevsDisp.txt', 'w')

# Staggered scheme
while t<=0.90:
t += deltaT
if t >=0.7:
deltaT = 0.01
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*ds(1)
fname.write(str(t*u_r) + "\t")
fname.write(str(assemble(fy)) + "\n")

fname.close()
print ('Simulation completed')
``````