The SPH particles represent the fluid flow. Particles have information about
the position, density, and velocity. In every simulation step, they are
changed by pressure force, viscosity force, and external force (i.e., gravity).

This program reads a text from standard input, and uses it as an initial
configuration of the particles. The character # represents “wall particle” (a
particle with fixed position), and any other non-space characters represent
free particles.

The compilation options -DG=1 -DP=4 -DV=8 represent, respectively, the factor
of gravity, pressure, and viscosity. By changing their values, you can see
different fluid behavior.

Portability

The program requires a C99 compiler; it uses complex types and one-line
comments. It also uses usleep, which may require -D_BSD_SOURCE or somewhat
to build with no warning. Under these conditions, it should be portable.
At least, recent compilers with -std=c99 -Wall -W -Wextra -pedantic says
nothing.

I expect it to work in any Unix-like environment. VTxxx/ANSI sequences are
used to clear screen and move cursor to home.

I’ve tested with gcc-4.6.3 and clang-3.0 on Linux (Ubuntu 12.04)
and gcc-4.5.3 and clang-3.1 on Cygwin. On Cygwin, gcc and clang complain about
a usage of I (complex’s imaginary unit), but I bet this is cygwin’s issue;
it is surely a C99 feature.

Obfuscation w/ Spoiler

First of all, the source code itself serves as an initial configuration.
Preprocessing directives (such as #include)’s # serve as walls.

This program uses double complex to represent any 2D vector. But, note that
x-axis and y-axis is swapped (real axis = y-axis, imaginary axis = x-axis).
The purpose of swapping is not only obfuscation, but also short coding: for
example, to add gravity to total force, force += G suffices, rather than
force += G*I.
(Incidentally, you can exert horizontal gravity by using, such as, -DG=I)

Every five entries of double complex a[] contain information of one particle:
position, wall-flag, density, force, and velocity, in turn.

You can use G, P, and V as a guide to find the calculation code of
gravity, pressure, and viscosity forces.

Though some assignments may look meaningless, it is actually meaningful; it
extracts “integer part of real part” from a complex value by assigning (and
casting) it to an integer-type variable.

Notes about Additional Files

“logo.txt” is a source of the logo in this remark file.

“column.txt” is a water column collapse, which is a popular demo of SPH.