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

Tensor index notation doesn't work with project - dot(Q,Q) vs. Q[i,j]*Q[j,k]

0 votes

Minimum example:

from dolfin import *
mesh = dolfin.UnitCubeMesh(10,10,10)
TS = TensorFunctionSpace(mesh, 'CG', 1)
Q = Function(TS)
project(dot(Q,Q), TS) # works
form = Q[i,j]*Q[j,k]
project(form, TS) # does not work, shape mismatch error

Is this a bug, or is it intentional (e.g. due to the way UFL is implemented)? In general, I would like to be able to use index notation with project since my forms are fairly complex. (I realize project is just a convenience function and I could reformulate this though.)

asked Jun 15, 2016 by FF FEniCS User (4,630 points)
edited Jun 15, 2016 by FF

1 Answer

+1 vote
 
Best answer

Hi, have you considered plugging in the definition of dot? I mean

project(as_tensor(Q[i, k]*Q[k, j], (i, j)), TS)
answered Jun 16, 2016 by MiroK FEniCS Expert (80,920 points)
selected Jun 17, 2016 by FF

Ah, I see now. I've only been using index notation in variational formulations prior to this (in which the end result is a scalar), which is why this wasn't necessary for me earlier. I had tried as_tensor already but didn't realize it needed the second argument to work. Thanks!

...