The Stable Fluids Algorithm by Jos Stam can be sped up with the help of the Fast Fourier Transformation. Let's implement this in the Julia Programming Language. Here is the code: https://github.com/Ceyron/machine-learning-and-simulation/blob/main/english/simulation_scripts/stable_fluids_fft.jl
The Julia language provides a binding to the FFTW package, the "Fastest Fourier Transform in the West". And indeed, it is fast!
Using the FFT together with periodic Boundary Condition (which you then need to have) greatly simplifies many steps in the Stable Fluids algorithm. In particular, you do no longer have to solve linear systems of equations for the implicit diffusion and the incompressibility projection. On top of that, you do not have to handle Boundary Conditions.
-------
📝 : Check out the GitHub Repository of the channel, where I upload all the handwritten notes and source-code files (contributions are very welcome): https://github.com/Ceyron/machine-learning-and-simulation
📢 : Follow me on LinkedIn or Twitter for updates on the channel and other cool Machine Learning & Simulation stuff: https://www.linkedin.com/in/felix-koehler and https://twitter.com/felix_m_koehler
💸 : If you want to support my work on the channel, you can become a Patreon here: https://www.patreon.com/MLsim
-------
Introduction
00:00 Introduction
00:56 Scenario
01:48 Algorithm Overview
05:22 Package Imports
05:58 Constants
06:21 Some Boilerplate
06:31 Defining the 2D Mesh
08:14 Defining the wave numbers
10:18 Precomputing diffusion decay
10:09 Computing normalized wave numbers
12:20 Defining the force
14:19 Pre-Allocating the Arrays
16:15 Setting up time loop
16:39 (1) Apply Forces
18:00 (2) Self-Advection by streamline backtracing
23:45 (3.1) Transform to Fourier Domain
24:16 (3.2) Diffusion in Fourier Domain
24:50 (3.3) Compute Pressure in Fourier Domain
25:43 (3.4) Project to Incompressibility
27:40 Advance in time
27:54 Visualize
31:15 Bug Fixing
33:14 Discussion
34:00 Outro