A simple conditionally stable 2D incompressible Navier-Stokes solver on a regular Cartesian quadrilateral grid, utilizing the Chorin projection/decomposition method.
The repository contains two implementations:
JavaScriptversion with browser-based solver.C++ consoleversion with MSVC project files, including enhanced ASCII rendering.
In the C++ renderer, each grid cell can display not only velocity magnitude, but also normalized velocity-vector direction markers.
The governing equations are:
We use the splitting method based on the Helmholtz-Hodge decomposition. For any arbitrary vector field
with:
Thus, the velocity field becomes:
Finite Difference (FD) form:
FD form:
FD form:
Rewritten expression for the iterative Gauss-Seidel solver:
A test case involves lid-driven flow in a box cavity. All walls have zero Dirichlet velocity conditions, except for the top side, where a sliding velocity is defined. This velocity periodically changes its direction from left to right and vice versa.
The JavaScript solution visualizes velocity magnitude using ASCII art.
The C++ solution (MSVC project) additionally visualizes normalized velocity-vector directions for each cell. The built executable is available in the cpp/ns_2d_console/build/ directory.
- JavaScript version: open
js/index.htmlin a web browser. - Windows compiled C++ version: run the executable from
cpp/ns_2d_console/build/Release/(compiled for ARM64 architecture). - Manual compilation: requires Microsoft Visual Studio (MSVC toolchain) using the project file
cpp/ns_2d_console/ns_2d_console.slnx.

