Optimal control from discrete data

Hello,

I would like to know whether there is a straightforward way to define ufl expressions from interpolated data (e.g. using numpy.interp).

My goal is adapt the tutorial Optimal control in DOLFINx by replacing

- \nabla \cdot \nabla u = f

by

- \nabla \cdot \nabla u = g(f)

where g is a function of f, approximating somehow g_samples at f_samples.

For forward evaluation, g = numpy.interp(f.x.array, f_samples, g_samples) should do the trick.
But what about the sensitivity w.r.t f?

Thanks in advance for your time and advice.

I guess this would be best do to with a PointSource (Point sources in DOLFINx — scifem) or a set of point sources.

For the adjoint equation, you would have to add appropriate sources on the RHS corresponding to dJ/du if the point source enters J in this way.

Similarly for the sensitivity, point sources would have to be added.