Consider the following example for generating a domain with a slit.
from dolfin import *
from mshr import *
from matplotlib import pyplot
parameters["plotting_backend"] = "matplotlib"
N = 40
r = 1.0
l = 1.0
w = 1e-2
D = Circle(Point(0.,0.), 1)
# define polygon to cut out,
c = Polygon([Point(-l/2,0), Point(0,-w), Point(l/2,0), Point(0, w)])
domain = D - c
mesh = generate_mesh(domain, N)
# mark the different parts of the boundary
boundary = CompiledSubDomain("on_boundary")
inner_boundary = CompiledSubDomain("on_boundary&&(fabs(x[0])<l)&&(fabs(x[1])<w+t)",
l = l, w = w, t = DOLFIN_EPS)
facet_domains = FacetFunction("size_t", mesh)
boundary.mark(facet_domains, 1)
inner_boundary.mark(facet_domains, 2)
# move mesh to close the gap in the domain
W = VectorFunctionSpace(mesh, "CG", 1)
t = Function(W)
DirichletBC(W, Expression(("0", "-x[1]"), degree = 1), facet_domains, 2).apply(t.vector())
ALE.move(mesh, t)
pyplot.figure()
plot(mesh)
pyplot.show()
Solving Laplace equation with Dirichlet boundaries:
V = FunctionSpace(mesh, "CG", 1)
u, v = TrialFunction(V), TestFunction(V)
a = inner(grad(u), grad(v)) * dx
L = Constant(0.) * v * dx
bcs = [DirichletBC(V, Constant(0.0), facet_domains, 1),
DirichletBC(V, Constant(1.0), facet_domains, 2)]
uh = Function(V)
solve(a == L, uh, bcs)
pyplot.figure()
plot(uh)
pyplot.show()
You can also have discontinuity across the slit, for example with a Neumann boundary condition on the slit:
bcs = DirichletBC(V, Expression("x[1]", degree = 1), facet_domains, 1)
solve(a == L, uh, bcs)
pyplot.figure()
plot(uh)
pyplot.show()