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

stitch together functions in a product space

+1 vote

I have three functions w, p, q from function spaces W, P, Q, all of different type and order.

How can I stitch them together to a function wpq from MixedFunctionSpace([W, P, Q])?

asked Jan 23, 2014 by nschloe FEniCS User (7,120 points)

2 Answers

+2 votes
 
Best answer

You can't stitch them together. You need to start from a mixed space and extract the subspaces.

answered Jan 24, 2014 by Garth N. Wells FEniCS Expert (35,930 points)
selected Jan 27, 2014 by nschloe
Stitching functions together to create a function belonging to a mixed space....(followup)
–1 vote

This may have been indirectly answered by Mikael previously …

I haven't tried this, but what he had suggested in the link above was something like this:

M = MixedFunctionSpace([V,Q,L]) 
u_m = Function(M)
u_m0 = project(some_function, V) # V is M.sub(0)
assign(u_m.sub(0), u_m0)
answered Jan 24, 2014 by timm FEniCS User (2,100 points)

This is not working correctly. MWE:

from dolfin import *

mesh = UnitSquareMesh(1, 1)
#mesh = UnitSquareMesh(10, 10)
W = VectorFunctionSpace(mesh, 'CG', 1)
P = FunctionSpace(mesh, 'CG', 1)
WP = MixedFunctionSpace([W, P])

WP0 = WP.sub(0).collapse()
WP1 = WP.sub(1).collapse()

u = Function(WP0)
p = Function(WP1)

p.assign(project(Expression('sin(6 * x[0])'), WP1))

plot(p, title='in')

up = Function(WP)
assign(up.sub(0), u)
assign(up.sub(1), p)

u, p = up.split()
plot(p, title='out')
interactive()

See https://bitbucket.org/fenics-project/dolfin/issue/210/subfunction-assignment-with.

...