Take a look at the responses in this thread:
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.