Lecture 2. Settings Things Up
2.1 Installation Options
As mentioned in Lecture 1, OpenFOAM is being developed under the Linux operating system and it works under Linux. To use it, we either need to use a Linux machine or create a Linux-like environment under Windows or macOS.Linux: If you already have a Linux machine, your options to use OpenFOAM are
- You can download and install the OpenFOAM package prepared for your Linux distribution, which is the easiest way. OpenCFD provides packages for popular Linux distributions such as Ubuntu, OpenSUSE and Redhat. CFD Direct provides only an Ubuntu package. This is the easiest and recommended option for installing OpenFOAM on Linux.
- If you want to use a version of OpenFOAM on a Linux distribution for which no package is provided (such as using CFD Direct's version on OpenSUSE) you can go with the Docker option or you can download the source files from the code repositories and compile them on your own.
Windows:You can use OpenFOAM on a Windows machine in a number of different ways.
- Windows Subsystem for Linux (WSL): First you install WSL, then install a Linux distribution such as Ubuntu inside it, and then install OpenFOAM inside Linux. This is the most preferred way of using OpenFOAM under Windows nowadays.
- VirtualBox:This is a free virtualization software. It allows you install an operating system inside another. You can create a virtual Linux environment inside your Windows machine, and in it you can do whatever you do with a native Linux installation.
- Docker: This technology creates a "container" for the working environment you want (for us Linux + OpenFOAM and other necessary tools) inside your non-Linux computer. OpenCFD and CFD Direct provide Docker images on their web sites.
- Preconfigured Packages for Windows: I know of 3 different companies supplying preconfigured OpenFOAM packages for Windows; OpenCFD, blueCFDCore and CFD Support. You simply download an executable and run it as if you are installing any other software in Windows. A linux like environment will be created using technologies such as MSYS2 or Cygwin, with OpenFOAM and possibly some other useful tools already installed inside. In my opinion, this is the easiest option for using OpenFOAM under Windows.
2.2 Linux Terminal
To use OpenFOAM you need to know the basics of how to use the terminal, also known as the "command line" or the "shell". If you are total Linux newbie, you may get help from several tutorials on the net, such as this video series from Jozsef Nagy. Actually Jozsef's channel is popular for OpenFOAM tutorials, but these Linux related ones are also good. Have a look at them. You may also find Learning the Shell or Beginner's Guide to the Bash Terminal useful. I'll share below a short list of the most commonly used commands,> cd to change directory (folder)
> ls to list the files and folders inside the current folder
> pwd to print the name of the working (current) directory
> mkdir to make (create) a new directory
> mv to move a file or folder to a different location
> cp to copy files and folders
> rm to remove (delete) files and folders
> nano to start a simple editor to edit text files
> clear to clear the command window
> Up arrow to access previosuly used commands
> TAB to perform TAB completion
2.3 Folders and Files that Come with OpenFOAM
Some of the important folders and files that come with an OpenFOAM installation are (may vary depending on which version of openFOAM you are using and how you installed it)- COPYING: This file has the GLPv3 license with which OpenFOAM is distributed. Long and not very fun to read. But have a look at it if you've never read an open-source license before.
- doc/Guides: You will see the User Guide as a PDF here. It is the official OpenFOAM documentation with a few hundred pages. Newer versions of the OpenCFD release do not have this, but have an online User Guide instead.
- src: This folder has tons of C++ source files. You do not need to bother with this folder if you are going to use OpenFOAM "as it is". But you need to dive into it if you want to make code modifications to implement new features or modify the existing ones.
- applications: This folder contains the C++ source files used to built the default applications (solvers and utilities). Again you do not need to bother with this if you are not going to make any code development.
- platforms: This folder has the executables for the built-in solvers and utilities. You'll be running these from the command line when you're setting up and solving problems. For example, blockMesh is used to create block-structured meshes or simpleFoam is used to solve incompressible flows.
- tutorials: This folder has several sample problems that are ready to be solved. They are grouped into different folders, such as incompressible, compressible, multiphase, etc. There are also samples for mesh generation. These are important because we can learn a lot by studying their files and solving these problems. Also, typically what we do to solve a new problem is to find a similar problem in this folder, copy its files to a new folder and edit the files according to our needs. This is usually easier than creating everything from scratch. Although this directory is called tutorials, actually what we have here are just ready to use files to solve problems, but not detailed explanations of those files or step-by-step instructions of how to use them. OpenFOAM users created such tutorials on their own and shared them as videos on the net. You can find several ofthem for the popular problems such as the one at /incompressible/icoFoam/elbow that solves the flow through a pipe elbow, or the one at /incompressible/simpleFoam/motorbike that solves the flow over a motorbike.
2.4 Environment Variables Set by OpenFOAM
Running the following command inside a terminal, you will see a list of all the environment variables set in your Linux system.> env
These are simply shortcut definitions that are easy to remember for things that are hard to remember and type. The ones that start with FOAM_ are set by OpenFOAM. You will see some of them used in OpenFOAM documentations and tutorials, such as the following oneFOAM_TUTORIALS=/home/ofuser/OpenFOAM/OpenFOAM-v2506/tutorials
which is a variable that points to the folder where OpenFOAM tutorials are stored. We use these environment variables by putting a $ sign in front of them, such as the following command which changes the working directory in a terminal window to OpenFOAM's tutorials directory.
> cd $FOAM_TUTORIALS
or the following one which first creates a directory named courseWork inside our home directory and then copies a tutorial folder to there> mkdir ~/courseWork
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity ~/courseWork
> echo $FOAM_UTILITIES
which on my machine shows /home/ofuser/OpenFOAM/OpenFOAM-v2506/applications/utilities. Nothing will be shown on the screen if the variable is not defined. You can use the life saver "tab completion" feature of the terminal by typing "echo $FOAM" and press the Tab key three times. All the environment variables whose name start with $FOAM will be shown. We use this "tab completion" trick all the time for all sorts of things when we work in a terminal.