Software for dunefield simulator

Back to main page


Source code:

Current: For Visual Studio Express 2015 for Desktop:
Previous: For Visual Studio Express 2010 C#:

(Download and unzip the source into a folder, then, with the appropriate compiler on your system, click the 'sln' file.)

Executable:Click to run (uses Microsoft's ClickOnce installer, circa 2010)

If there are problems, please let me know (bottom of this page). Thank you to Marissa Dattler for prompting fixes for compatibility with the 2015 compiler.

Using the simulator

Fig 1. User interface of the simulator

Select a model from the drop-down list 'Model'. Select a 'Neighbourhood' method. Set the desired dunefield dimensions, which must be powers of 2. A width of 1 cell is acceptable. The larger the dunefield, the slower it executes. Select an initialization method (usually 'random' or 'uniform') and a sand height (usually 1 to 3 will generate barchans, 10 or more will generate transverse ridges). Important: After selecting or changing parameters, press 'Initialize' to make them effective. Then press 'Run' (or Tick). The 'Run' button will change to 'Stop' when the simulator is running.

Frames for a video can be recorded to disk using the controls at the bottom of the simulator window. Using QuickTime Pro is one way to make frames into a video.

Scale for the dunefield and for the cross-sectional profile can be controlled by entering values in the appropriate scale control box. 'Auto' causes the scale to automatically bracket whatever values are present at the next refresh.

The cross-sectional profile is taken from the dunefield at the position of the grey triangle left of the field; drag it to obtain a profile at a different location. Shading indicates positions within a shadow.

The dunefield normally displays elevation, but click on items in the 'Show' box to see other attributes.

Click on the dunefield to bring up a 'magnified view' of the dunefield (essentially a debug tool). Click or click-drag elsewhere in the dunefield to move the focus of the magnifier (if you click-drag, it will update as the mouse moves). Figure 2 shows a magnified view of a sand pile after a few ticks. Each cell contains the cell coordinates [width, length], the sand elevation, the shadow height, and the hop distance. If the cell is in a 'wind shadow', a grey circle with white border appears in the lower-right corner.

Fig 2. Example of the magnifier window; sand pile with Von Neumann neighbourhood

The 'sand pile/pit' model will generate a sand pile at the center of the dunefield if the initial sand height is zero, or a pit at the center if the initial sand height is greater than zero. The pile/pit is created by adding/subtracting one grain per tick from the center cell, and by moving one tick at a time, using the magnifier to watch, one can see (and check) the effect of avalanching, neighbourhood, and shadow calculations.

The 'Recycle' checkbox controls whether sand that blows or avalanches off the right end of the dunefield ought to be wrapped to the left side ('recycled'), ie., whether the field has periodic streamwise boundaries or not.

Code structure

The source file is Visual C#, which is like Java and can be compiled using the free compiler from Microsoft (google for "visual C# express"). The source code works with the Visual C# 2010 or 2015 Express editions (it was developed with the 2008 edition and then updated to work with 2010, and again updated to work with Visual Studio Express 2015).

The code isn't extensively commented; it wasn't developed with the idea of public use. If there is value to anyone in improving it, or adding features, please let me know (via the link at the bottom of this page), I may be able to help.

The simulator can run many models, selected from a drop-down list, such as "Werner (1995)", "Momiji (2000)", etc. Each model can be run with one of several methods of finding steep slopes than need to be avalanched, such as "Moore, deterministic" or "Von Neumann, stochastic".

The models are implemented by the class 'Model.cs', which has virtual methods that can be overridden to implement various models and variants. For example, 'Werner1995.cs' provides overrides that implement Werner (1995).

As is stardard for C# Windows Forms applications, the class Form1.cs contains the top-level controls. Within Form1.cs, the method 'init' sets up the simulator for a simulation according to settings of the user interface. A FindSlope object is created that implements the nearest-neighbour algorithm desired by the user, and then that is passed to the constructor for a Model object, which will be the simulator for that particular user request. invokes the model's Tick method to have it run its model for one tick, and the user interface is updated after a user-specified number of ticks.

The dunefield array is owned by the model for efficiency, which slightly inconveniences some of the user interface display code.

The core of the simulator is Model.cs and its overrides (eg., werner1995.cs), and FindSlope.cs. The rest are user interface and controls. So adding a new model is easy -- just copy an existing model class (eg., Werner1995.cs), rename it, make changes, and add to the 'case' statements in Form1.Form1_Load and Form1.init (a bit clumsy; using attributes and reflection would have been classier). Experimenting with existing models is even easier -- just edit the model's code.

The Visual C# Express compiler is large but easy to download and install. C# is easy to read and modify if you know C or Java.

Comments or questions

You can reach me at: Comments

Jim Elder
2009 Nov, updated in 2011, 2015

Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 Canada License.