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

Ordering of u.split() for TensorFunctionSpace

+1 vote

The UFL manual describes how to access components of TensorFunctionSpace variables, like u[0,0] etc, but what is the ordering of (in 2D)

q,w,e,r = u.split()

?

asked Apr 10, 2017 by pf4d FEniCS User (2,970 points)

1 Answer

+1 vote

The ordering is:

q = u[0,0]; w = u[0,1]; e = u[1,0]; r = u[1,1];

New question: is there an easier way to determine this than

from fenics import *

mesh = UnitSquareMesh(1,1)
Q = FunctionSpace(mesh, 'CG', 1)
T = TensorFunctionSpace(mesh, 'CG', 1)
u = Function(T)
q,w,e,r = u.split()

ts = Function(Q)
ts.vector()[:] = 1.0
assq          = FunctionAssigner(q.function_space(), Q)
assq.assign(q, ts)
ts.vector()[:] = 2.0
assw          = FunctionAssigner(w.function_space(), Q)
assw.assign(w, ts)
ts.vector()[:] = 3.0
asse          = FunctionAssigner(e.function_space(), Q)
asse.assign(e, ts)
ts.vector()[:] = 4.0
assr          = FunctionAssigner(r.function_space(), Q)
assr.assign(r, ts)


project(u[0,0], Q).vector().max()
project(u[0,1], Q).vector().max()
project(u[1,0], Q).vector().max()
project(u[1,1], Q).vector().max()
answered Apr 10, 2017 by pf4d FEniCS User (2,970 points)

Hi, consider

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(10, 10)
V = TensorFunctionSpace(mesh, 'CG', 1)
v = TestFunction(V)

u = Function(V)
U = u.vector()
U.set_local(np.random.rand(U.local_size()))
U.apply('insert')

q, w, e, r = u.split()
u0 = as_matrix(((q, w),
                (e, r)))
assert id(w) == id(u0[0, 1]) 

b = assemble(inner(u0 - u, v)*dx)
print b.norm('linf')

# -----------------------------------

u0 = as_matrix(((q, e),
                (w, r)))

b = assemble(inner(u0 - u, v)*dx)
print b.norm('linf')

Oh yeah, that's nice!

...