In this quick guide, we will show you how to install OpenFOAM 2.2.0 on Mac OS X 10.8.3, as known as Mountain Lion.

This post is only a repetition of awesome work by B. Gschaider, and the original link can be found here.


A. Prerequisite

First, we need to make sure we have all the required files before installing OpenFOAM.

1. Xcode | https://developer.apple.com/xcode/

  • Download the latest version of Xcode and Command Line Tools. You’re going to need an Apple ID, and probably need to register as a developer. We’re using Xcode 4.6.1, and Command Line Tools  (OS X Mountain Lion) for Xcode – March 2013

2. MacPorts | http://www.macports.org/

  • Download Macports for Mountain Lion, and installation should be very straightforward (.pkg file)


B. Compilers and Libraries

Gcc4.6, OpenMPI, flex, bison, boost, cgal, ccache
(there was a mistake when I recorded the video. It’s ccache, not cache)

Now you’re ready to use MacPorts to install compilers and libraries using MacPorts. Simply launch Terminal and enter following commands.

sudo port selfupdate
Check if we’re on the same page.
gcc --version
If it returns default GCC 4.2.1, you’ve installed Xcode correctly. Recent updates in OpenFOAM require GCC 4.5 or higher. We’ll use MacPorts to install GCC 4.6
sudo port install gcc46
Select Gcc 4.6 as default compiler by typing the following.
sudo port select gcc mp-gcc46

Check to see if you’re doing it correct so far.

>> gcc –version
gcc (MacPorts gcc46 4.6.3_9) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

Now install OpenMPI by typing
sudo port install openmpi

These two will take a while, so sit back, and try not to scare your computer. You can also install multiple tools using a single command. Try this line to install the remainder.
sudo port install flex bison boost cgal ccache


 C. OpenFOAM

Option 1 : Download precompiled sparseimage file.

1. Unzip, and double-click the .sparseimage file to mount
2. Create symbolic link on your home directory.
cd ~
ln -s /Volumes/OpenFOAM-v2.2 OpenFOAM

3. Edit your .profile to source ~/OpenFOAM/OpenFOAM-2.2.0/etc/bashrc when you start up Terminal
vi ~/.profile
Add this line…
source OpenFOAM/OpenFOAM-2.2.0/etc/bashrc
4. Clean and recompile OpenFOAM
cd ~/OpenFOAM/OpenFOAM-2.2.0


Option 2 : If it doesn’t work out of the box for some reason, carefully follow this instruction.


This post is not approved or endorsed by ESI Group.

There’s nothing new in this post. I want to redo the very first tutorial provided in OpenFOAM document (read this). It’s called lid-driven cavity flow, and the schematics are shown as below.

