 # Is a product of grads a tensor in Fenics

Hi all,
I’m working with an equation that has a term like this

\dot u_i + ... = \nabla_j(\nabla_i\phi\nabla_j\phi)

where u_i is the function I want to solve for, hich is a vector, and \phi is a scalar function.

My question, is how does Fenics interpret the product of two grads? If the term on the right hand side would translate, for a test function w_i, as:

\nabla_i\phi\nabla_j\phi \nabla_j w_i

can I write that in Fenics as

inner(grad(\phi)*grad(\phi) , grad(w))*dx


or like

inner( outer(grad(\phi) , grad(\phi)) , grad(w) )*dx


Or are those two things the same for Fenics?

Thank you!

By simply trying such a code in dolfin, you obtain an error message:

from dolfin import *
mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, "CG", 1)
phi = Function(V)
W = VectorFunctionSpace(mesh, "CG", 1)
w = Function(W)
f = inner( outer(grad(phi) , grad(phi)) , grad(w) )*dx
f2 =inner(grad(phi)*grad(phi) , grad(w))*dx

Invalid ranks 1 and 1 in product.
Traceback (most recent call last):
File "outer.py", line 10, in <module>
f =inner(grad(phi)*grad(phi) , grad(w))*dx
File "/usr/local/lib/python3.6/dist-packages/ufl/exproperators.py", line 182, in _mul
return _mult(self, o)
File "/usr/local/lib/python3.6/dist-packages/ufl/exproperators.py", line 156, in _mult
error("Invalid ranks {0} and {1} in product.".format(r1, r2))
File "/usr/local/lib/python3.6/dist-packages/ufl/log.py", line 158, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Invalid ranks 1 and 1 in product.


thus you need to use outer.