cherryteastain 23 hours ago

Treat this as a "what do I need to do to make fluid flow that looks okayish in graphics" post rather than "how do I implement physics accurate CFD for industrial/scientific purposes" post.

Lots of points in there like

> "Air is an example of a compressible fluid; you squish it and it gets smaller. Water is an example of an incompressible fluid; you squish it and it pushes back, and doesn't get any smaller" (this only really depends on the Mach number, Ma>~0.3 and you are in compressible territory for any fluid. Incompressibility usually means we assume the divergence of velocity of zero)

> "Incompressible fluids are simpler to simulate because their density and pressure is always constant." (This is only true if you choose to adopt a grad P = 0 approximation)

are incorrect from a physics perspective.

If you look at what real incompressible Navier-Stokes solvers do [1], it's mathematically totally different from what this post shows. In fact, the part that this post omits (handle the pressure gradient term by first approximate time stepping the velocity term by ignoring the pressure term and then correct by solving a Poisson equation for the pressure residual, and then correct the velocity) is the most expensive step in incompressible solvers by far.

[1] https://en.wikipedia.org/wiki/Projection_method_(fluid_dynam...

  • WhitneyLand 22 hours ago

    Hate it when incompressible fluids are mentioned like it’s literally true with any qualification or explanation.

    Iiuc water might compress ~50% at the right place in the Earth’s mantle, maybe just not looking much like liquid.

    • usrnm 20 hours ago

      Every science including physics consists of models that are just good enough for a particular use case. It's implied

    • dieselgate 19 hours ago

      Think it was a high school physics demonstration where a glass bottle is filled to the brim with water and then dropped to show it doesn't break? Something like that, or you can hit it fairly hard with a hammer and it won't break as easily compared to an empty bottle.

      That and boiling water in a paper cup over a bunsen burner (chemistry class) are some of my favorite science demonstrations!

      Was literally talking to someone the other day about water being irregular in how it expands at freezing temperatures opposed to contracting.

      Water/H2O is such a cool molecule/substance

luismedel 5 hours ago

Nice.

The earliest jaw-dropping water effect I saw (and somewhat understood at 14) was the awesome credits scene from the Iguana's Earthquake demo[0].

The code[1] contains the following explanation (ancient DOS chars fixed with chatGPT)

  ; // UpdateTable : performs one integration step on U[CT]
  ; Differential equation is:  u  = a²( u  + u  )
  ;                             tt       xx   yy
  ;
  ; Where a² = tension * gravity / surface_density.
  ;
  ; Approximating second derivatives by central differences:
  ;
  ;  [ u(t+1)-2u(t)+u(t-1) ] / Δt² = a² (u(x+1)+u(x-1)+u(y+1)+u(y-1)-4u) / h²
  ;
  ; (where Δt = time step, h=Δx=Δy = mesh resolution)
  ;
  ; From where u(t+1) may be calculated as:
  ;                   ┌   1   ┐
  ; u(t+1) = a²Δt²/h² │ 1 0 1 │u - u(t-1) + (2-4a²Δt²/h²)u
  ;                   └   1   ┘
  ;
  ; When a²Δt²/h² = ½ last term vanishes, giving:
  ;                   ┌   1   ┐
  ;        u(t+1) = ½ │ 1 0 1 │u - u(t-1)
  ;                   └   1   ┘
  ;
  ; This needs only 4 ADD/SUB and one SAR operation per mesh point!

[0] https://www.pouet.net/prod.php?which=364

[1] https://hornet.org/code/demosrc/demos/hq_water.zip

otterdude 23 hours ago

This is an ok introduction to CFD in that you discretize a problem, but it is not insightful and not scientific in its approach. The author routinely admits he doens't know how certain portions of the code work.

