Index notation on trial function?

Hi there,

I know how to use ufl index notation, but I can’t make it work on trial/test functions.

Any idea on how to make the following mwe run?

from dolfin import *

class Right(SubDomain):
    def inside(self,x, on_boundary):
        return x[0] > 1-DOLFIN_EPS and on_boundary

class Left(SubDomain):
    def inside(self,x, on_boundary):
        return x[0] < DOLFIN_EPS and on_boundary

mesh = UnitSquareMesh(10,10)
V1   = FunctionSpace(mesh, 'CG', 2)
V2   = TensorFunctionSpace(mesh, 'CG', 2, (2,2))

u  = TrialFunction(V1)
v  = TestFunction(V1)

J  = Expression((('x[0]', '0'), ('0', 'x[1]')), degree = 2)
J  = interpolate(J, V2)

g1 = Constant(0)
g2 = Constant(1)
g3 = Constant(2)

a = inner(grad(J)*grad(u), grad(v))*dx
L = g1*v*dx

left = Left()
right = Right()

bc1 = DirichletBC(V1, g1, left)
bc2 = DirichletBC(V1, g2, right)
bc = [bc1, bc2]

u = Function(V1)

solve(a == L, u, bc)

Please state what you are trying to achieve. To me this does not really make sense, as you are trying to multiply the gradient of a tensor (3rd order tensor) with a vector. What shape should this become?

I want to mutiply a rank 3 tensor with a vector indeed.
But I just noticed that the mwe that I postet doesn’t make sense.
I can make a correct mwe, but what I basically have is a variational formulation, where my trial function - which is a vector - is mutiplied with a rank 3 tensor like this:

grad_J[i,j,k] * u[j]

The problem is that using ufl index notation doesn’t seem to be applicable to trialfunctions.

Please adjust your example to reflect what would actually like to do, and add the error message obtain with your indices approach.

As you have not adjust your example, this is my suggestion for you:

from ufl import indices
i, j, k = indices(3)
gradj = grad(J)[i,j,k]
gradu = grad(u)[j]
gJu = gradj*gradu

However, I can’t help you any further as your example does not make sense to me.

It seems that dot(grad(J), u) does the job, even for a rank 3 mutiplication with a vector.
But thank you anyways.

Based on what you have written above, I don’t think that dot(grad(J), grad(u)) will be gradJ[i,j,k]*gradu[j] but rather gradJ[i,j,k]*gradu[k]