The one I suggested should work nicely if your lookup tables only have a few entries, as in your MWE (although you might want to add exit() after the print call, now that I look at it again). @freya’s solution would be more efficient for assembly, although you’d have to linearize manually for a nonlinear residual like the one shown in your MWE. You could also try to extend my idea to implement a binary search recursively in UFL, although that may be more trouble than it’s worth.
Hi @kamensky! Thanks for your help.
Using @freya’s solution, in case of a nonlinear problem I think I’d have to reassemble the function at each time step and at each iteration, which is maybe a bit too much a trouble. I looked at your solution but it may indeed be very slow for some datasets, plus I don’t know if it’d work on a nonlinear problem.
To be honest I was hoping for an easy implementation that I wasn’t aware of but apparently there isn’t one - yet. I can always work with polynomial fitting for now.