\relax \special {t4ht=

Let’s run the case first, and then see more details.

Running instructions

1. You can find this tutorial here.


Copy this whole folder to your running directory. For me, I copied it to ~/OpenFOAM/RUN/cavity.

On terminal,

cp -r ~/OpenFOAM/OpenFOAM-2.0.x/tutorials/incompressible/icoFoam/cavity ~/OpenFOAM/RUN
cd ~/OpenFOAM/RUN/cavity

2. Generate mesh using blockMesh



3. Run icoFoam



4. Once calculation is done, view the case in ParaView



And, it’s done. You may have to play with ParaView a bit to get used it, but here’s how pressure and velocity field look as below.

Most OpenFOAM cases have these following folders. 0, constant, and system. Let’s look at the expanded view.

By running blockMesh (Step 2), OpenFOAM will use ~/constant/polyMesh/blockMeshDict to create the mesh, and it will create/update faces, neighbour, owner, points according to the change. Users can change boundary settings at ~/constant/polyMesh/boundary to patch, wall, symmetry, empty, etc.. (learn more about boundaries). Boundary condition should be applied correctly in every fields in 0 folder (~/0/p and ~/0/U).

In system folder, controlDict defines overall setting for the case. This tutorial is running icoFoam, suitable for transient incompressible laminar  flow. See complete list of OpenFOAM standard solvers here.

icoFoam uses PISO algorithm to solve incompressible Navier-Stokes equations.

Here’s output from icoFoam

Shaun-Kims-MacBook-Pro:cavity shkim$ icoFoam
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.0.x                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
Build  : 2.0.x-931a91d59a3a
Exec   : icoFoam
Date   : Nov 07 2011
Time   : 00:26:30
Host   : Shaun-Kims-MacBook-Pro.local
PID    : 14048
Case   : /Volumes/Mac-OF-2.0.x/RUN/cavity
nProcs : 1
sigFpe : Floating point exception trapping - not supported on this platform
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading transportProperties

Reading field p

Reading field U

Reading/calculating face flux field phi

Starting time loop

Time = 0.005

Courant Number mean: 0 max: 0
DILUPBiCG:  Solving for Ux, Initial residual = 1, Final residual = 2.96338e-06, No Iterations 8
DILUPBiCG:  Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DICPCG:  Solving for p, Initial residual = 1, Final residual = 7.55402e-07, No Iterations 35
time step continuity errors : sum local = 5.03809e-09, global = 4.40722e-19, cumulative = 4.40722e-19
DICPCG:  Solving for p, Initial residual = 0.523591, Final residual = 9.72352e-07, No Iterations 34
time step continuity errors : sum local = 1.07766e-08, global = 2.93897e-19, cumulative = 7.34619e-19
ExecutionTime = 0.03 s  ClockTime = 0 s

Time = 0.01

Courant Number mean: 0.0976805 max: 0.585722
DILUPBiCG:  Solving for Ux, Initial residual = 0.148584, Final residual = 7.15711e-06, No Iterations 6
DILUPBiCG:  Solving for Uy, Initial residual = 0.256618, Final residual = 8.94127e-06, No Iterations 6
DICPCG:  Solving for p, Initial residual = 0.379232, Final residual = 3.38648e-07, No Iterations 34
time step continuity errors : sum local = 3.15698e-09, global = 1.94222e-19, cumulative = 9.28841e-19
DICPCG:  Solving for p, Initial residual = 0.286937, Final residual = 5.99637e-07, No Iterations 33
time step continuity errors : sum local = 6.08774e-09, global = 5.80474e-19, cumulative = 1.50932e-18
ExecutionTime = 0.03 s  ClockTime = 0 s
Time = 0.5

Courant Number mean: 0.222158 max: 0.852134
DILUPBiCG:  Solving for Ux, Initial residual = 1.89493e-07, Final residual = 1.89493e-07, No Iterations 0
DILUPBiCG:  Solving for Uy, Initial residual = 4.14522e-07, Final residual = 4.14522e-07, No Iterations 0
DICPCG:  Solving for p, Initial residual = 1.06665e-06, Final residual = 3.39604e-07, No Iterations 1
time step continuity errors : sum local = 5.25344e-09, global = -9.50761e-19, cumulative = 8.05678e-18
DICPCG:  Solving for p, Initial residual = 5.36118e-07, Final residual = 5.36118e-07, No Iterations 0
time step continuity errors : sum local = 6.86432e-09, global = 4.62063e-19, cumulative = 8.51884e-18
ExecutionTime = 0.22 s  ClockTime = 0 s


If you want to keep the log instead of printing out on the terminal, run icoFoam as following.

icoFoam > log

It’s very useful to keep the log because it let you plot residuals using tools like foamGraphResUVWP .

# Update on April 2013
New post about OpenFOAM 2.2 on Mac OS X Snow Lion

# Now back to the original post…

As of today, the latest OpenFOAM available is OpenFOAM-2.0.1. I am going to walk through installing it on my Macbook Pro (2.4 Ghz Intel Core 2 Duo). Installing open-source code can be a hassle since hardware/specification varies a lot. But it’s a price to pay, but you can google whenever you encounter a problem. You may find this forum (cfd-online) very useful. I listed

1. Update your OS X to the most recent version. I paid $29.99 for the new OS X Lion (10.7.1) from App Store. (~6 hrs)

2. Go to App Store, and download and install Xcode 4.1 . It’s free, but you have to register as a developer. (~3 hrs)

3. Install Macports for Lion. Simply follow the link and click on Lion to download dmg file. (< 5min)

4. Now you’re ready to install gcc 4.5.3. Open Terminal or X11, and type as followed

>> sudo port install gcc45

It will take a while. (~3 hrs?)

5. Mac OS X 10.7 does NOT come with OpenMPI, so you need to install it. On Terminal, type

>> sudo port install openmpi +gcc45

6. Now we’re ready to install OpenFOAM. Here’s the link for OpenFOAM disk image file for Mac. Download ‘README’ and ‘Mac-OF-2.0.x.sparseimage.zip’.

7. Extract Mac-OF-2.0.x.sparseimage.zip, and mount the image by double clicking.

8. Now, follow the instruction on ‘README’… I’m just going to narrate it here as well. Open Terminal and type..

>> cd ~

>> ln -sf /Volumes/Mac-OF-2.0.x OpenFOAM

>> cd OpenFOAM

>> ln -sf ~/Documents/OF-User ‘whoami’-2.0.x

>> cd ~

>> vi .profile

and add this line

. ~/OpenFOAM/OpenFOAM-2.0.x/etc/bashrc

Quit and restart Terminal…

9. Change the OpenMPI setting…

>>vi ~/OpenFOAM/site/2.0.x/prefs.sh



10. It’s a good idea to recompile it from the beginning.

>> cd ~/OpenFOAM/OpenFOAM-2.0.x


…. this will clear everything up


…. this will take a while…


After few hours of wait, OpenFOAM is finally ready to use. Test drive it by doing one of the tutorials.