High-level fem interface not checking for matching function space of BC

Issue #717 resolved
Jan Blechta created an issue

The following code demonstrates that it is easy to pass wrong bc to solve (probably to FooVariationalSolver as well) and obtain junk.

from dolfin import *
import numpy as np

mesh = IntervalMesh(10,0,1)
P1 = FiniteElement("P", mesh.ufl_cell(), 1)
B2 = FiniteElement("B", mesh.ufl_cell(), 2)
Q = FunctionSpace(mesh, P1)
V = FunctionSpace(mesh, P1+B2)

u = TrialFunction(V)
v = TestFunction(V)
a = u*v*dx
L = Constant(0)*v*dx

bc = DirichletBC(Q, 1.0, lambda x,b:True) # Wrong

#uD = project(Constant(1.0), V) # Workaround to FFC #69; unimportant here
#bc = DirichletBC(V, uD, lambda x,b:True) # Correct

u = Function(V)
solve(a == L, u, bc)

# We should get constant solution equal to one
assert np.all(np.isclose(u.compute_vertex_values(), 1.0))

Wil fix this in branch jan/check-bc-space. First need FunctionSpace::contains(FunctionSpace&).

On algebraic level, dimension checks in DirichletBC::apply would be helpful.

Comments (1)

  1. Log in to comment