Note that F is a variational formulation (symbolical) written in the UFL form language.
To replace a coefficient in a ufl-form, you need to use ufl.replace
. i.e.
from ufl import replace
F_ = replace(F, {y:y_new})
Note that this returns a ufl-form, a symbolical representation of F
. To get a numerical value, you need to assemble it:
F_assembled = assemble(F_)
This returns a dolfin.Vector
which you can take the norm of:
F_norm = F_assembled.norm("l2")
For your specific problem, this would end up as:
from ufl import replace
while assemble(replace(F, {y:y_new})).norm("l2") >1e-6:
# Add code
The same hold for this assignment, you need to use replace and assembly.
Please also note that you are constantly reassigning values in your loop.
You should use the assign
function :
y_new = Function(V)
y_new.assign(project(y_BC, V))
while ...:
if i!=0:
y_initial.assign(y_new)
y_new.vector()[:] = y_initial.vector()[:] - assemble(.....)[:]
Note that J
is not defined outside of W(y)
.