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

Access to sub-functions without deepcopy

0 votes

See the following example:

from dolfin import *

mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, 'CG', 1)
W = MixedFunctionSpace([V, V])
w = Function(W)
v1, v2 = w.split(deepcopy=True)
print v1.vector().array()

I would like to avoid the deepcopy, since this occurs many times in my program. However, just setting deepcopy=False, this gives:

*** -------------------------------------------------------------------------
*** 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.
*** Process: unknown
*** DOLFIN version: 1.4.0
*** Git changeset:
*** -------------------------------------------------------------------------

I encountered some similar questions here, eg. some involving FunctionAssigner, but it seems to use deepcopies also. Is there any method of getting the components of v1 and v2 here without copying the data?

asked Jul 4, 2016 by maartent FEniCS User (3,910 points)
...