Hi, I made this demo. This is actually all from the paper Particle-based Viscoelastic Fluid Simulation (Simon Clavet, Philippe Beaudoin, and Pierre Poulin). It is an SPH type (particle-particle interactions), not MPM (particle-grid-particle). I do a lot of MPM nowadays, and I have a multi-grid thing to help with incompressibility, but this was me re-implementing the first fluid sim paper I ever implemented.
I did the implementation in JS to help other people reading the paper, and tried to keep everything as similar as possible to the pseudocode from just this single paper. Maybe it would be cool to integrate an additional grid on which incompressibility is enforced better but I didn't want to make the source confusing.
It is also a little difficult to do density ratios with just what is shown in the paper, here the masses are set to (1, .8, .6, .4). This is what causes the lightest particles to get launched so violently in the air. Probably would be useful to integrate some ideas from the paper Density Contrast SPH Interfaces (Barbara Solenthaler, Renato Pajarola).
I started revisiting SPH because I have some new ideas to combine it with an MPM/FLIP grid for closeups. I'm trying to do a multi-scale MPM simulation that can handle better surface tension droplets in closeups while also doing extremely large scale scenes. You can see some larger scale parallel sims on my YouTube: https://www.youtube.com/c/GrantKot
Hey this was also the first fluid sim paper I ever implemented! I haven't done any grid-based simulations (except maybe the classic "Real-Time Fluid Dynamics for Games" by Jos Stam), but I've been able to greatly improve compressibility by using "Position-Based Fluids" by Miles Macklin. Someday I'll dive into WebGPU and post a JS version on HN...
I have been following your work on twitter for quite a while. Didn't know you were on YouTube as well. I guess I was doing this since one of these demos https://youtu.be/BCUh1opDGA4
It's neat, but also it's unstable and hyper-energetic. Particles go flying off into space for no reason even long after gross motion has settled on mobile. Two particles falling downward past each other impart upward momentum somehow.
Also the fluids appear to be extremely compressible as to appear bouncy, like the whole thing is breathing, so not liquids, but also non-mixing and with surface tension, so not gasses? What fluids behave like this? Some kind of...uh...immiscible foams?
In principle yes, but real liquid atoms never "settle down" whereas the ones in the simulation clearly do.
What is going on is that the particles in this simulation represents something more like droplets: huge quantities of atoms grouped together and treated as solid sphere with properties matching some average of the atoms it is supposed to represent.
And water doesn't evaporate a droplet at a time, thus evaporation is something that this type of simulation cannot reproduce.
I'm not sure if the between layers thing might be a similar thing to when bubbles show up on the sides and bottom of a glass of water. Some of the bubbles are also staying because once it's settled down, there isn't enough action to cause them to pop. The constant associated with the surface tension in the sim can also be turned down.
Love the interesting density stratification and the little bubbles that move around. Very foamy or multi-fluid looking.
Not sure if it's intentional but the fact a click/touch only sort of locks the nearby particles is very satisfying. The fact I can slowly absorb particles into the click region, that the particles still engage in the slow, sticky motion and evolve inside the region and that I can then fling them off is bizarrely good.
Sure it could use a bit of optimisation and tweaking to make it move and look more like a fluid but I think this is a fantastic proof of concept of this particular method as an online, interactive example.
IMHO it behaves too much like a particle system. Even from the start, individual particles seem to pass through what should be a large pool of fluid at the bottom. Interesting, but doesn't seem physically realistic.
You probably also want to check the project from the same author that has more control sliders and code in human readable format instead of compiled wasm.
Nice. I like how it's full screen and responds fluidly to changing the browser window size.
Cool how it pauses when switching browser tabs. My RTX-3080* hums a little louder during the sim but not too much. I'm getting about 57 fps @ 3440x1440. *Actually probably my CPU fan doing the humming.
Thanks. It's a WebAssembly simulation so mostly CPU and very light on the GPU because it's just drawing points. It will actually run on mobile too with multitouch.
For someone with high-school level understanding of classical Newtonian mechanics, what would be the best way forward to learn Continuum Mechanics and things like MPM, etc.? Any book/course recommendations?
Continuum mechanics in itself is a very different subject from particle-based methods to approximate continuum mechanics, like MPM.
To actually learn continuum mechanics you need first a good understanding of vector calculus. But this is not necessary at all for using and tweaking particle based methods.
I see. What are the pre-requisites for understanding and playing around with MPM then? It's very hard to figure this out as someone who hasn't studied physics for a decade.
Disclaimer: I'm not an MPM expert at all, but I work in computational fluid dynamics.
I would suggest to start with the paper I link to below. First skim read it to understand the structure. Then try to follow in detail the parts that interest you most, and play with the code they provide. If you encounter concepts you don't understand, which are necessary for progressing, go look those up on Wikipedia or Google Books (for textbooks).
And don't be discouraged by the math notation. It's mostly just shorthand for things you probably understand very well in code.
For example the capital sigma (sideways M) with a letter "p" or something underneath simply means "loop over the range of the index p, and sum up the following expression for the different values of the index".
The capital delta (triangle pointing up) means "difference", for example delta-t is the increment from one time step to the next.
The upside-down delta is the Nabla, which means gradient, which means derivative in each spatial dimension.
You will trade away details, so this depends entirely on what you need for visuals and interactivity; heightfield fluids won’t give you splashes or bubbles or swirling. You could try to mix a heightfield sim on most of the bottom with a thinner SPH layer on top, but that might be treading into research territory.
Apart from 3D being harder to implement and slower to solve, it's also quite tricky to visualize.
You can't do like in the examples linked in this discussion and simply plot every (Nth) point, that mainly just dissolves into visual chaos. So you have to do 2D slices, or isosurfaces or streamlines or 3D view of a few tracer particles, preferrably combined with animated rotation of the system.
I did the implementation in JS to help other people reading the paper, and tried to keep everything as similar as possible to the pseudocode from just this single paper. Maybe it would be cool to integrate an additional grid on which incompressibility is enforced better but I didn't want to make the source confusing.
It is also a little difficult to do density ratios with just what is shown in the paper, here the masses are set to (1, .8, .6, .4). This is what causes the lightest particles to get launched so violently in the air. Probably would be useful to integrate some ideas from the paper Density Contrast SPH Interfaces (Barbara Solenthaler, Renato Pajarola).
I started revisiting SPH because I have some new ideas to combine it with an MPM/FLIP grid for closeups. I'm trying to do a multi-scale MPM simulation that can handle better surface tension droplets in closeups while also doing extremely large scale scenes. You can see some larger scale parallel sims on my YouTube: https://www.youtube.com/c/GrantKot