This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Constructing trace operator (matrix that restricts function to boundary)

+2 votes

I'm trying to construct a discretization of the trace operator that observes functions along a boundary. That is, suppose $\Gamma$ is some subset of the boundary of $\Omega$ - I want to assemble the wide matrix $B$ such that,
$$\vec{v}^TB\vec{u} = \int_\Gamma v(x) u(x) ds,$$
where $u$ lives in a function space with domain $\Omega$, but $v$ lives in a space with domain $\Gamma$. It is not sufficient to simply compute the trace for a given function - I actually need the matrix.

Is this possible in Fenics?

I tried the following, which is clearly wrong but hopefully illustrates what I'm trying to do:

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, 'Lagrange', 1)
u = TrialFunction(V)

boundary_mesh = BoundaryMesh(mesh,"exterior")
V_boundary = FunctionSpace(boundary_mesh, 'Lagrange', 1)

v_b = TestFunction(V_boundary)

boundary_observation_operator = u*v_b*ds
B = assemble(boundary_test)

This yielded the error:

An Integral without a Domain is now illegal.
ERROR:UFL:An Integral without a Domain is now illegal.
asked Mar 27, 2015 by Nick Alger FEniCS User (1,490 points)
edited Mar 28, 2015 by Nick Alger

This is of interest to me also. But it does not seem to be possible to do this since u and v_b are defined on different meshes. If the space V_boundary can be obtained by restriction of the space V onto the boundary, then you can do some workarounds. For an example see https://github.com/cpraveen/fenics/blob/master/2d/laplace_lagrange_multiplier/demo.py where I use Lagrange multipliers on the boundary to apply DirichletBC. I would be interested to know if there is a better way to do this.

...