Element wise GridFunction or CoefficientFunction

Hallo again,

currently I’d like to test a PMP method for an optimal control problem.
Therefore I need to (element wise) evaluate an expression of the form
\int_T \, n^2\, u \,p \, dx
where u is the state equation, p the adjoint and n the (local constant) control.
Afterwards, n is then supposed to be updated on each element, depending on the result.
I know I can do the evaluation with the “element_wise=True” flag, however, how can I set new values for n element wise?
So far n is a CoefficientFunction or L2 function.

Once again, thanks for any help :slight_smile:

Philipp

Hi,
create a GridFunction on a L2(order=0) space and set the vector of the gf.
Best

Oh, totally forgot about that.
Thanks a lot Christopher! :slight_smile: