Run OpenFOAM CFD simulations entirely in the browser via WebAssembly.
This project cross-compiles a minimal OpenFOAM stack (v2512) to WASM using Emscripten and provides a web frontend that runs meshing and solving without any server-side computation.
Important
This requires an OpenFOAM installation to build, but not to run in the browser.
- Compiles OpenFOAM core libraries to WebAssembly (static archives)
- Builds blockMesh and scalarTransportFoam as WASM executables
- Provides an example browser UI that:
- Loads OpenFOAM WASM modules in a Web Worker
- Runs blockMesh + solver with streaming console output
- Renders 2D field visualization (scalar/vector fields with jet colormap)
- Auto-generates editable forms for all case dictionaries (controlDict, fvSchemes, etc.)
- This is not reflection/introspection
- Case as a template -> user can change entries -> but no additions/removal
- Shows the objectRegistry contents at each time step via a built-in
registryDumpfunctionObject - Provides a filesystem explorer for all solver outputs
- libPstream (dummy)
- libOSspecific
- libOpenFOAM
- libfileFormats
- libsurfMesh
- libmeshTools
- libfiniteVolume
- libblockMesh
- libextrudeModel
- libdynamicMesh
- Docker with the
emscripten/emsdk:3.1.56image - Git (to clone OpenFOAM source)
- A modern browser with WebAssembly support (Chrome, Firefox, Safari, Edge)
# Clone this repo
git clone <repo-url> openfoam-wasm
cd openfoam-wasm
# Build everything (clones OpenFOAM v2512, patches, compiles via Docker)
./build.sh
# Serve the web app
cd dist
uv run python3 -m http.server 8080Open http://localhost:8080/ in your browser.
A live demo is available at foamscience.github.io/openfoam-wasm.
# Use an existing OpenFOAM source tree (skip clone)
./build.sh --foam-dir /path/to/openfoam
# Interactive Emscripten shell (for debugging)
./build.sh shell
# Clean build artifacts (have to remove the patforms folder manually if --from-dir is used)
./build.sh clean
# Control parallelism
JOBS=8 ./build.sh-
Build phase: The build script runs inside a Docker container with Emscripten, compiles OpenFOAM libs to static
.aarchives, then links the solver executables as.wasm+.jsmodules. -
Runtime: The browser loads the WASM modules into a Web Worker. Case files are written to Emscripten's in-memory filesystem (MEMFS).
blockMeshgenerates the mesh, thenscalarTransportFoamruns the simulation. Results are read back from MEMFS and rendered on a canvas. -
Key WASM adaptations:
POSIX.Cguards arounddlopen, signals, sockets (not available in WASM)- Static linking with
--whole-archiveto preserve Runtime Selection Tables dummyPrintStackreplacesexecinfo.h-based stack traces-fexceptionsand-sDISABLE_EXCEPTION_CATCHING=0for C++ exception support-sUSE_ZLIB=1for compressed I/O support
pitzDaily (scalarTransportFoam) — 2D backward-facing step with passive scalar transport. Editable via the auto-generated case editor in the browser.
- Ensure all required libraries are in the build list in
build.sh - Add a
build_appline for the solver - Update
collect_distto copy the new WASM binary - Exclude
coded*/codeStreamfeatures (requiresdlopen)
WASM binaries can get a bit large; we probably can optimize what to include in them, but they will get large anyway (no dlopen) so I din't care enough; They ship everything.
- tree-sitter-foam a tree-sitter grammar for OpenFOAM, WASM-buildable
OpenFOAM is licensed under the GNU General Public License v3.0. See the OpenFOAM license for details.