On 31/05/16 15:06, Gregory, Alastair C A wrote:
Hi Firedrakers,
I have two functions, v(x,y) and h(x,y). I find a quantity u(x,y)=v(x,y)/h(x,y) to solve a PDE. Now, I'm struggling with using u(x,y) when h(x,y) is equal to 0 at some cells. I get DIVERGED_NAN errors as I'm trying to divide by 0.
Now what I have done is to build a kernel that allows me to set the cells that will be dividing by 0, to 0, and otherwise proceed as normal on the cells that won't be dividing by 0. This arises since v is momentum and h is depth, and thus u is velocity. With 0 depth, I would like 0 velocity. However, sometimes I divide by a restriction to a function and thus can't use a kernel.
Is it true that when h is zero, v will *already* be zero? Or is it that you want to require that when h is zero v/h is also zero? If the former, you could just try regularising h slightly. h = h + epsilon Alternately you can do this: u = conditional(h == 0, Zero(v.ufl_shape), v/h) This selects an (appropriately-shaped) zero when h is identically zero and v/h otherwise. You can then use u in a form as normal. Cheers, Lawrence