17 - How to write an Eulerian fluid simulator with 200 lines of code.

  Рет қаралды 280,419

Ten Minute Physics

Ten Minute Physics

Күн бұрын

For the source html code, demo and all other tutorials see matthias-research.github.io/p...
There is also a discord server to discuss all videos here: / discord
In this tutorial I explain the basics of Eulerian, grid-based fluid simulation and show how to write a simulation engine based on these discussed concepts.

Пікірлер: 315
@Pjx1989
@Pjx1989 Жыл бұрын
As a fluid dynamic engineer, I’m very aware of the complexity of CFD. It’s absolutely stunning not just that you wrote a basic cfd code in 200 lines, but that it even runs on a browser and, most of all, that you could explain it in 10 minutes. Astonishing
@nathan87
@nathan87 Жыл бұрын
It's a nice piece of code, but it's literally CFD 101. Everybody's first fluid sim looks like this.
@mastrake
@mastrake Жыл бұрын
@@nathan87 Perhaps intended for people like me who are new to the topic?
@ProjectPhysX
@ProjectPhysX Жыл бұрын
Lattice Boltzmann is even simpler, a basic C implementation is 100 lines. Yet it's a lot faster and much more accurate :)
@mastrake
@mastrake Жыл бұрын
@@ProjectPhysX This is super cool stuff for someone just learning about it.
@abebuckingham8198
@abebuckingham8198 Жыл бұрын
As a functional programmer I see a great deal of redundancy and excess in this code so it could be shortened too. It's rather impressive that they kept it so small.
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
Hi all, thanks so much for all your positive feedback! A great motivation to do more videos!
@nolram
@nolram Жыл бұрын
Glad to see this channel finally get the attention it deserves :) PS: Matthias, consider putting the Discord server in the description of these, since we have a bunch of people there willing to help out others and discuss these videos.
@DogeMultiverse
@DogeMultiverse Жыл бұрын
These r awesome! Physicist content creator
@momoaraki7934
@momoaraki7934 Жыл бұрын
Incredible!!!
@LJ_Dev
@LJ_Dev Жыл бұрын
yes please
@King-mj2bn
@King-mj2bn Жыл бұрын
It would be great if you could use variables names that were slightly more self-describing. Readability is far more important than brevity.
@notapplicable7292
@notapplicable7292 Жыл бұрын
These videos are such a nice breath of fresh air after reading simulation papers
@rstknives2423
@rstknives2423 Жыл бұрын
Everything is easy when you are both a programmer and a physicist
@Premrajcfd7
@Premrajcfd7 Жыл бұрын
Me too..I am a mechanical engineer with a ardent interest and hands-on working knowledge of python,C,C++ to simulate physics
@wallbrick2170
@wallbrick2170 Жыл бұрын
you forgot mathematicians ;-;
@this_is_mayhem
@this_is_mayhem Жыл бұрын
@@wallbrick2170 yeah, mostly methematician, because if you know math then you are able understand physics as well
@krishnakarthik4752
@krishnakarthik4752 Жыл бұрын
@@this_is_mayhem Well, not really
@multiarray2320
@multiarray2320 Жыл бұрын
@@this_is_mayhem meth?
@CosineKitty
@CosineKitty Жыл бұрын
This is exactly what I have wanted to understand for years now. I have long thought it would be so cool to simulate a lava lamp, or the waves on the surface of a swimming pool. Every time I try to read about fluid mechanics, it's page after page of differential equations. You have made this so clear and intuitive. Thank you so much!
@kathmanducity
@kathmanducity Жыл бұрын
I have been looking for this eloquent lecture for the last 15 years.
@joepeters8746
@joepeters8746 Жыл бұрын
I know that you have little views, but the content you makes me delightet! It is very hard to find University level tutorials or explanations for fluids and softbodies, so your well made videos are a treasure! Especially for me as a Games Engineer it is very funny to know the math and algorythms.
@voxelltech
@voxelltech Жыл бұрын
absolutely
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
I am glad you like it. The numbers will go up with more videos. 3K subs for only 17 videos is actually quite good :-)
@adrianalanbennett
@adrianalanbennett Жыл бұрын
This is the shortest, clearest explanation I have ever heard of method like this. Do you have any sources I could look into to learn more? Thanks.
@GeoffryGifari
@GeoffryGifari Жыл бұрын
really appreciate that you go all the way with the instructions, AND put the whole source code out for the public
@j1d7s
@j1d7s Жыл бұрын
I just stumbled on your channel. It is great how much good explanations you pack into a dozen minutes. I will recap all the videos in your series and try out the code.
@deathTurgenev
@deathTurgenev Жыл бұрын
So glad I got this channel recommended to me. The videos along with the PDF overviews are amazing. I'm looking to try them in another language and will be happy to share
@snsacharya1737
@snsacharya1737 Жыл бұрын
A great video for aspiring numerical analysts. Amazing to see how you covered incompressibility to the Gauss-Seidel method within 10 minutes and a code that demonstrates all that 👏
@joxterjones2563
@joxterjones2563 Жыл бұрын
Great video, thanks for posting this. I first wrote a MAC-type simulation for incompressible viscous flow back in the early 1980's. Seeing what you have done in 200 lines of code is amazing - we have come a long way! Your explanations are excellent and are a first rate introduction to a complex topic.
@harrymattah418
@harrymattah418 Жыл бұрын
I just can't decide what impresses me most. The conciseness of the code, or that of your explanations.
@jabaadams4734
@jabaadams4734 Жыл бұрын
I've read Bridson's book on Fluid Simulation for Computer Graphics, but you give an excellent and brief, yet detailed explanation. It cleared some things up for me. Thank you! Subscribed.
@AlienXtream1
@AlienXtream1 2 ай бұрын
THANKYOU! SO many talks about fluid simulations (and fluid/water in general) mistakingly claim (orimply) that water *is* incompressable. this is the first time i've seen someone correctly assert its "functionally incompressable" XD
@halihammer
@halihammer Жыл бұрын
Thank you so much for this information! This is such valuable content for people who are interested but don't have the opportunity or time to acquire this knowledge at a university or by reading specialist literature!
@sietsebuijsman8523
@sietsebuijsman8523 Жыл бұрын
That was very interesting! I’ve been wanting to work towards a fluid simulation for a while, and your explanation really helped!
@erang42
@erang42 Жыл бұрын
Love your videos, Matthias! Such a great initiative to create this video series, and to use web-based tech so that it's easy to play around with your interactive demos. Keep up the great work. ~ Eran.
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
Thanks! I am happy to hear that people like it and will definitely make more videos
@stefdevs
@stefdevs Жыл бұрын
You're doing god's work here. Thank you! Your XPBD research and educational media is enabling me to make a game that I would otherwise not be able to.
@pixel_physics
@pixel_physics Жыл бұрын
Ohh my, i never thought i will see a tutorial from THE Matthias Müller. Im such a huuuuuuuuuge fan of your works and papers! You are probably the most cited person in my bachelor and masters thesis - both about fluids. And damn i like your research. So awesome! Keep up your work! Youre freakn awesome in what youre doing!
@7177YT
@7177YT Жыл бұрын
Brilliant, I could follow along pretty easily. The simple simulation strategy and clear visualisations helped. please prepare more projects simulating closed little systems like this! Thank you!
@abonham82
@abonham82 Жыл бұрын
Quite appreciate the way you articulate variables. “Boldface V”, “italic u and v”. Great work
@j.j.maverick9252
@j.j.maverick9252 Жыл бұрын
finally youtube recommended something good! Thanks for a clear and still concise explanation, the staggered grid approach is new to me also
@hoytvolker3
@hoytvolker3 Жыл бұрын
Elegant as always, thanks for taking the time to share such informative videos.
@maverick.laurel
@maverick.laurel 3 ай бұрын
Thank you so much for the great contents and I have been rewatching the videos many times! ❤ Definitely looking forward to the upcoming tutorials for viscous liquids and other fluid simulation methods.
@youtubeicin2836
@youtubeicin2836 Жыл бұрын
Just discovered your channel and tried out the simulator, so fun! Keep up the good work :)☺
@tantumDicoQuodCogito
@tantumDicoQuodCogito Жыл бұрын
Description of physical behavior of particle is perfect for free interpretation on code by programmers, for me is most important than explaining mathematical. Good video.
@manuelnovella39
@manuelnovella39 Жыл бұрын
Ok, you definitely earned yourself a new subscriber. Keep it up, man, and congrats for your work 👌🏽
@SmartAndSecureWay
@SmartAndSecureWay Жыл бұрын
Excellente vidéo et démo ! 👋 Un plaisir de découvrir votre vidéo et maintenant de vous suivre.
@lucas-coutinho
@lucas-coutinho 7 ай бұрын
Wow that's amazing! I'm really excited about your channel! Thanks for sharing your knowledge
@kiaranritchie3021
@kiaranritchie3021 Жыл бұрын
Another excellent tutorial. Thank you very much for this!
@user-pm4vd6ij8i
@user-pm4vd6ij8i Жыл бұрын
What an amazing channel! I'm very interested in physics simulation, and your channel is awesome! Thank you so much.
@noertri618
@noertri618 Жыл бұрын
Man, thinking about ball hanging motion make my head hurt, but you make simulation of fluid, that is amazing
@supersaiyan9616
@supersaiyan9616 Жыл бұрын
Hello Matthias, Thank you so much for your video series
@irtizahussain5001
@irtizahussain5001 Жыл бұрын
Its so beautiful. I am just going to cry with joy.
@alansmithee419
@alansmithee419 Жыл бұрын
Something I've noticed in my physics course is that simulations of complex systems can be incredibly simple. The difficult bit is determining what is the best way to program something, so that it is both accurate and has reasonable computation costs. The programming itself will almost invariably result in a very short program. From what I can tell the huge thousands-of-lines projects that people spend years developing are tools which have many different methods of doing many different things for many different purposes. Each thing is short, the collation of them all into one widely useable toolkit so that no one ever has to code any of it again is not.
@olbtube
@olbtube Жыл бұрын
Great video, good explanations and the result is beautiful! Subscribed!
@humblerambler
@humblerambler Жыл бұрын
So effective! 15 years ago I was doing these simulations with industrial level CFD software and I was writing much more code just to analyze results. [feels nostalgic]
@imafackinjunglist
@imafackinjunglist 8 ай бұрын
So that is when this would of been groundbreaking?
7 ай бұрын
Thank you very much. Greetings from Popayan, Colombia.
@kingofmaglos3
@kingofmaglos3 Жыл бұрын
Excellent video and a really interesting channel. Defo going to check out more of your videos!
@rodrigocarvalho51542
@rodrigocarvalho51542 Жыл бұрын
As a physicist who moved to CS this is a delight!
@skippythemagnificent8103
@skippythemagnificent8103 Жыл бұрын
This is exceptionally well and clearly explained, many thanks, now to work out how to make the force flow around a 2D planet .....
@sciencefordreamers2115
@sciencefordreamers2115 5 ай бұрын
Thank you so very much man, absolutely valuable content, thank you for generously sharing the code too!
@andrewsheehy2441
@andrewsheehy2441 Жыл бұрын
This is really great! Thank you and well done!
@adidanusaputra4761
@adidanusaputra4761 Ай бұрын
Very impressive make me build an interest in programming
@Trust_me_I_am_an_Engineer
@Trust_me_I_am_an_Engineer 4 ай бұрын
Thank you so much for this explanation, Matthias! I just found this video : it's fascinating. I've subscribed (of course) and now I'll get a (large) mug of coffee and watch your other videos. Actually, you only need 1000 kgf /cm² to compress water more than 3% , but only an engineer who works in high pressure hydraulics would notice that. Don't worry. 😁
@MissPiggyM976
@MissPiggyM976 22 күн бұрын
Very well done, many thanks!
@samanthaqiu3416
@samanthaqiu3416 Жыл бұрын
looking forward for upcoming tutorials!
@KlaudiusL
@KlaudiusL Жыл бұрын
Your channel is gold! .. new subs, thank you
@joshuabeattie6246
@joshuabeattie6246 Жыл бұрын
Thanks for the great information. Hope you're doing well.
@TCsab314
@TCsab314 Жыл бұрын
Instantly subscribed. Thank you.
@CharlesVanNoland
@CharlesVanNoland 7 ай бұрын
Ah, a staggered grid. I never heard of that little trick! Thanks! :D
@cobaltxii
@cobaltxii Жыл бұрын
Beautiful video, subscribed
@tunahandogan5309
@tunahandogan5309 Жыл бұрын
Super Content and Nicely Done 👌👌
@TheAmazingFlint
@TheAmazingFlint Жыл бұрын
Amazing explanation!
@veitheld167
@veitheld167 Жыл бұрын
Awesome! That is the little programm that I always wanted to write myself to simulate the flow around airfoils or sails, but I never managed to get this done. I got a s far as translating the equations to discrete cells, but then I always ended up with very large scarce equation systems, which needed an engine like Matlab to solve. Your choice of the staggered grid and all the other tricks are so elegant and make the solution so lean and efficient. Too bad that you did not post this video years ago, it would have saved me a lot of time. Great job!! Now I am looking forward to your solution of the full Navier-Stokes equations. OK, I'll give you a budget of 300 lines of code for that...😀
@miguelguerrero3394
@miguelguerrero3394 Жыл бұрын
You cant find analytic solutions to fluid dynamics unless in some very simple cases like laminar flow through a pipe, which your case definitely isn't. The only solution is discrete CFD simulation and then verify it is close enough to reality
@veitheld167
@veitheld167 Жыл бұрын
​@@miguelguerrero3394 Yes, I know that. Thats why solving the Navier-Stokes equations is on the list of the Millennium Problems, for which the Clay Mathematics Institute offered a US $7 million prize fund ($1 million per problem). CFD is the only option to approach these problems for now...
@miguelguerrero3394
@miguelguerrero3394 Жыл бұрын
@@veitheld167 oh ok, nevermind then.
@benjaminlehmann
@benjaminlehmann 20 күн бұрын
That was so great. Thanks
@jplanet8
@jplanet8 Жыл бұрын
This is very informative!!!!! 😃
@mytino
@mytino Жыл бұрын
Fantastic tutorial!
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
Thanks, I am glad so many viewers like it!
@ianglenn2821
@ianglenn2821 7 ай бұрын
3:11 The staggered grid is sometimes called the Arakawa grid, after Akio Arakawa, the scientist who popularized it during the nascent years of fluid simulations.
@AsmageddonPrince
@AsmageddonPrince Жыл бұрын
Omg, are you the same Matthias who used to present awesome physics simulation stuff as an Nvidia researcher years and years ago? If yes, I can't believe I found another of your channels after so many years haha :-)
@Havealot
@Havealot Жыл бұрын
@Matthias: Talking about divergence, in theory your video should be five times more informative than the ones on "Two Minute Papers". However, I find this so much more interesting and useful. So, thanks for the additional information inflow. Keep up the great work!
@peterhall6656
@peterhall6656 Жыл бұрын
That was insightful.
@skhelladi
@skhelladi Жыл бұрын
Nice job Matthias! I developed the same code in c++ based in part on yours, I put a demo on youtube.
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
Nice work!
@Elta305
@Elta305 Жыл бұрын
Very good vidéo ! Just a little remark, Lagrange was born in Italy but worked in France with "L'Académie des Sciences", lived through the French Revolution and his body is actually in the Pantheon so it should probably be Franco-Italian. (the concept of nationality came with the Revolution so it's a bit fuzzy)
@azscab
@azscab 6 ай бұрын
This may have changed my life.
@shengzhehou2209
@shengzhehou2209 Жыл бұрын
Very amazing effect ! Will fluid simulation from Lagrange perspective (e.g. SPH) be covered in the future ?
@kqiesaw.9385
@kqiesaw.9385 Жыл бұрын
This is amazing. I'm going to see if I can reimplement this in unity with as much optimization I can shove into it and see what is the largest resolution I can simulate in real time.
@mickeymcfly4954
@mickeymcfly4954 Жыл бұрын
So did you? How did it go?
@thecarlostheory
@thecarlostheory Жыл бұрын
U are a great person.
@shilo_kulo
@shilo_kulo Жыл бұрын
great tutorial
@fCauneau
@fCauneau Жыл бұрын
Great... Great... Great job guy !! Thanks so much for sharing !!! (I wrote such simulator for meteorological applications long time ago, but the code was far from this beauty...)
@blinded6502
@blinded6502 Жыл бұрын
I've read paper named "Real-time fluid dynamics for games" before, which follows similar idea This explanation is a lot more insightful though
@Croesquared
@Croesquared Жыл бұрын
Cool stuff, just finished my aerospace engineering masters. My favorite course was a class in CFD theory. Maybe you could make some videos on the finite volume method as well, or finite elements.
@mghemke
@mghemke Жыл бұрын
This **was** finite volume (the volume we are talking about is one Cell) - for each volume (cell) you are enforcing applying body forces, the divergence is zero (incompressible fluid and no sources or sinks) and the advection of velocities.
@Karlemilstorm
@Karlemilstorm Жыл бұрын
Hello Mathias. Great video, making my own implementation in C++ with opencv now. How many iterations did you run for the Gauss-Seidel method? Is the Gauss Seidel method better than solving the sparse matrix numerically? The big-O complexity is O(n*iter) for Gauss-Seidel and seems to be O(nb²) where b=4 for sparse matrices.
@muggzzzzz
@muggzzzzz Жыл бұрын
Karman vortex street is one of the possible explanations of the wave-particle duality of light. These vortices act as particles and waves at the same time. Imagine that photons are just ether vortices appearing when the ether flows through atoms.
@jmauriciou
@jmauriciou Жыл бұрын
This Is amazing
@blacklistnr1
@blacklistnr1 Жыл бұрын
I don't understand why the pressure can be calculated like that. What am I missing? If it's incompressible d will be 0 "after projection"(@7:03), and if you mean the d before the projection then the liquid is no longer incompressible(it compresses/expands momentarily before propagating the corrected values).
@zaqk2
@zaqk2 5 ай бұрын
at 9:44 , the subscript of weights of last 2 terms seems like typo. Its w00w11 and w01w11. This was an amazing tutorial thou... Most understandable vdo... Thanks for making this.
@sahhaf1234
@sahhaf1234 Жыл бұрын
That's superb....
@NightStarGazer
@NightStarGazer Жыл бұрын
I can't believe I just found this !! I wanted to do CFD for a school project this year but I had given up because i after doing quite extensive research on she topic and trying to write a simple code twice that never worked i got overwelmed and settle for something I find way less interresting. This however gives me hope again thank you so much !! How hard would it be to account for compressibility ? I would really like to manage to implement it.
@eazegpi
@eazegpi Жыл бұрын
I really liked this video. Superbly explained. I have one small question though. What would be the neccessary modifications if your grid had a different spacing in each direction? I think the divergence would have to ve corrected by a factor hy for the u components and a factor hx for the v components, but I can't figure out how to correctly calculate the pressure, which also depends on h. Thanks!
@ricard458
@ricard458 Жыл бұрын
Amazing! Please teach us how to do other types of simulations. I will try all for sure. Thanks for your time.
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
Many videos will follow. I am currently working on one about flip water simulation.
@nolram
@nolram Жыл бұрын
I would still love to see a video about rigidbodies, since they tend to be the most common type of simulation in games and film :) Maybe a more detailed tutorial (especially in regards to angular velocity) based on your XPBD bodies paper could be possible ?
@TenMinutePhysics
@TenMinutePhysics Жыл бұрын
Sure, eventually I will cover everything I have been doing. However, since people seem to like fluid sim a lot the next one will be about FLIP 🙂
@ogibinedi
@ogibinedi Жыл бұрын
i see the code with html 779 line of code .... i just do not know how did you figured out all of those stuff sir, you are incredible...
@ASMacman
@ASMacman Жыл бұрын
Do you expect to have any upcoming example of Semi-Lagrangian simulations like the kind used in oceanic+atmospheric models?
@nikolaoskaimasidis5576
@nikolaoskaimasidis5576 Жыл бұрын
Great video! How does the code manage to create vortices from the boundary layer that separates if no viscosity is included?
@ashishsri970
@ashishsri970 Жыл бұрын
Fantastic video! I'm curious though, any ideas for how could one modify this code to include other arbitrary shapes for obstacles (e.g. a NACA 4 digit airfoil)?
@Joe-zw9ep
@Joe-zw9ep Жыл бұрын
Amazing
@roastyou666
@roastyou666 Жыл бұрын
THANK YOU ❤
@novavr3dnovaresearch780
@novavr3dnovaresearch780 10 ай бұрын
Thanks a lot for the video. Quick question. If we are using Jacobi method instead of the Gauss-Seidel method in order to do parallel implementation. Can Overrelaxation be used with the Jacobi method?
@charlesaugustosantosdocarm7465
@charlesaugustosantosdocarm7465 Ай бұрын
Genius!
@gebybii
@gebybii Жыл бұрын
Hi! Very amazing results! I was working on LBGK before but this solution seems far more powerfull... One question : why advection on x et y components are not the same? Interpolation on y only?
@artemiyf9078
@artemiyf9078 Жыл бұрын
Thank you so much for this tutorial, sir. Can you please explain where you took the equation for the pressure on 7:04?
@lionelmartinez6810
@lionelmartinez6810 Жыл бұрын
Qué maravilla de vídeo. ¿Podría hacer alguno de una simulación electromagnética? Por ejemplo, el funcionamiento de una antena tipo dipolo. Thank
@stanleyyyyyyyyyyy
@stanleyyyyyyyyyyy Жыл бұрын
very nice code!
@daejeonsalam7262
@daejeonsalam7262 Жыл бұрын
you are genious
@stomoxe1
@stomoxe1 Жыл бұрын
Very good ! could you in an other video simulate high frequency propagation into electric circuit? (antenna)
@archi_designer
@archi_designer Жыл бұрын
Thank you, very nice works How we can use custom dxf shape instead of the circle?
@rlhugh
@rlhugh Жыл бұрын
Also, I notice you do not use the pressure-Poisson approach to removing divergence. What is the benefits and trade-offs of each approach?
@Sopiro
@Sopiro 3 ай бұрын
I just found a gem!
Coding Adventure: Simulating Fluids
47:52
Sebastian Lague
Рет қаралды 1,6 МЛН
Navier-Stokes Equations - Numberphile
21:03
Numberphile
Рет қаралды 1,1 МЛН
Шокирующая Речь Выпускника 😳📽️@CarrolltonTexas
00:43
Глеб Рандалайнен
Рет қаралды 12 МЛН
小女孩把路人当成离世的妈妈,太感人了.#short #angel #clown
00:53
WHY THROW CHIPS IN THE TRASH?🤪
00:18
JULI_PROETO
Рет қаралды 9 МЛН
Cute Barbie Gadget 🥰 #gadgets
01:00
FLIP FLOP Hacks
Рет қаралды 50 МЛН
Fluid dynamics feels natural once you start with quantum mechanics
33:00
braintruffle
Рет қаралды 2,1 МЛН
Coding Challenge 180: Falling Sand
23:00
The Coding Train
Рет қаралды 757 М.
What Is The Most Complicated Lock Pattern?
27:29
Dr. Zye
Рет қаралды 1,3 МЛН
How to train simple AIs to balance a double pendulum
24:59
Pezzza's Work
Рет қаралды 71 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 551 М.
I Made a Graph of Wikipedia... This Is What I Found
19:44
adumb
Рет қаралды 2,5 МЛН
But How DO Fluid Simulations Work?
15:12
Gonkee
Рет қаралды 366 М.
Every Weird Math Paradox
11:15
ThoughtThrill
Рет қаралды 16 М.
Turbulent Flow is MORE Awesome Than Laminar Flow
18:32
Veritasium
Рет қаралды 10 МЛН
Шокирующая Речь Выпускника 😳📽️@CarrolltonTexas
00:43
Глеб Рандалайнен
Рет қаралды 12 МЛН