I'm trying to assemble a multilinear form (for no purpose other than understanding better what's happening). From the FEniCS book, I understand that a multilinear form of arity-2 should result in a rank 2 tensor after assembly. So I tried to assemble something trivial:
# (define v1 and v2)
A = assemble(v1 * v2 * dx)
I was not quite sure how assembly depends on v1
and v2
being test functions or trial functions (at this stage, there didn't seem to be any difference), so I opted for test functions.
However, none of the following definitions worked at all:
# First try
V = FunctionSpace(mesh, 'CG', 1)
(v1, v2) = (TestFunction(V), TestFunction(V))
A = assemble(v1 * v2 * dx) # "Invalid expression"
# Second try
V = FunctionSpace(mesh, 'CG', 1)
(v1, v2) = TestFunction(V*V)
A = assemble(v1 * v2 * dx) # "Unable to extract all indices."
# Third try
V = VectorFunctionSpace(mesh, 'CG', 1)
v = TestFunction(V)
(v1, v2) = (v[0], v[1])
A = assemble(v1 * v2 * dx) # "Unable to extract all indices."
Could someone explain to me what's wrong with each of these, and how to do it right?