When defining an Expression
for DirichletBC
, I noticed that this expression is evaluated on points which do not sit on the boundary. Why is this? Are there ways to prevent it?
The following code highlights the behavior:
from dolfin import *
from matplotlib import pyplot as pp
class MyExpr(Expression):
def eval(self, values, x):
values[0] = 0.0
pp.plot(x[0], x[1], 'xk')
return
my_expr = MyExpr()
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, 'CG', 2)
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(v)) * dx
L = v * dx
bcs = DirichletBC(V, my_expr, 'on_boundary')
sol = Function(V)
solve(a == L, sol, bcs=bcs)
pp.show()
This marks all points at which DirichletBC
is evaluated. Somewhat surprisingly, this does not only include points on the actual boudary, but also end- and midpoints of edges of cells adjecent to a boundary.