I’m really sorry. I hope this serves the purpose:
#!/usr/bin/python2
from dolfin import *
tol = DOLFIN_EPS*1E3
youngs = 10E3
nu = 0.3
##################################
class DirichletBoundary(SubDomain):
def inside(self, x, on_boundary):
return ( (abs(x[1]) < tol or abs(x[1]-1) < tol) and on_boundary)
##################################
class InternalEdges(SubDomain):
def inside(self, x, on_boundary):
return (not on_boundary)
##################################
class InterfaceEdges(SubDomain):
def inside(self, x, on_boundary):
return (abs(x[1]-0.5)<tol)
##################################
def sigma(u):
return (youngs/(1.0-nu*nu))*((1.0-nu)*sym(grad(u))+nu*Identity(2)*tr(sym(grad(u))))
##################################
def tcohesive(x):
dn = jump(x,n)
tn = conditional(lt(dn,0.002),1.0,0.0)*dn
return as_vector([0.0,tn])
#################################
mesh = UnitSquareMesh(10,10)
boundaries = MeshFunction('size_t', mesh,mesh.topology().dim()-1)
DirichletBoundary().mark(boundaries, 1)
ds = Measure('ds', domain=mesh, subdomain_data=boundaries)
internals = MeshFunction('size_t', mesh,mesh.topology().dim()-1)
InternalEdges().mark(internals,2)
InterfaceEdges().mark(internals,3)
dS = Measure('dS', domain=mesh, subdomain_data=internals)
# Some geometric entities
n = FacetNormal(mesh)
h = CellSize(mesh)
h_avg = 0.5*(h('+')+h('-'))
alpha = 10.0*youngs/(4.0*h_avg*(1.0+nu)*(1.0-2.0*nu))
# Function spaces and functions
U = VectorElement('DG',mesh.ufl_cell(),1)
V = VectorFunctionSpace(mesh, 'DG', 1)
v = TestFunction(V)
u_ = Function(V)
bcs = [DirichletBC(V,Expression(('0.0','x[1]*0.004'), degree=2),DirichletBoundary(),"geometric")]
#bilinear form. the problem is in tcohesive(u_)
aVol = inner(sigma(u_),sym(grad(v)))
aBulk = -inner(outer(jump(v),n('+')),avg(sigma(u_)))-inner(outer(jump(u_),n('+')),avg(sigma(v)))+ alpha*dot(jump(u_),jump(v))
aCohesive = dot(jump(v),tcohesive(u_))
F = aVol*dx+aBulk*dS(2)+aCohesive*dS(3)
J = derivative(F, u_)
problem = NonlinearVariationalProblem(F, u_, bcs, J)
solver = NonlinearVariationalSolver(problem)
solver.solve()
T = TensorFunctionSpace(mesh,'DG',1)
s = project(sigma(u_),T)
File('./Stress.pvd')<<s
The example is rather long, because its a pretty special problem. To narrow it down: The problem clearly lies in the conditional in the function tcohesive. When I replace it with a simple mathematical expression (for example sin(dn)) the result is as expected. But when I use the conditional the result has nothing to do with the values I plugin or expect. The rest of the code works fine with no error messages.