Stable Fluids implemented in Python/NumPy

Поделиться
HTML-код
  • Опубликовано: 25 авг 2024

Комментарии • 52

  • @MachineLearningSimulation
    @MachineLearningSimulation  2 года назад +2

    Check out Jos Stam's 1999 SIGGRAPH Paper here: d2f99xq7vri1nk.cloudfront.net/legacy_app_files/pdf/ns.pdf
    And his 2003 GDC extension here: graphics.cs.cmu.edu/nsp/course/15-464/Fall09/papers/StamFluidforGames.pdf

  • @programming3218
    @programming3218 2 года назад +9

    I was expecting this to have so many more views. Great job!

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад

      Thanks for the kind words 😊
      Feel free to share the video with friends and colleagues. ;)

  • @fexvfx
    @fexvfx 3 месяца назад +1

    Ich finds geil wie du from scratch das einf mal so dahincodest und dabei super erklärst 😅

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 месяца назад

      Danke für das Kompliment 😊
      In die Vorbereitung zum Video ist natürlich auch etwas Zeit reingeflossen :D

  • @wanhonglau779
    @wanhonglau779 2 года назад +6

    this channel is super cool!

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +1

      Thanks a lot :)
      Feel free to look around and if you enjoy, consider sharing it with your peers. That would be super nice.

    • @wanhonglau779
      @wanhonglau779 2 года назад +1

      @@MachineLearningSimulation definitely!
      Additionally would you consider building a community on Discord for exchange of all things related to simulations, ML .. etc.?
      I believe its also a good platform for doing live coding tutorial

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +1

      That's a great idea. Indeed, I was also thinking about starting a community server on Discord. I might do it in the next weeks.
      Can you elaborate on what you mean by Discord being a good platform for live coding tutorials?

    • @wanhonglau779
      @wanhonglau779 2 года назад +1

      ​@@MachineLearningSimulation awesome! I look forward to it happening
      In Discord, you can open a voice live channel where audience are free to join. In the channel, you could share your screen. So it ends up working pretty much like Zoom/ Google Meet. I do see a number of ML related Discord community adopting this approach to interact with audience/ hosting tutorial class

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +1

      Thanks for the insight :)
      I probably have to do a bit of research on how to set it up properly and maybe get some inspirations of the ML discord channels. (Do you have some good examples there?).
      Maybe, it can be live before Christmas.

  • @theworldischanging71
    @theworldischanging71 2 года назад +2

    Thanks a bunch for this vid my guy 🙏

  • @EarlWallaceNYC
    @EarlWallaceNYC 2 года назад +2

    Excellent. Thank you

  • @Anzo9
    @Anzo9 5 месяцев назад +1

    Thank you for making this excellent video and the impressive, efficient implementation! I have a question though regarding the diffusion operator which I might have misunderstood. Should the diffusion operator not be the discretised form of A = [ identity - viscosity * dt *
    abla^2 ] which is solved for with b = the advected vector field (w_2 in Stam's paper) as part of the linear system? In your code, A seems to be already premultiplied by the advected vector field (w_2) which is only meant to be b in the linear system.

  • @Kaassap
    @Kaassap 6 месяцев назад +1

    great video! Is there a reason for not using object oriented programming?

    • @MachineLearningSimulation
      @MachineLearningSimulation  6 месяцев назад

      Thanks 🙏
      No particular, back at the time of the creation of the video, that was my preferred way of teaching it. Today I still believe, that the functional approach is more straightforward. However, in the more recent videos (like the ones on the KS equation) you also see a little bit of OOP.

  • @achalpandeyy
    @achalpandeyy Год назад +1

    Hi, I have a question.
    After the step 4.2 "Correct the velocities to be incompressible", when I compute the divergence (with the same function as defined in the code) of `velocities_projected` I still get non-zero divergence values. Why is that? Isn't making the divergence 0 the entire reason we did this step?

    • @MachineLearningSimulation
      @MachineLearningSimulation  Год назад

      Hi, that's a great question!
      If you compute the divergence before and after the projection step, one sees a difference. There is a reduction in divergence. But divergence of the velocity field after projection is not zero (or at least not below a sufficient tolerance) like what we would want for incompressibility.
      From a CFD point of view, you are right: having a non-zero divergence (or at least not below a sufficient tolerance) is an incorrect simulation. However, (even an incorrect) incompressibility projection step creates swirly motion, which is what I wanted to obtain for the video. You can also see this yourself if you comment out the projection step, the fluid will just boringly flow upwards. It does not create the bloom.
      The reason we see this, is because we are only "partially" projecting to incompressibility. The problem with the code is (as with many PDE simulations) a correct prescription of the boundary conditions. For the pressure poisson problem, one commonly has homogeneous (=zero) Neumann boundary conditions. We do not have this here. I chose that to simplify the code with the consequence of not being fully physically correct. If you take a look at the matrix-free poisson Operator, you can clearly see that this does not solve for Neumann BCs. Indeed, it does not even prescribe Dirichlet BCs. It does something really weird (a mathematician might also say stupid :D ) in that it has zero on the main diagonal for entries that lie on the boundary. That is a very crude assumption, but is sufficient for our purposes here :).
      Hope that helped. Let me know if sth is unclear.

    • @achalpandeyy
      @achalpandeyy Год назад

      @@MachineLearningSimulation I see. Thanks for the detailed response!

  • @heavennoes
    @heavennoes 2 года назад +2

    I tried this code on Jupiter but it is showing per 'frame'

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +1

      Yes, I can understand. The relatively crude way I implemented the animation here does only work when you execute the script as a single Python file. In order to get a proper animation in Jupyter Notebooks, you probably have to resort to Matplotlib Animations: jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
      If you want to look into it and port the simulation to this other animation format, feel free to open a Pull Request on GitHub Repo: github.com/Ceyron/machine-learning-and-simulation

  • @maximegr3992
    @maximegr3992 9 месяцев назад +1

    Hello man, really liked the video. I am trying to use the same algorithm for other configurations but I need to implement boundary conditions. Any idea on how to do this ? Thanks in advance

    • @MachineLearningSimulation
      @MachineLearningSimulation  9 месяцев назад +1

      Hi, appreciate the kind words 😊
      This video already uses wall BCs (homogeneous Dirichlet BCs), although the pressure handling is a bit hacky.
      If you are interested in periodic BCs, then check out the Julia video: ruclips.net/video/F7rWoxeGrko/видео.html
      Or what kind of boundary conditions are you interested in?

    • @maximegr3992
      @maximegr3992 9 месяцев назад +1

      @@MachineLearningSimulation Hi thanks for your respond. I was making some simulations where I had put a wall in the middle. For that, I used Dirichlet boundaries by just fixing the velocity everywhere at the wall to be zero, which is just a realisation of the no slip condition. So I think its fine now. Thanks though! My next goal is to implement an algorithm myself to solve NSE based on finite difference method applied on both the streamfunction and vorticity

  • @snusnufreak
    @snusnufreak Год назад +1

    This looks very similar to the finite difference approach you used to solve the open-lid problem in another of your videos. I wish I could learn the subtleties, where would you suggest to start?

    • @MachineLearningSimulation
      @MachineLearningSimulation  Год назад +2

      Hi,
      there is indeed a great similarity between the two. :)
      I think the best way to start is to look at numerical solution strategies to PDEs, in particular to the essential problems of Navier-Stokes which are diffusion, advection, convection, and incompressibility projection. There will be a video series on the channel covering those in the mid-near future. Until then, I can totally recommend Lorena Barba's 12 steps to Navier-Stokes lorenabarba.com/blog/cfd-python-12-steps-to-navier-stokes/ . It is a bit outdated by now, not in the numerics, those are still correct and well-used, but she uses an older approach to Python. For this new series, I want to use "modern Python" as well as Julia.
      For the stable fluids algorithm, the advection/convection is not done by classical Eulerian schemes like central or upwind differences, but by a semi-lagrangian scheme. This is quite an interesting approach, but it is almost only used in computer graphics as there are little theoretical guarantees on it in comparison to classical CFD techniques. In order to understand, I can recommend Jos' papers linked in the pinned comment.
      Good luck with the learning journey :). It is very captivating, but can also be frustrating :D.
      And maybe see you soon for the new playlist! :)

  • @sudeephalder8792
    @sudeephalder8792 Год назад

    Can you please tell me in detailed that how you are creating the animation of this fluid flow??? I can plot , but not able to animate. Kindly help

    • @MachineLearningSimulation
      @MachineLearningSimulation  Год назад

      The animation used for this simulation is a bit hacky. 😅 It only works if you run it as a script and will probably not correctly work if executed within a jupyter notebook. One is also unable to export it as a movie, gif etc.
      All of that would be possible with the FuncAnimation functionality of matplotlib, but I do not have much experience with it. If you do, please feel free to open a pull request on GitHub :)

  • @jhanolaer8286
    @jhanolaer8286 2 года назад +1

    Sir, just asking.. how do i combine or interact the density arrays and velocity arrays?

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +1

      Hi,
      thanks for the question :)
      I am not 100% sure if I get you right. Are you referring to something like shown in this video: ruclips.net/video/RaaDhAu-QFk/видео.html ?
      If this is the case, you could, for instance, build an interactive application that reads in the mouse position and drag direction during each time iteration. Based on that, you could have a heuristic that relates the input into some form of forcing f you apply, as shown in the first step of the algorithm.
      Hope that helps :)

    • @jhanolaer8286
      @jhanolaer8286 2 года назад

      @@MachineLearningSimulation Hi sir, sorry. what i mean is if i update the velocity how do I update the density connected with him at velocity?

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад

      @@jhanolaer8286 Probably, you refer to having a passive species within the flow. You basically have to advect the densities alongside the velocities.
      It's a little more advanced to discuss it in the comment. I would refer you to the original paper by Jos Stam: d2f99xq7vri1nk.cloudfront.net/legacy_app_files/pdf/ns.pdf

    • @jhanolaer8286
      @jhanolaer8286 2 года назад

      @@MachineLearningSimulation Sir, another question. If i make diffuse the density ,then the same also the velocity make to diffuse?

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад

      Yes, you could use the same implicit diffusion step for the velocities and the densities. You just have to adjust the diffusivity as they might differ.

  • @vowo4931
    @vowo4931 2 года назад +4

    :D I didnt understand but like

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +3

      Haha :D Glad, you liked it.
      I can totally understand that the video is quite packed, so it can be hard to digest if one's base knowledge in Numerics or Python is not too deep. But for all the videos in this playlist, I plan to have two versions: A short one (like this) for which it is just coding it down for people who have some prior understanding and just want to see, how it can be done - and another, longer video with all the details.

    • @vowo4931
      @vowo4931 2 года назад +2

      @@MachineLearningSimulation tnx for all the information, im trying make water with cellular automata maybe thats more easy haha but i want to know more about this method new sub :D

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад +2

      Thanks a lot ❤️
      Cellular automata are also nice for this.
      I also want to release a video on the lattice-boltzman method in the next weeks. It is some sort of advanced cellular automata.

    • @vowo4931
      @vowo4931 2 года назад +1

      @@MachineLearningSimulation did you have discord server? it can be cool to notify and share stuff for learning etc

    • @MachineLearningSimulation
      @MachineLearningSimulation  2 года назад

      Not yet, but I'm thinking of starting one. Atm, I'm doing some research on I could properly do it.
      Do you have some public discord servers you like (maybe also with regard to educational content) that I could take a look at for some inspiration?
      I plan to have the discord server then started before the end of the year.

  • @brtw2478
    @brtw2478 2 года назад +2

    Hey man! Do you have any platform in which I could message you on? /an email I could send to, have an enquiry!