Skip to content

Foundation OpenFOAM(R) and Homebrew

Alexey Matveichev edited this page Feb 9, 2024 · 1 revision

Foundation OpenFOAM(R) and Homebrew

Note 1

This guide assumes you've got Homebrew package manager installed. If it is not the case, install it following instructions at http://brew.sh.

Note 2

Text in the monospace font is commands you need to enter at the shell prompt. In the guide it is denoted as $ so if you copy-n-paste commands from the guide, you don't need to copy that character.

Note 3

<version> suffix, which is used in the guide, depends on the actual version, you are installing. Adapt the guide for your requirements.

Overview of the installation procedure is following:

$ brew install open-mpi metis scotch
$ cd $HOME
$ hdiutil create -size 64g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle
$ mkdir -p $HOME/OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle
$ cd $HOME/OpenFOAM
$ FOAM_VERSON=<version>; git clone https://github.com/OpenFOAM/OpenFOAM-{$FOAM_VERSION}.git
$ cd OpenFOAM-<version>
$ mkdir -p $HOME/.OpenFOAM
$ echo 'export WM_COMPILER=Clang' > $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_COMPILE_OPTION=Opt' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_MPLIB=SYSTEMOPENMPI' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_NCOMPPROCS=$(sysctl -n hw.ncpu)' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_LABEL_SIZE=32' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_QUIET=1' >> $HOME/.OpenFOAM/prefs.sh
$ source etc/bashrc
$ [ "$(ulimit -n)" -lt "8192" ] && ulimit -n 8192
$ ./Allwmake > log.Allwmake 2>&1

Third-party libraries

OpenFOAM(R) uses different third-party libraries to avoid reinventing a wheel. The list of possible libraries are following:

  • OpenMPI: for parallel communications.
  • METIS, Scotch: for mesh decomposition.
  • Zoltan: for mesh decomposition and mesh renumber.

Before version 11 OpenFOAM(R) also used CGAL and Boost, yet they were dropped due to problems on legacy systems. The patch set implements a functionality to automatically search for Brew and MacPorts libraries, so there is no need in additional configuration for third-party libraries.

Case-sensitive disk image

OpenFOAM(R) users case-sensitive file naming scheme, while MacOS is usually installed on case-insensitive volumes. To avoid name clashes (ex. OpenFOAM's Time.H and system time.h) user must create disk image or sub-volume with case-sensitive file system.

$ cd $HOME
$ hdiutil create -size 64g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle
$ mkdir -p $HOME/OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle
$ cd $HOME/OpenFOAM

Commands create disk image OpenFOAM.sparsebundle in user home folder ($HOME), create mount point for the disk, attaches the disk to the mount point, and goes in the freshly mounted folder.

If you prefer to use APF sub-volume, refer to corresponding wiki page.

Prepare sources

$ git clone https://github.com/OpenFOAM/OpenFOAM-<version>.git
$ cd OpenFOAM-<version>
$ curl -LO https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-<version>-<commit>.patch
$ git checkout <commit>
$ git apply OpenFOAM-<version>-<commit>.patch

You can still download tarball from http://dl.openfoam.org/source/<version>, yet, repository version includes bug fixes, which were introduced since release, so here I assume, that you get sources from git repository.

Since, git repository constantly envolves, patches contain two suffixes: OpenFOAM(R) version and SHA1 of the commit for which the patch is created.

With the commands above you clone repository, download patch, and apply the patch, so in the end you get sources ready for compilation. If you want to use newer source tree with older patch it worth to try applying older patch, usually it works for releases.

Prepare environment

Here I modify content of files with echo and sed. If you prefer, you can edit corresponding files by hand.

$ mkdir -p $HOME/.OpenFOAM
$ echo 'export WM_COMPILER=Clang' > $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_COMPILE_OPTION=Opt' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_MPLIB=SYSTEMOPENMPI' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_NCOMPPROCS=$(sysctl -n hw.ncpu)' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_LABEL_SIZE=32' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_QUIET=1' >> $HOME/.OpenFOAM/prefs.sh

Environment setup:

$ source etc/bashrc
$ [ "$(ulimit -n)" -lt "8192" ] && ulimit -n 8192

Compile

$ ./Allwmake > log.Allwmake 2>&1

Depending on your hardware and choosen options this can take from several minutes to several hours.

After compilation you can proceed to testing and making OpenFOAM(R) usage more convenient.