The code below is from http://fenicsproject.org/qa/7607/working-with-boundarymesh?show=7607#q7607, but this question is in its own right:
I have a function that is defined on (a functionspace of a submesh of a boundarymesh of)
a boundary, and I wish to use it in a surface-integral of the whole domain.
from dolfin import *
import numpy as np
parameters["allow_extrapolation"] = True
degree = 2
mesh = UnitSquareMesh(20, 20)
class LeftBoundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)
leftboundary = LeftBoundary()
boundaries = FacetFunction('size_t', mesh)
boundaries.set_all(0)
leftboundary.mark(boundaries, 1)
ds = Measure('ds')[boundaries]
boundarymesh = BoundaryMesh(mesh, 'exterior')
left_mesh = SubMesh(boundarymesh, leftboundary)
L = FunctionSpace(left_mesh, 'CG', degree)
bf = Function(L)
# here goes some more code to find the correct bf
# but here a dummy function will do
bf.vector()[:] = np.ones(20*degree + 1, dtype=float)
V = FunctionSpace(mesh, 'CG', degree)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v)) * dx
b = interpolate(bf, V) * v * ds(1)
# b = project(bf, V) * v * ds(1)
assemble(b)
The code above works for degree=1
, but when I use higher order Lagrange polynomials, I get the error
*** -------------------------------------------------------------------------
*** Error: Unable to evaluate function at point.
*** Reason: No matching cell found.
*** Where: This error was encountered inside Function.cpp.
*** Process: unknown
***
*** DOLFIN version: 1.4.0
*** Git changeset:
*** -------------------------------------------------------------------------
Trying to use project
instead of interpolate
does not work either. What am I missing here?
Thanks in advance