Difference between revisions of "OpenFOAM installation instructions"

From CUSF Wiki
Jump to navigation Jump to search
m
(Added fix for common bug)
Line 32: Line 32:


==Windows 10 and above: Install WSL Ubuntu==
==Windows 10 and above: Install WSL Ubuntu==
I recommend installing [https://docs.microsoft.com/en-us/windows/wsl/install-manual Windows Subsystem for Linux] instead of setting up a dual-boot partition (use WSL1, discussion of WSL2 below).
Install [https://docs.microsoft.com/en-us/windows/wsl/install-manual Windows Subsystem for Linux] version 1 (WSL1, not WSL2)  


====== ''WSL Version comparison (optional):'' ======
====== ''WSL Version comparison (optional):'' ======
Line 43: Line 43:
OpenFOAM is an open-source Computational Fluid Dynamics (CFD) package. We will use it to simulate the fluid (air) flow.
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 [https://develop.openfoam.com/Development/openfoam/-/wikis/precompiled/debian this website]):<syntaxhighlight lang="bash">
The Ubuntu (Native or WSL) installation instructions as of 31/12/2021 are summarised below (adapted from [https://develop.openfoam.com/Development/openfoam/-/wikis/precompiled/debian this website])
 
First, update the package index and upgrade the packages.<syntaxhighlight lang="bash">
sudo apt update
sudo apt upgrade
</syntaxhighlight>If the first command fails with an error message that looks like <code>Certificate validation failed: The certificate is NOT trusted</code> ... <code>N: Updating from such a repository can't be done securely...</code> then run <code>sudo apt upgrade</code> anyway, and re-run <code>sudo apt update</code>, followed by <code>sudo apt upgrade</code><syntaxhighlight lang="bash">
curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash
curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash
sudo apt-get install openfoam2112-default
sudo apt-get install openfoam2112-default
</syntaxhighlight>  
</syntaxhighlight>  
Append the following line to your <code>~/.bashrc</code> file, if not already present:<syntaxhighlight lang="bash">
Append the following line to your <code>~/.bashrc</code> file, if not already present. If you don't know how to do this, run <code>nano ~/.bashrc</code>, remembering that <code>^X</code> which is <code>CTRL+X</code> exits nano. <code>^</code> is short for the <code>CTRL</code> button.<syntaxhighlight lang="bash">
source /usr/lib/openfoam/openfoam2112/etc/bashrc
source /usr/lib/openfoam/openfoam2112/etc/bashrc
</syntaxhighlight>
</syntaxhighlight>

Revision as of 23:20, 1 February 2022

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 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> 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.
    • 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 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, remembering that ^X which is CTRL+X exits nano. ^ is short for the CTRL button.

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