Here is a minimal example of how to extract the the pressure from a boundary surface:
from dolfin import *
mesh = UnitSquareMesh(10, 10)
class Boundary(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0) and on_boundary
el1 = VectorElement("Lagrange", mesh.ufl_cell(), 2)
el2 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, MixedElement([el1, el2]))
w = Function(W)
# Assign some data to mixed space
p = Function(W.sub(1).collapse())
p.interpolate(Expression("2*x[1]", degree=1))
fa = FunctionAssigner(W.sub(1), p.function_space())
fa.assign(w.sub(1), p)
# Mark all vertices on boundary with 1
vf = MeshFunction("size_t", mesh, 0)
Boundary().mark(vf, 1)
# Get sub-component
w_1 = w.sub(1, deepcopy=True)
v_to_d = vertex_to_dof_map(w_1.function_space())
boundary_vertices = vf.where_equal(1)
vertex_coords = mesh.coordinates()[boundary_vertices]
for (coord, entity) in zip(vertex_coords, boundary_vertices):
print(coord, w_1.vector().get_local()[v_to_d[entity]])
yielding:
[ 0. 0.] 0.0
[ 0. 0.1] 0.2
[ 0. 0.2] 0.4
[ 0. 0.3] 0.6
[ 0. 0.4] 0.8
[ 0. 0.5] 1.0
[ 0. 0.6] 1.2
[ 0. 0.7] 1.4
[ 0. 0.8] 1.6
[ 0. 0.9] 1.8
[ 0. 1.] 2.0
which you can append to an array an plot with matplotlib.