Difference between revisions of "OpenFOAM installation instructions"
NikLebedenko (talk | contribs) m (→Install ParaView: clarified things) |
NikLebedenko (talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The Windows installation instructions are also available in [https://www.youtube.com/watch?v=n2iDOBe4h5A&ab_channel=NikL video format] | |||
'''Important''': These instructions only work for Ubuntu or Windows 10 and above. | '''Important''': These instructions only work for Ubuntu or Windows 10 and above. | ||
Line 24: | Line 24: | ||
* Click "OK" on all the dialogue boxes. | * Click "OK" on all the dialogue boxes. | ||
You can now open files in ParaView from the command line with <code>paraview.exe <file></code>, replacing <code><file></code> the file you wish to open. | You can now open files in ParaView from the command line with <code>paraview.exe <file></code>, replacing <code><file></code> with the file you wish to open. | ||
=== Ubuntu: === | === Ubuntu: === | ||
Simply run this command:<syntaxhighlight lang="bash"> | Simply run this command:<syntaxhighlight lang="bash"> | ||
sudo apt-get install paraview | sudo apt-get install paraview | ||
</syntaxhighlight>You can now open files in ParaView from the command line with <code>paraview <file></code>, replacing <code><file></code> the file you wish to open. | </syntaxhighlight>You can now open files in ParaView from the command line with <code>paraview <file></code>, replacing <code><file></code> with the file you wish to open. | ||
==Windows 10 and above: Install Ubuntu== | ==Windows 10 and above: Install WSL Ubuntu== | ||
Install [https://docs.microsoft.com/en-us/windows/wsl/install-manual Windows Subsystem for Linux] version 1 (WSL1, not WSL2). | |||
If you have never used a command line on Linux (or related systems), then the first 10 minutes of [https://www.youtube.com/watch?v=s3ii48qYBxA&ab_channel=DistroTube this video] might be helpful. The whole video is great, but the first 10 minutes are the absolute essentials. | |||
====== ''WSL Version comparison (optional):'' ====== | ====== ''WSL Version comparison (optional):'' ====== | ||
Line 40: | Line 42: | ||
**''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 [https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2 this page] and [https://newbedev.com/how-to-set-up-working-x11-forwarding-on-wsl2 this page] for further information.'' | **''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 [https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2 this page] and [https://newbedev.com/how-to-set-up-working-x11-forwarding-on-wsl2 this page] for further information.'' | ||
==Install OpenFOAM on Ubuntu== | ==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. | 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 [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 | 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>, navigate to the bottom of the file with the arrow keys, and type the line in. <syntaxhighlight lang="bash"> | ||
source /usr/lib/openfoam/openfoam2112/etc/bashrc | source /usr/lib/openfoam/openfoam2112/etc/bashrc | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Remember that <code>^X</code> which is <code>CTRL+X</code> exits nano. <code>^</code> is short for the <code>CTRL</code> button. Make sure to type <code>Y</code> on the prompt <code>Save modified buffer?</code> after pressing <code>CTRL+X</code> | |||
Restart Ubuntu. Now check the installation completed correctly by running a tutorial case:<syntaxhighlight lang="bash"> | Restart Ubuntu. Now check the installation completed correctly by running a tutorial case:<syntaxhighlight lang="bash"> | ||
cd ~ | cd ~ | ||
Line 57: | Line 66: | ||
blockMesh > log.blockMesh | blockMesh > log.blockMesh | ||
icoFoam > log.icoFoam | icoFoam > log.icoFoam | ||
</syntaxhighlight> | touch foam.foam | ||
</syntaxhighlight>You can now view the results in ParaView: | |||
* WSL Ubuntu: <code>paraview.exe foam.foam</code> | |||
* Native Ubuntu: <code>paraview foam.foam</code> |
Latest revision as of 23:36, 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 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).
If you have never used a command line on Linux (or related systems), then the first 10 minutes of this video might be helpful. The whole video is great, but the first 10 minutes are the absolute essentials.
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.
source /usr/lib/openfoam/openfoam2112/etc/bashrc
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
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