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
vedosity 149 days ago [-]
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...
Yes, particle velocity! I believe this clip is after I implemented metaballs too, so the particles blend together to make it feel more fluid-like.
smusamashah 148 days ago [-]
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
beders 148 days ago [-]
Beautiful and mesmerizing. Well done
BugsJustFindMe 149 days ago [-]
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?
Rygian 149 days ago [-]
> Particles go flying off into space for no reason even long after gross motion has settled on mobile.
My intuition tells me this is how evaporation works.
SiempreViernes 149 days ago [-]
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.
BugsJustFindMe 149 days ago [-]
Except that it doesn't happen like evaporation at all, and it happens differently on mobile vs desktop.
Etherlord87 149 days ago [-]
My problem with it is that the substances coalesce into bubbles, but not into layers depending on weights.
hoseja 149 days ago [-]
They do actually. Red > orange > green > blue. Let it settle.
Etherlord87 148 days ago [-]
But there are still bubbles within layers, no?
kotsoft 148 days ago [-]
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.
semi-extrinsic 148 days ago [-]
They appear more like a sort of gel, if you ask me. Also, some of the heavier fluids actually freeze into cryshals.
AbrahamParangi 148 days ago [-]
This is true of all non-physically accurate fluid simulations which are essentially all of them.
jamiejquinn 149 days ago [-]
Let me highlight some positive things about this:
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.
tromp 149 days ago [-]
The IOCCC also featured a very concise fluid simulator [1] [2], which can be seen in action in this video [3].
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.
For the most relaxing thing you will do today - try to get the different layers to be homogeneous by perturbing them slightly with the cursor.
exodust 149 days ago [-]
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.
kotsoft 148 days ago [-]
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.
This one looks much better, and it seems to better model the stickiness of the water (though maybe the scale is different).
HexDecOctBin 149 days ago [-]
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.
HexDecOctBin 148 days ago [-]
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.
semi-extrinsic 147 days ago [-]
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.
HexDecOctBin 147 days ago [-]
Thanks!
greenbit 149 days ago [-]
Sort of looks like the weird stuff on the TV in Vivarium
Jarmsy 149 days ago [-]
Keys 1-4 spawn new material at the mouse location
Workaccount2 149 days ago [-]
Very cool, could see something like this being in a passive display.
Interestingly, this code is from 2012! I just assumed it was something new.
dukeofdoom 149 days ago [-]
I just want something like this for a pygame I'm making.
But not very compue intensive.
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.
memalign 149 days ago [-]
Fun that it supports multi-touch!
yobananaboy 148 days ago [-]
Trying to sort the particles into single color blobs is pretty fun!
yobananaboy 148 days ago [-]
Whoa also changing window size affects the simulation too!!
tempodox 149 days ago [-]
Nice, I feel splashy.
You can grab a chunk of the goo, drag it up and let it fall.
amelius 149 days ago [-]
Maybe I'm spoiled, but I expected a 3-D simulation.
semi-extrinsic 148 days ago [-]
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
Short clip of my implementation here: https://imgur.com/a/2IARiBq
I like the different fluids in your sim though, I may try that myself.
Things like "how do you properly make a B-52?" ( http://www.cocktailhunter.com/bartender-guide/specific-gravi... ) or a Pousse Café ( https://youtu.be/4OJd_phsa5w )
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?
My intuition tells me this is how evaporation works.
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.
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.
[1] https://www.ioccc.org/2012/endoh1/endoh1.c
[2] https://www.ioccc.org/2012/endoh1/hint.html
[3] https://www.youtube.com/watch?v=QMYfkOtYYlg
Demo : https://kotsoft.github.io/particle_based_viscoelastic_fluid/
Code : https://github.com/kotsoft/particle_based_viscoelastic_fluid...
Video :https://www.youtube.com/watch?v=3OxC4oqy74U
edit : you probably also want to check one of the mentioned link : https://matthias-research.github.io/pages/tenMinutePhysics/i...
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.
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 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).
https://www.researchgate.net/publication/336796234_Material_...
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.
Interestingly, this code is from 2012! I just assumed it was something new.
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.
You can grab a chunk of the goo, drag it up and let it fall.
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.
https://en.wikipedia.org/wiki/Material_point_method
Granted this is web, but I think I can simulate that many particles with a simple loop in java on 60 FPS.
2. Goes down to 15 FPS on my old laptop.
3. The proof is in the pudding: please post the link to your Java code.