## Modeling a Watershed with Arrays

*This is the second installment of a four-part series. The other three parts can be accessed by clicking on the links below.
Methods for Using Arrays Effectively*

Modeling Customers Switching Between Brands

Modeling Customers Switching Between Brands – The General Case

Modeling Customers Switching Between Brands

Modeling Customers Switching Between Brands – The General Case

*This is the second installment of a multipart series. The first part can be found by clicking here. **Part 3 is available here.*

In the first post of this series, I showed how to conditionally pull information from an array. In this post, I will extend this concept to show how to route information through an arrayed model. This is especially useful in spatial modeling applications.

**Routing Water Through a Watershed**

A common ecology application is the modeling of a watershed. Part of such a model will necessarily involve a network of stream or river segments – called *reaches* – which feed each other. It is desirable to implement this in a way that makes it easy to modify the reach network. Using an explicit stock-flow network makes this very difficult. However, it is relatively straightforward to use arrays of stocks and flows to build an easily configurable network.

Imagine a small watershed broken down into reaches as shown below:

For our purposes, a new reach will need to be created at every junction point. Therefore, in this example and from a topological point-of-view, it is not strictly necessary to treat reach 4 separately from reach 2 nor reach 5 separately from reach 3, but reaches 2 and 3 must be separate from reach 1. There are, of course, other reasons to separate reach 4 from 2 and reach 5 from 3, for example, slope, channel width, length, etc.

Every reach flows into exactly one other reach at its head, but many reaches can flow into the head of the same reach. This requires a many-to-one representation of the reach network. This is accomplished quite easily with a routing map which, for each reach, contains the number of the reach that this reach flows into. We also need someway to signify the outlet. Since reach numbers start at one, we can use zero to signify the outlet. Using these rules, the above network is completely represented in the following routing map:

Reach | Flows into |

1 | 0 |

2 | 1 |

3 | 1 |

4 | 2 |

5 | 3 |

The nice thing about this representation is that it fits nicely into a one-dimensional array where the array index is the reach number and the reach it flows into is the value stored in that array element.

The model itself uses one stock to represent each reach. * *That stock has one inflow for water entering the reach and one outflow for water leaving the reach: *(Download the zipped STELLA model here) *