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

Stitching functions together to create a function belonging to a mixed space....(followup)

0 votes

I found this segment of code on the bugreports page and it works.

from dolfin import *

# Create mesh and define function spaces
mesh = UnitSquareMesh(256, 256)
V = VectorFunctionSpace(mesh, "CG", 2)
P = FunctionSpace(mesh, "CG", 1)
Z = MixedFunctionSpace([V, P])

    # Define function
    v0 = Expression(("sin(2*pi*x[0])*sin(2*pi*x[1])", "cos(2*pi*x[0])*cos(2*pi*x[1])"))
    q0 = Expression("cos(x[0])")

    z = Function(Z)

    u0 = Function(V)
    u0.interpolate(v0)
    p0 = Function(P)
    p0.interpolate(q0)

    assign(z, [u0, p0])

So is this something different from what was asked in the original question ? In the example, we do seem to be stitching functions together to create a function belonging to a mixed space.. Am I missing something her ?

asked Jun 16, 2014 by shriram FEniCS User (1,540 points)
edited Jun 16, 2014 by shriram

1 Answer

+1 vote
 
Best answer

In this example you aren't really 'stitching' together u0 and p0 to form z in the sense that z is not being created (via reference or otherwise) when you use the 'assign' function.

Rather, the 'z' function already exists and is a mixed function over the space (two scalar fields). The assign command is just copying the values of u0 and p0 into that z function. If, after the assign statement, you change u0, the value in z will not change because u0 and the first subspace of z are completely different object which were merely set equal. z.sub(0) doesn't actually link to u0 in any way.

Now if you did something like (untested):

 z = Function(Z)
u0, p0 = split(Z)

then u0 is the first subspace of z, so changing it will change z, and vise versa. (note how you don't have to define u0 as a function beforehand).
Note: If you want to then initialize u0, you will need to use the assign command again with something like (untested):

assign(z.sub(0), interpolate(v0,V))

Does that help?

answered Jul 1, 2014 by mwelland FEniCS User (8,410 points)
selected Jul 3, 2014 by shriram
...