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

Plot a function that exists only on the boundary

0 votes

I have an Expression. I generate this expression by sub-classing. I'd like to plot it's inner product with the unit normal. This value only makes sense on the boundary. How do I plot it?
Here's a minimal example.

from dolfin import *

mesh_obj  = UnitSquareMesh( 8, 8 )
normal = FacetNormal( mesh_obj )

V = FunctionSpace ( mesh_obj, "CG", 1 )
u = TrialFunction ( V )
v = TestFunction ( V )
f = Constant( 2.0 )

# Define a vector valued Expression.
# The expression I'm using is more complicated.
beta = Expression( ('x[0]', 'x[1]') )

# This is the linear form I want to evaluate. In order
# to test it, i'd like to visualize the boundary function
# in the last term.
a = inner(grad(u), grad(v))*dx + u*v*dx + inner( beta, normal )*u*v*ds
L = f*v*dx

# You guys know better than me what this does.
A = assemble(a)
b = assemble(L)

#  Solve the linear system for u.
sol = Function( V )
solve(A, sol.vector(), b, 'lu')

# Plot the solution.
plot ( sol, interactive = True ) 

So, how do I plot inner(beta,normal)? This arises from using Robin boundary condition, in case someone was wondering.

asked Dec 31, 2015 by Yair Daon FEniCS User (1,350 points)

Maybe this is related to http://fenicsproject.org/qa/8590/plot-facetnormal. The normals can't be plotted in a trivial way, hence I also expect that the inner product with the normal can't be.

...