Skip to content

OpenFOAM(R) release & Homebrew

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

Note 1

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

Note 2

Text in 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, you do not need to copy that character.

Version notation depends on itself. The latest is just single-digit, before it was two/three digits (or one/twodigits and x). Adapt commands according to your requirements.

$ brew install open-mpi
$ brew install boost
$ brew install cgal
$ brew install metis
$ brew install libomp
$ brew tap mrklein/foam
$ brew install mrklein/foam/scotch
$ brew install mrklein/foam/parmgridgen
$ cd $HOME
$ curl -L http://dl.openfoam.org/source/<version> > OpenFOAM-<version>.tgz
$ hdiutil create -size 8.3g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle
$ mkdir -p OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle
$ cd OpenFOAM
$ tar xzf $HOME/OpenFOAM-<version>.tgz
$ [ -d OpenFOAM-<version>-version-<version> ] && mv OpenFOAM-<version>-version-<version> OpenFOAM-<version>  # if you are installing new versions
$ cd OpenFOAM-<version>
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-<version>.patch > OpenFOAM-<version>.patch
$ git apply OpenFOAM-<version>.patch
$ mkdir -p $HOME/.OpenFOAM
$ echo 'WM_COMPILER=Clang' > $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_COMPILE_OPTION=Opt' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_MPLIB=SYSTEMOPENMPI' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_NCOMPPROCS=$(sysctl -n hw.ncpu)' >> $HOME/.OpenFOAM/prefs.sh
$ source etc/bashrc
$ [ "$(ulimit -n)" -lt "4096" ] && ulimit -n 4096
$ ./Allwmake > log.Allwmake 2>&1

Basically installation process can be split into following parts

Install dependencies

Basic version just needs OpenMPI; Scotch and METIS libraries are used for parallel decomposition; for certain operations on surfaces CGAL is needed. To install these dependencies the following commands are executed:

$ brew install open-mpi
$ brew install boost
$ brew install cgal
$ brew install metis
$ brew tap mrklein/foam
$ brew install mrklein/foam/scotch
$ brew install mrklein/foam/parmgridgen

Note, as Homebrew is constantly updated, certain installation flags can stop working, consult brew info <package> for valid ones. Also if you do not need certain functionality, which depends on external libraries, you can skip installation of these packages. For example, if you prefer METIS decomposition, do not install Scotch.

Download sources

As release sources come packed in tarballs one can safely download them to case insensitive file system with

$ curl -L http://dl.openfoam.org/source/<version> > OpenFOAM-<version>.tgz

Create disk image

IIRC there is a guide on openfoamwiki.net on how to create disk image with Disk utility. I think this way is long and error-prone, so I prefer to create images with CLI interface:

$ hdiutil create -size 8.3g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle

Size key specifies size of the image, as usually I keep all OpenFOAM versions on one image, the size is rather large but as it is sparse image, its size will grow as necessary (for example size of disk image with 6 different OpenFOAM versions is around 6G). Type of the disk image is Sparse bundle as it is more convenient for backup software. Volume name is OpenFOAM, you can change it to anything you like. File system type is set with -fs flag, in the command it is just extended HFS, if you'd like, you can add J letter there to get journaling. And finally -fsargs -s supply -s option to newfs utility that forces it to create case sensitive file system.

Mount disk image

First mount point is created with mkdir command and then disk image mounted to the newly created mount point:

$ mkdir -p OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle

Extract sources

The source tar-ball is extracted to the case-sensitive file system:

$ cd OpenFOAM
$ tar xzf ~/OpenFOAM-<version>.tgz
$ [ -d OpenFOAM-<version>-version-<version> ] && mv OpenFOAM-<version>-version-<version> OpenFOAM-4.0  # you need this as newer packing scheme is a little bit different

Sources are now in OpenFOAM-<version> folder.

Download patch

As the patch should be applied in OpenFOAM- folder, first change folder with cd and the download patch into this folder.

$ cd OpenFOAM-<version>
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-<version>.patch > OpenFOAM-<version>.patch

Apply patch

Patch is applied with git command. One of the advantages of this way of patch application is git's ability to set necessary FS flags on the files.

$ git apply OpenFOAM-<versino>.patch

Build OpenFOAM(R)

Before you start build of OpenFOAM(R), you need to correct certain settings in accordance to your environment. Earlier in this guide I have suggested editing etc/bashrc file, yet it is much easier to have preference file ~/.OpenFOAM/prefs.sh instead. If you already have this file, skip the part witch echos.

$ mkdir -p $HOME/.OpenFOAM
$ echo 'WM_COMPILER=Clang' > $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_COMPILE_OPTION=Opt' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_MPLIB=SYSTEMOPENMPI' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_NCOMPPROCS=$(sysctl -n hw.ncpu)' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_LABEL_SIZE=32' >> $HOME/.OpenFOAM/prefs.sh
$ source etc/bashrc
$ [ "$(ulimit -n)" -lt "4096" ] && ulimit -n 4096
$ ./Allwmake > log.Allwmake 2>&1

First five commands create preferences, 6th sets up environment variables, 7th increases maximum number of open file for a process, which is necessary for certain lnInclude folders, and finally last command starts build process. Build output goes to log.Allwmake file. So if anything goes wrong, this file should be checked for the error.

Setting WM_NCOMPPROC environment variable instructs wmake to execute build in parallel. This can significantly accelerate the process.

Time necessary for build depends on the processor and hard drive of your Mac. For my Core i5 2.3 GHz it's around 2 hours.

After the build is finished you can test your installation (if every things seems to be OK, you can delete log.Allwmake file) and add convenience bits to your ~/.profile.