FOAMY Lectures

CFD Lectures with OpenFOAM

by Dr. Cuneyt Sert

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 macOS: If you are a Mac user, then you can go with the Docker option, Canonical Multipass option or install using the source files.


Windows:You can use OpenFOAM on a Windows machine in a number of different ways.

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

When we simply type "cd" it takes us to our home folder. Same is achieved by typing "cd ~", where tilda is a shortcut for our home directory. Typing "cd .." takes us to one folder up. Typing "cd ../.." goes up two folders.

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)

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 one

    FOAM_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

When you see an OpenFOAM related environment variable used in a documentation and wonder if it is defined in your system or not, or want to see what its value is, use the echo command as follows.

> 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.

< Previous Lecture    TOC    Next Lecture >