jeudi 20 février 2014

Building OpenFOAM 2.3.0 on OS X

NB! Updated version of the guide can be found in the post Building OpenFOAM on OS X

Recently OpenFOAM Foundation announced release of OpenFOAM 2.3.0. So I've decided to make patches to build this version with Clang.

Notes:
  1. Build process was tested on OS X 10.9 with Clang version: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  2. In this version CGAL library appeared which depends on boost, gmpmpfr, and cmake. I use Homebrew as a package manager so patches assume that boost, gmp, and mpfr are installed with brew. Basically I use this package manager to get installation prefixes for the libraries.
  3. I have multi-threaded build of boost intalled (--without-single option of the package) so build was tested with this version (i.e. libraries have -mt suffix). If you have single threaded libraries installed makeCGAL script will try to adjust build options, though this wasn't tested.
  4. Paraview is downloaded from paraview.org and installed in /Applications
Instruction is rather similar to the previous one:
  1. Download OpenFOAM sources from openfoam.org: OpenFOAM-2.3.0.tgz and ThirdParty-2.3.0.tgz
  2. Download patches: OpenFOAM-2.3.0-2.patch and ThirdParty-2.3.0-1.patch
  3. Create disk image with CASE SENSITIVE file system. One can find instructions with pictures in OpenFOAM wiki.
  4. Mount created disk image to $HOME/OpenFOAM (for example, it can be done with command hdiutil attach -quiet -mountpoint $HOME/OpenFOAM <your disk image file>).
  5. Unpack source archives to $HOME/OpenFOAM (if you downloaded files elsewhere, correct paths to archives)
    $ cd $HOME/OpenFOAM
    $ tar xzf ~/Downloads/OpenFOAM-2.3.0.tgz
    $ tar xzf ~/Downloads/ThirdParty-2.3.0.tgz
  6. Copy patches into correspondent directories:
    $ cp ~/Downloads/OpenFOAM-2.3.0-2.patch OpenFOAM-2.3.0/
    $ cp ~/Downloads/ThirdParty-2.3.0-1.patch ThirdParty-2.3.0/
  7. Apply patches with git apply command. I prefer using git (instead of patch) for this because git will get permissions on created files (for example addr2line4Mac.py will be created as an executable).
    $ cd OpenFOAM-2.3.0
    $ git apply OpenFOAM-2.3.0-2.patch
    $ cd ../ThirdParty-2.3.0
    $ git apply ThirdParty-2.3.0-1.patch
    $ cd ../OpenFOAM-2.3.0
  8. Edit etc/bashrc to correspond to your system and desires. Major changes that can be done are:
    • Change export WM_MPLIB=SYSTEMOPENMPI to export WM_MPLIB=OPENMPI if you'd like to use OpenMPI from ThirdParty source distribution (version 1.6.5). I use Homebrew installed OpenMPI 1.7.4.
    • Remove verbosity by changing export FOAM_VERBOSE=1 to export FOAM_VERBOSE=0
  9. Source etc/bachrc
  10. Execute ./Allwmake
  11. Wait.
Build process will take some time, after you can test installation with traditional:
$ mkdir -p $FOAM_RUN 
$ run
$ cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
$ cd cavity
$ blockMesh
$ icoFoam


To mount disk image automatically upon every launch of terminal you can add something like:

# OpenFOAM
if [ -f $HOME/.OpenFOAM-release ]; then
OF_VER=$(cat $HOME/.OpenFOAM-release)
if [ ! -f $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc ]; then
hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM-$OF_VER.sparsebundle &&
. $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
else
. $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
fi
fi

to .profile file and create .OpenFOAM-release file with

$ echo '2.3.0' > $HOME/.OpenFOAM-release

This snippet assumes that you've names your disk image OpenFOAM-2.3.0.sparsebundle.

That's it.

3 commentaires:

  1. I get the following error: ./Allwmake: line 4: wmakeCheckPwd: command not found
    Error: Current directory is not $WM_PROJECT_DIR
    The environment variables are inconsistent with the installation.
    Check the OpenFOAM entries in your dot-files and source them.

    export WM_PROJECT=OpenFOAM
    export WM_PROJECT_VERSION=2.3.0

    ################################################################################
    # USER EDITABLE PART: Changes made here may be lost with the next upgrade
    #
    # either set $FOAM_INST_DIR before sourcing this file or set
    # 'foamInstall' below to where OpenFOAM is installed
    #
    # Location of the OpenFOAM installation
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    foamInstall=$HOME/OpenFOAM/OpenFOAM-2.3.0
    # foamInstall=~$WM_PROJECT
    # foamInstall=/opt/$WM_PROJECT
    #foamInstall=/usr/local/OpenFOAM/OpenFOAM-2.3.0
    #
    # END OF (NORMAL) USER EDITABLE PART
    ################################################################################

    brew_help() {
    echo <<- EOM
    Applied patch assumes you are using Homebrew (http://brew.sh) as a
    package manager but it wasn't found. Please check you installation.
    EOM
    }

    # Checking if brew is available
    `which -s brew` || { brew_help; unset brew_help; return; }
    unset brew_help

    #
    # These are the defaults for this version which should generally be
    # overridden from the prefs.sh file or from command-line specification
    #
    #- note the location for later use (eg, in job scripts)
    : ${FOAM_INST_DIR:=$foamInstall}; export FOAM_INST_DIR

    #- Compiler location:
    # foamCompiler= system
    foamCompiler=system

    #- Compiler:
    # WM_COMPILER = Clang
    export WM_COMPILER=Clang
    unset WM_COMPILER_ARCH WM_COMPILER_LIB_ARCH

    #- Architecture:
    # WM_ARCH_OPTION = 32 | 64
    export WM_ARCH_OPTION=64

    #- Precision:
    # WM_PRECISION_OPTION = DP | SP
    export WM_PRECISION_OPTION=DP

    mein Email rostand.mowa@yahoo.de

    RépondreSupprimer
  2. Hello Alexey, if you could just upload a video of the installation process, that would be unbelievably great! you will be my hero, role model/god! :)

    RépondreSupprimer
    Réponses
    1. I don't see the point in making video of the installation process (also to make it I need to 1) find a software to capture the video, 2) change locale so text labels in the video are in English) as it won't make installation process easier.

      So, guess, I won't be your role model/god. Sorry.

      Supprimer