Assignment 6 (Flow modeling)

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 teh 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:

CSLAB01:>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.  
CSLAB01:> 

The first project will integrate all the assignments into a flow computation package so it is good to think about this while deciding the structure of your FD/FA code. You can display a FD and FA grid in the same way that you display an elevation grid (see figure below). You can do more elaborate visualisations, like draping the FA on top of the surface (elevation). This can be done with a nice extension your draw-grid() function. Think about it!

You do not need to submit your code. We will demo it in class.