Navier-Stokes simulator (WIP)

Foreword

Under classical, non-relativistic continuum mechanics, effectively incompressible Newtonian fluids are governed with remarkable accuracy by the following system of partial differential equations:

\begin{equation*} \begin{aligned} \nabla \cdot \mathbf{q} &= 0,\\ \frac{\partial \mathbf{q}}{\partial t} + \nabla \cdot (\mathbf{q} \otimes \mathbf{q}) &= -\nabla p + \frac{1}{\text{Re}} \nabla^2 \mathbf{q}, \end{aligned} \end{equation*}

where \(\mathbf{q}\) is the velocity vector, \(p\) is the pressure, and \(\text{Re}\) is the Reynolds number. We will craft a tiny solver for this system in BQN, considering a 2D domain with periodic boundary conditions.

Simulator

The simulator is based on the material from this book, but aiming for a zero dependency implementation.

z ← {
  _p ⇐ {(-´𝔽¨)β‹ˆ(+´𝔽¨)⟜⌽}
  Cβ€ΏE ⇐ βŸ¨β‹ˆβŸœ-´˘, β€’math{𝕗.Cosβ‰Λ˜π•—.Sin}⟩
}
FFT ← {π•ŠβΌ: z.C{β‰ Γ·ΛœΒ·π”½π”Ύβˆ˜π”½}π•Šπ•©; (1=β‰ )β—ΆβŸ¨(+∾-)⟜(βŠ’Γ—z._p˘·z.E∘-Ο€Γ—β†•βŠΈΓ·βˆ˜β‰ )Β΄(π•ŠΒ¨βŠ’βŠ”Λœ2|βŠ’Λœ), βŠ’βŸ©π•©}
βŠ‘βˆ˜βˆž