OpenFOAM installation instructions

From CUSF Wiki
Revision as of 20:16, 25 January 2022 by NikLebedenko (talk | contribs) (Created the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Important: These instructions only work for Ubuntu or Windows 10 and above.

MacOS: If you intend to use OpenFOAM for fluid-structure interaction (FSI) simulations, install an Ubuntu virtual machine. Otherwise, use a Docker image for higher performance.

Install ParaView

If you wish to view the results of the simulations, the best way to do this is with ParaView.

Simply download the executable for your operating system 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.

Windows 10: 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 with CTRL+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> the file you wish to open.

Windows 10 and above: Install Ubuntu

I recommend installing Windows Subsystem for Linux instead of setting up a dual-boot partition (use WSL1, discussion of WSL2 below).

  • 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.
    • If you want to use WSL2 anyway, I recommend you install ParaView on Ubuntu to avoid reading between file systems. You must also install XMing to view the GUI. See this page and this page for further information.

Install OpenFOAM on Ubuntu

OpenFOAM is an open-source Computational Fluid Dynamics (CFD) package. We will use it to simulate the fluid (air) flow.

The Ubuntu installation instructions as of 31/12/2021 are summarised below (adapted from this website):

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:

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