This is a simple implementation of a lattice gas automation simulation. The output is written to png.
This was written for two reasons. 1. I have wanted to implement a lattice gas for some time. 2. This serves as an exhibit of my c coding style.
D2Q6, D2Q7, D2Q8 and D2Q9 (2D with 9 states) elements are implemented. Which element is in use is changed by parsing in a different command line argument.
- src folder hold all the source.
- src/main.c is the entry point.
- obj/ houses all the object files. It needs to exist.
- test/ houses the test executables. It needs to exist for testing.
- pics/ houses the output pictures
- gifs/ houses the output gifs. Made with the ImageMagick's convert utility.
- Makefile is the file that defines the build commands.
- LatticeGas is the executable that will be built.
- gcc is used to build.
- libpng is used and expects it in the normal build paths.
- make is used as the build system.
- ImageMagick is used to make the gifs.
Testing is very rudimentary and does not use any external libraries. Each src/test_*.c file is build as an executable in test/ and then executed. If it returnes a non-zero exit code, the test is assumed to have failed. A shortcomming is that the next test will still be run.
Done with make test
The default make command is the LatticeGas executable. This is the main program. When executed it will reun a lattice gas simulation up to the given number of iterations and print the output as png files in the pics folder.
The structure that is simulated is defined in the sec/main.c. In particular each cell is defined as either Mirror, Fixed or _Flow. The type of a cell is queried through the getCellType function.
Mirror cells simply reflect any input back the way it came. These should be used for no flow boundaries. (They violate the concervation of momentum).
Fixed cells always have the same value in all iterations. These should be used for inlets and outlets. (They violate the concervation of momentum and mass.)
The value of fixed cells is determined by the value returned getFixedValue function.
Flow cells are normal cells that propogate and collide bits in them conserving both mass (number of bits) and momentum.
There is no damping. There is no damping of the momentum, so the wake of an object becomes infinitly wide, given enough time. Obviously this is non-physical. Damping should be introduced. However this si a bit tricky as all bits are binary values and so introducing damping while maintaining the binary bits is a difficult problem. Any ideas would be welcome.