OpenFOAM installation instructions
The Windows installation instructions are also available in video format
Important: These instructions only work for Ubuntu or Windows 10 and above.
MacOS: Please see these instructions on using a Docker image to install OpenFOAM. An Ubuntu VM on Mac will not work with these instructions.
Install and Use ParaView
If you wish to view the results of the simulations, the best way to do this is with ParaView.
Windows 10 and above:
Simply download the executable for Windows 10 from this website.
The same website also hosts excellent tutorials and documentation PDFs - these should be your first resource when learning how to use ParaView.
In order to run ParaView from the command line, you must add paraview.exe
to Path:
- Find the folder containing your
paraview.exe
executable, and copy the folder's location (not the file's location) to your clipboard withCTRL+C
. - In the search bar, type "Edit the system environment variables" and click the first option.
- Click the box labelled "Environment Variables..." in the lower right corner.
- A dialogue box appears. In the lower half labelled "System Variables", scroll to the variable "Path"
- Double click on the "Path" variable.
- Click "New"
- Paste the folder path you copied earlier into the text box that is now selected.
- Click "OK" on all the dialogue boxes.
You can now open files in ParaView from the command line with paraview.exe <file>
, replacing <file>
with the file you wish to open.
Ubuntu:
Simply run this command:
sudo apt-get install paraview
You can now open files in ParaView from the command line with paraview <file>
, replacing <file>
with the file you wish to open.
Windows 10 and above: Install WSL Ubuntu
Install Windows Subsystem for Linux version 1 (WSL1, not WSL2)
WSL Version comparison (optional):
- WSL1 Pros: fairly fast read/write in both Ubuntu and Windows file systems. Cons: much slower at read/write in Ubuntu file system than WSL2.
- WSL2 Pros: lightning fast read/write in Ubuntu. Cons: very slow read/write when moving data between Ubuntu and Windows.
- Summary: Use WSL1 if you have a Windows-based ParaView or another app that will read lots of data between file systems.
Install OpenFOAM on Native Ubuntu or WSL Ubuntu
OpenFOAM is an open-source Computational Fluid Dynamics (CFD) package. We will use it to simulate the fluid (air) flow.
The Ubuntu (Native or WSL) installation instructions as of 31/12/2021 are summarised below (adapted from this website)
First, update the package index and upgrade the packages.
sudo apt update
sudo apt upgrade
If the first command fails with an error message that looks like Certificate validation failed: The certificate is NOT trusted
... N: Updating from such a repository can't be done securely...
then run sudo apt upgrade
anyway, and re-run sudo apt update
, followed by sudo apt upgrade
curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash
sudo apt-get install openfoam2112-default
Append the following line to your ~/.bashrc
file, if not already present. If you don't know how to do this, run nano ~/.bashrc
, navigate to the bottom of the file with the arrow keys, and type the line in.
Remember that ^X
which is CTRL+X
exits nano. ^
is short for the CTRL
button. Make sure to type Y
on the prompt Save modified buffer?
after pressing CTRL+X
source /usr/lib/openfoam/openfoam2112/etc/bashrc
Restart Ubuntu. Now check the installation completed correctly by running a tutorial case:
cd ~
mkdir -p OpenFOAM-sims/tutorials
cp -r $FOAM_TUTORIALS/incompressible OpenFOAM-sims/tutorials
cd OpenFOAM-sims/tutorials/incompressible/icoFoam/cavity/cavity/
blockMesh > log.blockMesh
icoFoam > log.icoFoam
touch foam.foam
You can now view the results in ParaView:
- WSL Ubuntu:
paraview.exe foam.foam
- Native Ubuntu:
paraview foam.foam