We are in a (closed and connected) uneven area that lives in $X \subset\mathcal R$. Height of the ground is indicated by $f : X \to \mathcal R$, which is a twice continuously differentiable function.
It rains a fixed measure of water $e$. The area is nonabsorbant, such that the water does stay on the ground. This water is particularly persistent, in that it does not go for local minima, but intelligently finds the global minima. This implies that there is a unique water stand over $X$.
Denote the distribution of water over the space as $w : X \to \mathcal R$. I would like to compute $w(x)$, and the stand of the water (how high it has risen).
Define as the effective height of the ground
$$ \tilde f(x) = f(x) + w(x) $$
One of the requirements onto $w$ is that
$$ w(x) + f(x) = h \, \forall x : w(x) > 0 \tag 1$$
That is, effective surface is flat if there is water on it (and there is a unique effective surface heigh $h$ for any area with water on it). Secondly,
$$ \int_X w(x) dx = e \tag 2$$
Easier problem
Assume that $f$ was non-decreasing. Then, there exists $\bar x$ such that $w(x) > 0$ for $x < \bar x$ and $w(x) = 0$ for $x > \bar x$. We can find $\bar x$ using that
$$ \int_0^{\bar x} w(x) dx = e = f(\bar x) - \int_0^{\bar x} f(x)dx$$
Then, we can simply compute $w(x) = f(\bar x) - f(x)$.
I suppose there is some sort of transformation of $X$ into a new domain that is sorted by $f(x)$, and then I could apply this solution approach? Or how would I go on with solving this (original, not the easy) setup? Is there a better characterization/reformulation that allows me to find it quickly numerically?