[Bowdoin Computer Science]

Flow direction and accumulation on grids

In this assignment you will write functions for flow modeling on a grid terrain. The simplest (and most used) approach to modeling flow is to compute the FD (flow direction) and FA (flow accumulation) of the terrain. FD models where the water flows, and FA models how much water flows through that point in the terrain. Both of these are grids of the same size as the original grid. In other words, each cell in the terrain will have a corresponding FD and FA cells in the FD grid, and the FA grid. The assumption you will use is that water flows from each cell in the grid to the stepeest downslope neighbor.

Thus, you will write two functions: one to compute the FD grid, given the elevation grid. And one to compute the FA grid given the FD grid.

To compute FD for each cell in the terrain, you will have to find the stepeest downslope neighbor of that cell; if there is more than one stepeest downslope neighbor pick one (at random). If all neighbors of a cell have same height or are upslope assign FD=0. For each of the other neighbors (8 in total), use a different code (you can choose 1 through 8, for e.g.).

To compute the FA grid assume that initially every cell in the terrain has 1 unit of water, and that every cell distributes its water (initial, as well as incoming), to the neighbor pointed to by its flow direction. This is the hardest part of this assignment, and the first time so far that you have to think how you will compute FA (i.e. the algorithm). Not only that, but I would like you to try and analyze the worst case running time of your algorithm (as a function of the input grid size).

You can structure your program as you like. You can write two different programs, or you can write one program that can run both functions. Ideally the program will wait for your command and execute it:

dover:>flow 
flow>flowdir in=set1.asc out=set1-dir.asc 
Computing FD for set1.asc....done 
flow>flowaccu in=set1-dir.asc out=set1-accu.asc 
Computing FA for set1-dir.asc....done 
flow>flowdir in=kaweah.asc out=kaweah-dir.asc 
Computing FD for kaweah.asc....done
flow>exit 
OK, bye.  
dover:>