/OpenFOAM-AppleM1

GNU General Public License v3.0GPL-3.0

OpenFOAM-AppleM1

Patch to compile OpenFOAM-v2306 on M1 Mac.

OpenFOAM-v2306

Procedures

  1. Install these dependencies from homebrew
brew install cmake open-mpi libomp adios2 boost cgal fftw kahip metis petsc hypre
  1. Install legacy Scotch (Thanks to @gerlero for creating this tap)
brew tap gerlero/openfoam
brew install scotch-no-pthread
  1. Create a case-sensitive APFS volume like this

I usually create a soft link to keep everything consistent with Linux.

ln -s /Volumes/OpenFOAM ~/OpenFOAM
  1. Clone the OpenFOAM source code into this volume
cd ~/OpenFOAM
git clone https://develop.openfoam.com/Development/openfoam.git OpenFOAM-v2306
cd OpenFOAM-v2306
git checkout OpenFOAM-v2306

Optional: adding submodules such as petsc4Foam

git submodule init
git submodule update
  1. Apply my patch for M1.
curl -OL https://github.com/BrushXue/OpenFOAM-AppleM1/raw/main/M1.patch
git apply M1.patch
  1. Add OpenFOAM to .zshrc or .bashrc(if you wish)
echo 'source ~/OpenFOAM/OpenFOAM-v2306/etc/bashrc' >> ~/.zshrc

Important: you need to add the following for M1 (but not for x86):

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib
  1. Compile the code
./Allwmake -j -s -l

It takes 40~45 minutes on M1.

Optional: you may add -with-bear option after installing bear.

See https://openfoamwiki.net/index.php/HowTo_Use_OpenFOAM_with_Visual_Studio_Code for more information

Optional: Install paraview from Homebrew

brew install --cask paraview

Known issue

Currently on Apple Silicon, floating point exception will trap SIGILL instead of SIGFPE. It is known that Asahi Linux can correctly trap SIGFPE so the problem is from macOS or XCode. The workaround is to use SIGILL for now. If you don't like this workaround, please submit a bug report to Apple (but don't expect they'll fix it).

It is suggested to run the following parallel command in scripts to avoid macOS restrictions.

. $WM_PROJECT_DIR/bin/tools/RunFunctions
runParallel ***Foam

swak4Foam

Procedures

  1. Install these dependencies from homebrew:
brew install mercurial bison pkgconfig
  1. Download swak4Foam
hg clone http://hg.code.sf.net/p/openfoam-extend/swak4Foam swak4Foam
cd swak4Foam
hg update develop
  1. Apply my patch for macOS.
curl -OL https://github.com/BrushXue/OpenFOAM-AppleM1/raw/main/swak4Foam.patch
git apply swak4Foam.patch
  1. Important: add bison to PATH:
export PATH="$(brew --prefix)/opt/bison/bin:$PATH"
  1. Compile the code.
export WM_NCOMPPROCS=$(sysctl -n hw.ncpu)
./AllwmakeAll

It takes approximately 6 minutes on M1.

Known issue

python 2.7 is removed in macOS 12.3+. Therefore funkyPythonPostproc is disabled.

Benchmark

The benchmark is modified from https://www.cfd-online.com/Forums/hardware/198378-openfoam-benchmarks-various-hardware.html