Cut off functions with UFL

Hello,

I’d like to implement some cut off for coefficients of a nonlinear problem.

With u = Function(U), and P=p(u) is a ufl based operation on u.
I’ve been trying to implement something of the sort:
if pointwise, P >= 2, then modify P so that at these specific points P=2.

Any idea how that could be achieved?
I don’t have a minimal example to offer because I don’t even know how to write the test cited above.
Thank you for your help y’all!

Consider using a conditional, as described in: How to implement function with condition? - #3 by dokken

1 Like

That’s what I had in mind but I did not know how to do it.
Thank you for your help.