Fluid Sim
- 4 Devlogs
- 17 Total hours
Python TUI dependency-less fluid simulation with ASCII visualisations!
Python TUI dependency-less fluid simulation with ASCII visualisations!
I made various minor edits, from error handling of edge cases (e.g. tiny terminal with huge rendering config) and optimised mouse input, then reformatted the project for pypi upload. And then I uploaded it!
I decided to call the project spume (plume was already taken by someone else :<), but I would love to hear some other nice names. Does anyone have any good ideas?
I worked on README.md and added CLI flag argparse, adding flags for sim dimensions, physics config such as maxiter and rtol, grid spacing, time speed, and viscosity, among others.
I continued working on it; just a single spawn point with no interesting interaction made it seem like a rather generic, almost repetitive sim. So I added WASD to move the spawn point around, then I added click-to-disrupt mechanics to introduce some more interesting, unpredictable, visually interesting patterns.
It took multiple iterations of various input-handling systems to settle on a final, simple but (mostly) reliable input system that should be fairly easy to extend in the future without using external libraries.
I had planned to submit this for macondo, so unfortunately I’m really behind on devlogs. So below is a recap of a few things.
I first read up on fluid simulators, about implementations like stable fluids, or more particle-based versions. I got a basic skeleton (diffuse, advect, project) and made sure I understood most of the logic.
I then wrote up the advection logic. This took an unfortunate amount of time; I started with a basic manual implementation, but then with some review from DS V4, it was suggested I implement a multigrid logic for performance, so I followed some guides (and advice from V4) to implement it.
I then worked on the diffusion script (I’m separating all parts into different scripts for max clean-ness :D). It wasn’t so bad, but I had to do a bit of research, read up on conjugate gradient solvers, but with some help it was fine.
Projection was a pain; seemingly it affected border conditions, and had to be done multiple times, or could be optimised or something, but it seems to almost work. (Still diverges? I’m not sure.) Ahhh, but the output logs still show significant issues. One day it’ll work.
I then used matplotlib to make a changing visualisation. I would like for it to be a TUI visualisation (with braille?), but for now it works.
After a long break (school international tours, and other stuff), I continued, first by converting the matplotlib visualisation into a TUI ascii-gradient-based terminal text visualisation, using ansi codes for alternate buffers and overwrite to efficiently create the TUI.
That’s a really short recap of my progress; there seem to be a lot of physics accuracy issues, performance optimisations, stuff to learn about numpy vectorisation, etc. But it’s already really cool to watch the visualisation! And the ascii turned out really nice.