Implementation of the paper Particle-based Viscoelastic Fluid Simulation (Simon Clavet, Philippe Beaudoin, and Pierre Poulin) https://dl.acm.org/doi/10.1145/1073368.1073400
https://kotsoft.github.io/particle_based_viscoelastic_fluid/
Implements up to and including Section 3, Simulation Step. Similar to verlet integration, we also track position, and previous position, and use those to compute velocity. Velocity is also stored to be further operated on in the viscosity step.
Implements Section 4, Double Density Relaxation, but neighbor search is O(n^2). Note that for this paper, the inner j loop starts at 0 and not i + 1.
Implements spatial hashing. You can toggle on/off to see the performance difference. Resources:
Iterates through active buckets instead of via particles to try to get more locality.
I wanted to see if I could set up some caches around each bucket I iterate to get a further perf increase.
Implements Section 5, elasticity and viscosity. Spring adjustment is where I had to make some changes to the paper to improve stability.
An unfinished experiment to apply position corrections all at once, rather than sequentially as they are done in the paper. Sequential position corrections is biased, so it causes many swirls to appear, as well as it needs both read and write access to the positions and presents some challenges when multithreading.
If you would like to see more features (e.g. multi-material, rigid bodies) and more optimizations (e.g. SoA version), or if you'd like to support development of my sandbox Liquid Crystal https://kotsoft.itch.io, donations are greatly appreciated.