I would like to solve a problem in the MixedFunctionSpace([W, P])
, and instead of allocating separate functions in W
and P
, I start off with up
in WP
(see also this question about stitching together functions).
At one point, I need to solve a nonlinear equation for u
only, though (the tentative velocity update in Chorin's method for Navier-Stokes). The corresponding call
solver.solve(step_problem, ui.vector())
won't work since .vector()
isn't valid for subfunctions. Also, I cannot allocate a new function ui
from W
and fill in the values back into up
(see bug #210).
What is a better way to deal with this than
from dolfin import *
mesh = UnitSquareMesh(20, 20)
W = VectorFunctionSpace(mesh, 'CG', 2)
P = FunctionSpace(mesh, 'CG', 1)
WP = MixedFunctionSpace([W, P])
up = Function(WP)
u, p = up.split()
f = Expression(('sin(x[0])', 'cos(x[1])'))
v = TestFunction(W)
F = dot(u, v) * dx - dot(f, v) * dx
solve(F == 0, u)
which yields
*** Error: Unable to access vector of degrees of freedom.
*** Reason: Cannot access a non-const vector from a subfunction.
*** Where: This error was encountered inside Function.cpp.