Skip to content

OpenFOAM(R) git version & Homebrew

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

Note 1

This guide assumes you've 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 from the guide, you don't need to copy that character.

<version> suffix, which is used in the guide, depends on actual version, you are installing. It could be just one digit; one digit and x; or two digits and x. Adapt guide for your requirements.

$ 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
$ cd
$ 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
$ git clone https://github.com/OpenFOAM/OpenFOAM-<version>.git
$ cd OpenFOAM-<version>
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-<version>-<commit>.patch > OpenFOAM-<version>-<commit>.patch
$ git checkout -b local-install <commit>
$ git apply OpenFOAM-<version>-<commit>.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
$ echo 'WM_LABEL_SIZE=32' >> $HOME/.OpenFOAM/prefs.sh
$ source etc/bashrc
$ [ "$(ulimit -n)" -lt "4096" ] && ulimit -n 4096
$ ./Allwmake > log.Allwmake 2>&1

So, basically installation process can be split into following parts

Install dependencies

Basic version just needs OpenMPI and Scotch libraries, 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/scotch
$ 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 after recent mess in Homebrew certain packages can go missing).

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

Checkout sources

$ cd OpenFOAM
$ git clone https://github.com/OpenFOAM/OpenFOAM-<version>.git

Sources will be checked out into OpenFOAM-<version> folder. Since checkout process creates source tree, this operation should be done on case-sensitive file system (i.e. which was first created on disk image and after mounter into $HOME/OpenFOAM).

Download patch

As the patch should be applied in OpenFOAM- folder, first change folder with cd and then download patch into this folder. Since git version source tree is constantly evolving, I have decided to add commit SHA1 to the patch file name, to keep information about the state of source tree for which patch was created. So in addition to substitution of <version>, you need to substitute commit part of the file name, i.e. for OpenFOAM-2.4.x-8685344.patch <version> is 2.4.x, and commit is 8685344.

$ cd OpenFOAM-<version>
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-<version>-<commit>.patch > OpenFOAM-<version>-<commit>.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. <commit> part in the commands below should be replaced with the number from the patch file name (like described in previous section).

$ git checkout -b local-install <commit>
$ git apply OpenFOAM-<version>-<commit>.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 with 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 'WM_LABEL_SIZE=32' >> $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

First five commands create preferences, 6th sets up environment variables, 7th increases maximum number of open files for a process, 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.