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

Manually construct mixed function

+3 votes

Let's suppose I have a MixedFunctionSpace W consisting of two subspaces V. How can I construct a function in W from two functions in V, i.e.

#!/usr/bin/env python

from dolfin import *

mesh = IntervalMesh(100, 0.0, 1.0)


V = FunctionSpace(mesh, "CG", 1)
W = V * V

f1 = interpolate(Expression("sin(x[0])"), V)
f2 = interpolate(Expression("cos(x[0])"), V)

u = Function(W, (f1,f2)) # does not work

I know that in this particular case simply interpolating Expression(("sin(x[0])", "cos(x[0])"), W) would work, but my question is how I can do this with two general functions f1,f2. This is just the simplest example I came up with.

asked Oct 11, 2013 by cevito FEniCS User (5,550 points)

1 Answer

+4 votes
 
Best answer

Right now you cannot do this in a straight forward way. There is a reported issue about this at bitbucket. However if you are using the development version of DOLFIN you can interpolate two functions into a third one by:

u = interpolate(Expression(("f1", "f2"), f1=f1, f2=f2), W)
answered Oct 11, 2013 by johanhake FEniCS Expert (22,480 points)
selected Oct 11, 2013 by cevito
...