Legacy FEniCS has two similar-looking but different ways to “split” Function
s in mixed spaces. See the following example for a way to get phi
as a Function
:
from dolfin import *
import matplotlib.pyplot as plt
#mesh = Mesh('../../res/mesh_generation/annulus_refined.xml')
mesh = UnitSquareMesh(8,8)
V = VectorElement("Lagrange", mesh.ufl_cell(), 2)
Q = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
W = FunctionSpace(mesh,MixedElement([V,Q,Q,Q,Q]))
#hdf5 = HDF5File(mesh.mpi_comm(), './state.h5', 'r')
qTilde = Function(W)
#hdf5.read(qTilde, 'var')
qTilde.assign(Constant((0,1,2,3,4,5)))
# Long-standing ambiguity in the Legacy FEniCS API:
#
# https://bitbucket.org/fenics-project/dolfin/issues/194/split-u-versus-usplit
#
# Difference between "split" as free function and method:
u,p,c,q,phi = split(qTilde)
print(type(phi))
_,_,_,_,phi_func = qTilde.split()
print(type(phi_func))
# Can evaluate `phi_func` at a spatial point:
from numpy import array
print(phi_func(array([0.3,0.3])))