Issue 124 – November 26, 2022

OpenFOAM on Windows: First Contact

Hey there,

It’s Robin from CFD Engine, a Mac user who’s been diving into the world of OpenFOAM on Windows & coming up pleasantly surprised.

I tried three different options for installing OpenFOAM on Windows 11 & (spoiler alert) I reckon I could use any of them as my daily driver 😲

Here’s a (surprisingly positive) summary of my first contact with OpenFOAM on Windows…

“You don’t”

It’s been a decade since I last used a Windows machine & back then the answer to “How do I run OpenFOAM on Windows?” was…“You don’t.”

Back then you probably did your OpenFOAM in Linux – maybe on a separate machine, maybe by dual-booting your Windows box, or (at a pinch) in a virtual machine.

Whichever route you took, you were probably stuck with less RAM & less cores than you really wanted. Windows machines didn’t make great OpenFOAM workstations back then.

But times have changed – your current Windows box probably has loads of cores & heaps of RAM, certainly enough to do some CFD. So, how easy is it to install OpenFOAM on it? 🤔

Let battle commence

I’d seen Windows mentioned on the OpenCFD wiki, so that was my first stop. If an official release works well, then I don’t need to look any further.

The wiki detailed three installation options:

  • Windows Subsystem for Linux – the bit of Microsoft magic that lets you run a Linux distribution inside Windows.
  • Native Windows – like it sounds, a native Windows version of OpenFOAM that comes with a little Unix-like environment to work in.
  • Docker – the packaging option everyone loves to hate, except me 💛

I came prepared for battle, but (to my surprise) they all pretty-much just worked. Here are a couple of thoughts on each one & some gotchas…

Windows Subsystem for Linux (WSL)

This is my preferred option & the one I’d recommend, whether this is your only CFD machine or if you’re building cases to run on a Linux cluster.

Install the latest WSL from the Microsoft Store, then type wsl in a PowerShell & follow the instructions to install Ubuntu (it takes a few mins to install).

You could use another Linux distribution (Debian, Kali, SUSE or Oracle) but using Ubuntu makes the OpenFOAM install really easy.

Once it’s ready, you can copy-paste the usual Ubuntu installation commands for either an OpenFOAM.com or an OpenFOAM.org release & you’re all set.

Very uneventful 👏

Native Windows

This is probably the quickest (& most Windows-y) way to install OpenFOAM on your Windows box, but maybe not the easiest one to work with 🤔

Download a single file, right-click to install (install it as administrator to avoid problems), double-click the shiny OpenFOAM icon on your desktop & behold…a new terminal with all the usual OpenFOAM commands, plus a few helpful Linux ones.

As far as I can tell, you’re restricted to having all your simulation files live within the install directory. Maybe you can change this, or install it somewhere else? I’m not sure.

Also, you can’t compile code with this installation type & it’s only available for ESI/OpenCFD releases.

That said, the installation is easy-peasy 👍

Docker

I’m torn on this one 😕 I’m a big fan of Docker & I use it to run OpenFOAM on my Mac, but I wouldn’t bother with it on Windows (unless you have a custom Docker image &/or you use Docker on other machines).

The latest version of Docker Desktop uses the Windows Subsystem for Linux in the background, so you might as well just skip any Docker shenanigans & just use the WSL/Ubuntu method instead (IMHO).

Gotchas

There were a few things that caught me out, probably because I’m a Windows-noob, but I’ll note them here in case they get you too.

Where are my files?

You can find all the WSL/Ubuntu/OpenFOAM files by looking for the special Linux drive in Explorer (it should be at the bottom of the sidebar, with a penguin icon 🐧).

It was a bit trickier to find the files when I used the “Native” install, but if you type explorer . in the native version’s terminal then all is revealed.

VS Code Extension

If you use VS Code, then there’s a neat extension for working with WSL. It sets up VS Code so that the user interface runs in Windows whilst the backend runs in Linux.

You can still edit files as normal, but you’ll now be able to use OpenFOAM commands from the terminal within VS Code – neat.

ParaView

Don’t bother trying to run ParaView from inside WSL (or in Docker) just install ParaView for Windows & use that instead.

To open a case: use touch open.foam to create an empty .foam file in your case directory (or just save an empty file from your text editor) & read that straight into ParaView (you could even make .foam files open in ParaView by default & then you’d just have to double-click on them) 👍

Surprised, in a good way

I was prepared for this to be a bit of a nightmare, but I was more than surprised. It pains me to say it, but it’s easier to run OpenFOAM on Windows than it is on my Mac 🫢

The native install gets my award for being the quickest & easiest to install. Whilst the WSL is my overall winner for being easier to work with (although your mileage may vary if you’re new to Linux).

I’ve only been playing with this though, what’s your day-to-day experience running OpenFOAM in Windows?

For example, is the speed of OpenFOAM in WSL (or Docker, or the Native installation) acceptable? (All my testing was in a Windows 11 VM on my Mac, so 🐌).

I’m keen to hear your thoughts on anything OpenFOAM/Windows-related, you undoubtedly have more experience than me, so fill me in.

Until next week, stay safe,

Signed Robin K