Fast real time fluid simulator based on MPM algorithm
kotsoft.github.io
kotsoft.github.io
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
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.
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.