TypeError: unsupported operand type(s) for +: 'Form' and 'Function'

Hello,

I am using the fixed point method to find the minimum of the integral Pi = tr(F.T*F) *dx . However, when I want to do the iteration, I am getting this error: TypeError: unsupported operand type(s) for *: 'Form' and 'float'. I have attached my minimal code.
Thanks

from dolfin import *
from ufl import replace
mesh = UnitSquareMesh(4,4)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
du = TrialFunction(V)            
v  = TestFunction(V)            
u  = Function(V)
F = Identity(len(u)) + grad(u)
u0, u1 = Function(V), Function(V)
f = Expression(("0", "0"), degree=1)
u0 = project(f, V)
Pi = tr(F.T*F) *dx
dPi = derivative(Pi, u, v) 
dPi_val = replace(dPi,{u:u0})
deltax = 1.e-6
u1 = -dPi_val *deltax + u0

To answer my question for future reference, I think the issue is that dPi is the integral of weak form of the Euler-Lagrange equation of Pi, while u0 is a Function of space.
So, I need to use u0_int = dot(u0, v)*dx and then use u1 = -deltax * dPi_val + u0_int

2 Likes