How to convert a tuple of function space to a vector function space?

#1

Hello,

I have trouble converting a tuple of functions to a vector function. I have produced a tuple of functions from a matrix with 3 columns. For each column, I create a function correspondingly. Now I am having trouble converting the tuple of functions to a vector function space. How can I do it? Thank you very much!

#2

Hi, the way I understand your question the following should help

from dolfin import *
import numpy as np


mesh = UnitSquareMesh(3, 3)
# Scalar and vector valued spaces
V = FunctionSpace(mesh, 'CG', 2)
W = VectorFunctionSpace(mesh, 'CG', 2)

# The vector valued function to fill
w = Function(W)

# Scalar functions from data
vs = [Function(V) for _ in range(W.num_sub_spaces())]
for v in vs:
    v.vector().set_local(np.random.rand(v.vector().local_size()))

assign(w, vs)

# Success?
v = as_vector(vs)
L = inner(w - v, w - v)*dx
print sqrt(abs(assemble(L)))