That was *so* scripted

The flow solver was a project undertaken in C++ for my Final Year Project with my project partner at the University of Warwick. It was designed to simulate the flow of water over a randomly generated landscape, eroding it as it went. The resulting landscapes could then be viewed by opening the resulting output file in Matlab, which would then display them in 3D along with a representation of the water flow so far. These detailed outputs could then be used to investigate how a river network reaches a point in which the disipation of the energy in the water is optomised

The algorithm for creating a random landscape is as follows:

  1. Create an array and fill it with 0s
  2. Pick a point at random on the landscape
  3. Give the random point a height dependant on its proximity to the center of the island, and a random element.
  4. Flesh out all points around it into a small hillock using the normal distribution curve
  5. Repeat from 2 until a pre-defined number is reached
  6. Output the array as a matlab file

This is then followed by the flow solver (this is the simplest case):

  1. Sort the landscape into another array in height order
  2. Create a water array filled with the value 1
  3. Starting with the highest point on the sorted landscape array, move the water on that point to the lowest neighbouring point.
  4. Using the quantity of water, and the slope between sites, determine the erosion for that site and erode it.
  5. Find the next highest point with water and repeat from 3
  6. When all water is removed, repeat from 2 until a set value is reached.
  7. Output the array to a matlab file.

Anyway, my project partner and I got pretty respectable marks from it in the end, the report is probably in a cupboard in Warwick's Physics department somewhere, but the source is here for you to download if you want it.

Word of warning: We only ever ran this on Sparc 5 Solaris machines, so I have no idea how well it would compile on other platforms. Also it's not very well documented. You'll have to look at the comments in the source for a description. I would go and document it now, but... well have you ever gone back to an essay that you've already handed in to check for spelling mistakes? It's that sort of situation. I've already got my credit (and subsequent degree) for this, thanks :)

Download source files (46 KB)
downloaded 1548 times

Here's some pictures of the output:

Water flow early in the landscape's evolution The landscape about half-way through a simulation. Note the eroded areas where rivers are forming