# Distribute water over uneven ground

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?

• Presumably what you're trying to say is that when water falls at a certain point, it moves to the nearest local minimum, filling it in and thereby making it flat. This means the outcome depends on the distribution of the rainfall, not just how much of it there is. Are you trying to think about all possible solutions, or do you have this information in mind too?
– Ian
Jan 22, 2017 at 12:27
• @Ian I'm interested in the less realistic case where water falls to the global minimum, and then we can neglect the distribution of rainfall. Jan 22, 2017 at 12:30
• Is your last explanation similar to "start pouring the water near the global minimum and watch what happens" ? Jan 22, 2017 at 12:57
• @Evgeny in the easier problem, the global minimum is equivalent to the local minimum. So yes, in that particular case I can do that. If I pour water "near" the global minimum in the general case, I get into the discussion from John's answer, and I don't want to. Therefore in general, I dont think about the actual dynamic process of how the water moves, but just the stationary distribution in the end under which there is a unique water stand over $X$. Jan 22, 2017 at 13:06
• Well, this dynamical process is still of help here :) by the way, do you really mean that $w(x) + f(x) = h$ everywhere? Because it is somewhat unnatural for a water. Jan 22, 2017 at 13:59

The problem has no unique solution. Consider (in 2D ) a shape like this:

\                 /
\  /\       /\  /
\/  \     /  \/
.B  \   /    .c
\ /
. A


As water pours in over point $A$, the middle trough fills up. But when you reach the "lip" of that trough, and add a little more water, one solution is that it pours over into $B$; another is that it pours over into $C$, and a third is that it pours equally into both. So there are in fact infinitely many solutions that satisfy your initial conditions.

To make a similar example in 3-space, extrude and cap the ends.

• As I have clarified in the question, my water immediately goes for global minima. Or in other words, I'm interested in the particular solution where the water stand is unique over $X$. Jan 22, 2017 at 12:52
• Oh I might see, you were saying that I can't state (1) as a differential equation? I have reformulated. Jan 22, 2017 at 13:13
• I think that at first try you might neglect this case, because it is not typical. It is not typical in the same sense that when you randomly pick coefficients of polynomial equation its roots almost always would be simple. What distinguishes this case from the typical one is that two maxima have the same height which is an additional condition. Jan 22, 2017 at 13:26
• Ca n you characterize the case in which the solution is unique? And is there any hope that solutions for cases near the nonunique cases are in any reasonable sense stable? I'm not sure what you mean by 'water stand'; if it's the max height, then it is unique in the case I described; only the distribution is variable. Jan 22, 2017 at 13:45
• I think that since the problem happens only when you have some maxima with the same height $f(x)$ ("bad property"), I can characterize this. Since having critical points at different heights is already a generic property, we won't have problem here. You can always add something very small to a function with "bad property" such it won't have this property. P.S. I feel like I'm borrowing something from catastrophe theory :) Jan 22, 2017 at 14:13

Here's one way of solving this numerically I came up with that involves solving for $h$ as a first step:

$$h - \int_X f(x) \mathbb{1}_{f(x) \leq h}dx = e$$

There appears no closed form solution for $h$ in the general case, but any root-finding algorithm should be able to solve this quickly. Obtaining $w(x)$ is then trivial:

$$w(x) = h - f(x)$$

• Well, if you are looking for uniform level of water, this is a reasonable solution. Jan 22, 2017 at 15:38
• Look at my example. Imagine the pit labelled A has capacity 10. If you set the volume to be, say, 9, then your solution will put fluid in all of pits A, B, C (lots in A, a little in B and C). But that's not consistent with the idea of "filling at the min of $f$", which you added in earlier comments. (And this complaint works even if the levels of the boundaries between A and B and between A and C are slightly different rather than identical. If you're trying to solve something even slightly realistic, this seems like a bad approach. Jan 22, 2017 at 21:47
• For the root finding: you might want to compute the max $u$ of $f$ over $X$, and set $h_0 = u + (area(X) / h)$, Your true solution will then be between $0$ and $h_0$, and since the function on the left is increasing as a function of $h$, bisection will get you to an answer very fast. I still think -- see my previous comment -- that it's likely to not be a useful answer, but at least you'll get it quickly. :) Jan 22, 2017 at 21:50