This is a much better approach to CFD / Navier-Stokes and will help you understand the various phenomenon along the way. https://lorenabarba.com/blog/cfd-python-12-steps-to-navier-s...

  • gfaure 23 hours ago

    Agreed. I started from this article a few years ago, and was frustrated enough by:

    > So that means, while I know what it does, I don't really know how, since all the work is in that mysterious function.

    that I spent the time to work it out myself. (answer: It arises from discretising the Laplacian -- 6 is the number of direct neighbours in 3D)

  • wiz21c 22 hours ago

    CFD start to become really painful when the fluid leaves the cells...

    • otterdude 19 hours ago

      Thats why we have the courant number!

jlhawn 1 day ago

The title should be updated to note this is from 2006.

Has there been anything like this published in the past 20 years but for compressible fluids? I have wanted to make a simple atmospheric model for years but have been unable to because of the complexity and probably my lack of complete understanding.

  • lacunary 22 hours ago

    I'm curious what you want to model; what's an example phenomenon you'd like to be able to demonstrate?

    • jlhawn 20 hours ago

      Atmospheric circulation. hadley cell, polar cell, and mid-latitude cells. It would also be interesting to see how new bands would occur if we increased the rotational speed of the earth, thus increasing the strength of the coriolis effect. It would also be neat to draw your own continents and orography and see how that impacts climate. which places become more wet/dry, etc. Change how much long wave radiation is absorbed by the atmosphere as the composition of the atmosphere changes. I'm not interested in actually making weather or climate predictions but using it as a tool to educate people on how the climate works.

      • jamiejquinn 18 hours ago

        Interestingly, most large-scale atmospheric models I know of use a (mostly) incompressble fluid approximation, even though air is obviously compressible at human scales. It just isn't at the flow speeds and length scales of global-scale fluid models. Where compressibility is important for those models is where density changes due to temperature. Look into the Boussinesq and anelastic approximations if you're interested!

        • jlhawn 13 hours ago

          that's interesting because my understanding was that a lot of models used pressure as the vertical (height) coordinate and with tracking temperature at any given coordinate lets you know the density of the air at any point.

          • jamiejquinn 6 hours ago

            That's typical of models that use the anelastic approximation, where it's useful for a number of reasons to rewrite the equations replacing the true vertical with a vertically stratified variable. I've seen density, pressure and temperature used.

            That's less of a different model and more a different way to rewrite the equations to make them easier to analyse or simulate.

            We might be talking at slightly different angles here. There's a strong difference in the equations between compressibity of the fluid due to compression and changes in density due to temperature, chemical concentration, etc. The term compressibility usually refers to the first usage, and modelling it leads to sound waves in the system and has major implications for how the system is simulated, I mean it's an entirely different class of algorithms. The second, where density still changes but not due to compression, so no sound waves, that can be easily modelled without including full compressibility. This allows (generally simpler) incompressible models to still incorporate useful thermal physics where important, like in climate and weather. Also, the smaller the scale of the system the more compressibility matters so I wouldn't be surprised if compressibility starts to matter for e.g. Tornados. But I'm not certain on that...

  • btrettel 18 hours ago

    Fluid dynamicist here. The word "compressible" has multiple meanings and this might be confusing you. You don't need compressible flows in the sense of high Mach numbers. There are other models where the flow is variable density, but thermodynamic and hydrodynamic pressure are decoupled to remove the pressure waves that make high Mach number flows hard. There's also the Boussinesq approximation for buoyancy when the density varies only a small amount. I'm not particularly familiar with atmospheric models, but I'm sure they don't use the high Mach number form. "Incompressible" methods are common for the second class of model I mentioned, though how to use them so might not be obvious.

briandw 23 hours ago

I don't know about the CFD, but I really enjoyed reading this blog back in my iOS days. Friday Q&A was especially good. He would take some part of Obj-C or Cocoa and build a simple version from scratch.

jp191919 20 hours ago

Reminds me of The Structural Dynamics of Flow by Leslie Claret

makach 23 hours ago

article is good, comments are fantastic!