6 ms·
Fast real time fluid simulator based on MPM algorithm
- amelius 2y agoMaybe I'm spoiled, but I expected a 3-D simulation.
- semi-extrinsic 2y agoApart 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.
- jamiejquinn 2y agoLet 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.
- limbicsystem 2y agoFor the most relaxing thing you will do today - try to get the different layers to be homogeneous by perturbing them slightly with the cursor.
- Jarmsy 2y agoKeys 1-4 spawn new material at the mouse location
- devdaim 2y agocool stuff
- hiergiltdiestfu 2y agoso satisfying, thank you
- dukeofdoom 2y agoI just want something like this for a pygame I'm making. But not very compue intensive.
- dahart 2y agoHeightfield fluid sims are much less compute intensive. https://dl.acm.org/doi/10.1145/97880.97884 https://dl.acm.org/doi/10.1145/97880.97884 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.
- kotsoft 2y agoHi, 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 https://www.youtube.com/c/GrantKot
- beders 2y agoBeautiful and mesmerizing. Well done
- vedosity 2y agoHey 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... Short clip of my implementation here: https://imgur.com/a/2IARiBq https://imgur.com/a/2IARiBq I like the different fluids in your sim though, I may try that myself.
- cholmon 2y agoVery cool! What does the changing color of the fluid indicate, particle velocity?
- Workaccount2 2y agoVery cool, could see something like this being in a passive display. Interestingly, this code is from 2012! I just assumed it was something new.
- tempodox 2y agoNice, I feel splashy. You can grab a chunk of the goo, drag it up and let it fall.
- yobananaboy 2y agoTrying to sort the particles into single color blobs is pretty fun!
- yobananaboy 2y agoWhoa also changing window size affects the simulation too!!
- 4RealFreedom 2y agoChange your window size and watch the fireworks!
- greenbit 2y agoSort of looks like the weird stuff on the TV in Vivarium
- phkahler 2y agoIMHO 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.
- tombh 2y agoLooks like this is the repo https://github.com/kotsoft/kotsoft.github.io https://github.com/kotsoft/kotsoft.github.io
- GistNoesis 2y agoYou 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. Demo : https://kotsoft.github.io/particle_based_viscoelastic_fluid/ https://kotsoft.github.io/particle_based_viscoelastic_fluid/ Code : https://github.com/kotsoft/particle_based_viscoelastic_fluid/ https://github.com/kotsoft/particle_based_viscoelastic_fluid... Video :https://www.youtube.com/watch?v=3OxC4oqy74U 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/index.html https://matthias-research.github.io/pages/tenMinutePhysics/i...
- tombh 2y agoOh wow, great, thank you!
- dheera 2y agoSalad dressing!
- kragen 2y agothis is absolutely fantastic. i wonder what the source code looks like
- genpfault 2y ago> MPM algorithm https://en.wikipedia.org/wiki/Material_point_method https://en.wikipedia.org/wiki/Material_point_method
- memalign 2y agoFun that it supports multi-touch!
- deleted 2y ago[deleted]
- BugsJustFindMe 2y agoIt'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 2y 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.
- BugsJustFindMe 2y agoExcept that it doesn't happen like evaporation at all, and it happens differently on mobile vs desktop.
- SiempreViernes 2y agoIn 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.
- Etherlord87 2y agoMy problem with it is that the substances coalesce into bubbles, but not into layers depending on weights.
- hoseja 2y agoThey do actually. Red > orange > green > blue. Let it settle.
- beatboxrevival 2y agosimilar: https://github.com/onsetsu/floom https://github.com/onsetsu/floom
- amelius 2y agoThis one looks much better, and it seems to better model the stickiness of the water (though maybe the scale is different).
- HexDecOctBin 2y agoFor 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?
- semi-extrinsic 2y agoContinuum 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 2y agoI 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 2y agoDisclaimer: 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). https://www.researchgate.net/publication/336796234_Material_point_method_after_25_years_theory_implementation_and_applications 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.
- EmilyHughes 2y ago1. Doesn't look like fluid at all 2. Goes down to 40 FPS on my computer Granted this is web, but I think I can simulate that many particles with a simple loop in java on 60 FPS.
- kleiba 2y ago1. It does to me, but then again: 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.
- exodust 2y agoNice. 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 2y agoThanks. 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.
- tromp 2y agoThe IOCCC also featured a very concise fluid simulator [1] [2], which can be seen in action in this video [3]. [1] https://www.ioccc.org/2012/endoh1/endoh1.c https://www.ioccc.org/2012/endoh1/endoh1.c [2] https://www.ioccc.org/2012/endoh1/hint.html https://www.ioccc.org/2012/endoh1/hint.html [3] https://www.youtube.com/watch?v=QMYfkOtYYlg https://www.youtube.com/watch?v=QMYfkOtYYlg