Objective Function

Hello everyone. I have one question. I am trying to write the following objective function in Fenics and I am getting TypeError: unsupported operand type(s) for /: 'Form' and 'float' . Is it possible to have an objective function like this in Fenics? Any help is much appreciated. I guess I should mention that force f is given and both u and v are solutions of PDEs.

If the PDEs for u and v have been solved already, and you’re just computing J(u,v) as a post-processing step, then you could do something like

J = 1.0 + assemble(f*v*ds)/assemble(f*v*ds)

I guess my question was: I want to write it as the UFL form so I will be able to take derivative of the functioanal with respect to u . By writing like this J = 1. + J1/J2 J is just a float and i will not be able to take derivative of J with respect to u

You need to use software such as dolfin-adjoint if you want to find the sensitivity of J wrt. u.