Affichage des articles dont le libellé est OS X. Afficher tous les articles
Affichage des articles dont le libellé est OS X. Afficher tous les articles

dimanche 20 juillet 2014

Building OpenFOAM on OS X. Update.

As I've got tired of struggling with Blogger (funny layout, lack of ability to markup posts in Markdown, rather inconvenient commenting) I've decided to move patches repository to Github. So all questions and bugs can be filed there. Installation guides can be found in wiki.

Since last post I've added the following things:

  1. Added patches for 2.1.x versions.
  2. Finally I've got a fresh OS X 10.9 installation and found out there's no gdb, so I've added lldb support to addr2line_mac.py. Also cleaned code a bit so it passes pylint without complains.
  3. Changed paraview from alias to function so now paraFoam doesn't complain about unknown command.
  4. Corrected sed patterns in Alltest file from tutorials folder.
  5. Added a sample file for environment setup.
As finally I was able to pass human test on openfoamwiki.net, maybe installation guides there should be also updated.

mardi 15 avril 2014

Building OpenFOAM on OS X

NB. Updated versions of the patches are on Github.

Previous patches I've posted in this blog (#1, #2, #3) have certain mistakes. Mainly because I forgot about DYLD_LIBRARY_PATH environment variable and did not test parallel execution of the solvers. Recently I've decided it is time to fix it. Also that tiny feedback I had, showed that there is two common errors during compilation: people create disk images with case insensitive file system and they try to apply patches in an arbitrary folders. The second problem is hard to solve by a blog post, while the first one can be solved if we change the process of disk image creation. Go from error-prone GUI way to just one command executed in terminal window. And here goes the guide.
Build process was tested on OS X version 10.9.2 with clang --version: Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn).

Before we start

I've made certain assumptions about the software you have on your Mac:
  • Homebrew is used as a package manager to install open source software. If not, you can install it following instructions on the site.
  • All software from ThirdParty source pack will be installed using Homebrew.
  • All commands are executed in Terminal application (usually it is called Terminal.app).
  • $ in the beginning of the lines is a shell prompt and you don't need to copy it, if you're copy/pasting commands from the post. In general commands should be executed in the sequence shown in the post.
  • You've downloaded Paraview application from paraview.org and installed it in /Applications.
To install dependencies you can use the following set of commands:
$ brew tap homebrew/science
$ brew install open-mpi
$ brew install scotch
$ brew install boost --without-single --with-mpi
$ brew install cgal
The last command will also install cmake, gmp, and mpfr as dependencies.

Downloading necessary pieces

At this point it is time to decide what version of OpenFOAM you'd like to build. As 2.3.0 introduced certain backward incompatible changes, I've made patches for 2.2.2 and 2.3.0. Further in the guide I assume you've downloaded source pack and patch into ~/Downloads/OpenFOAM folder.

OpenFOAM 2.2.2

Download source pack. Either following link on the OpenFOAM web site http://www.openfoam.org/archive/2.2.2/download/source.php, or by executing the following commands in in Terminal:
$ cd Downloads
$ mkdir OpenFOAM && cd OpenFOAM
$ curl -L http://downloads.sourceforge.net/foam/OpenFOAM-2.2.2.tgz > OpenFOAM-2.2.2.tgz
Download patch using following link https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.2.2.patch, or if you still have terminal opened, issue the command:
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.2.2.patch > OpenFOAM-2.2.2.patch

OpenFOAM 2.3.0

Download source pack. Either following link on the OpenFOAM web site - http://www.openfoam.org/download/source.php, or just executing this in Terminal:
$ cd Downloads
$ mkdir OpenFOAM && cd OpenFOAM
$ curl -L http://downloads.sourceforge.net/foam/OpenFOAM-2.3.0.tgz > OpenFOAM-2.3.0.tgz
Download patch using following link https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.3.0.patch, or if you still have terminal opened issue the command:
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.3.0.patch > OpenFOAM-2.3.0.patch
After this you're ready to proceed to the actual build process.

Building OpenFOAM

!!! Cause certain file names in this part depend on the version of OpenFOAM you're building, I use N and M variables in the file names. For OpenFOAM version 2.2.2: N=2, M=2; for OpenFOAM version 2.3.0: N=3, M=0.

Also it is possible that you already have disk image with the same name in your home folder. Correct the names accordingly.


To build OpenFOAM first you need to create disk image with case sensitive file system. You can either follow the guide from OpenFOAM wiki, or just issue these commands in your terminal:
$ cd
$ hdiutil create -size 4.4g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle
Last command will create disk image with the name OpenFOAM.sparsebundle with estimated size 4.4 G (as it is the sparse image, after creation the size of the file will be different), create HFS+ file system with a volume name OpenFOAM in the image. Finally -fsargs -s will instruct newfs_hfs utility to create case sensitive file system.
After the image was created you can mount it, I will assume it is mounted in $HOME/OpenFOAM
$ mkdir OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle
After you extract source pack, copy patch to the created folder, and apply patch (remember, you've downloaded the source pack and the patch into ~/Downloads/OpenFOAM):
$ cd OpenFOAM
$ tar xzf ~/Downloads/OpenFOAM/OpenFOAM-2.N.M.tgz
$ cd OpenFOAM-2.N.M
$ cp ~/Downloads/OpenFOAM/OpenFOAM-2.N.M.patch .
$ git apply OpenFOAM-2.N.M.patch
At this point maybe you'll need to edit etc/bashrc file. But since compiler settings are fixed (it is Clang), OpenMPI and other libraries settings are fixed (they are installed with Homebrew), in fact the only thing worth editing is path settings and only in case if you're installing OpenFOAM elsewhere (i.e. not in $HOME/OpenFOAM). Now you're more-or-less ready to compile.
$ source etc/bashrc
$ ./Allwmake > log.Allwmake 2>&1
The last command executes Allwmake script and redirects its output to log.Allwmake file; just in case, if anything goes wrong, it'll be easy to locate the source of error having this log file.
After Allwmake execution is finished, you can test the build with:
$ mkdir -p $FOAM_RUN
$ run
$ cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
$ cd cavity
$ blockMesh
$ icoFoam
If you'd like to test parallel run, it is necessary to do:
$ cat > system/decomposeParDict
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

numberOfSubdomains 4;

method          scotch;
^D
$ decomposePar
$ mpiexec -np 4 icoFoam -parallel
(^D is entered with Ctrl and D keys pressed together)

Post-configuration

There are several ways of managing mounting disk image and sourcing etc/bashrc file.
The first one is to define alias in your $HOME/.profile:
alias of2NM='hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle; sleep 1; source $HOME/OpenFOAM/OpenFOAM-2.N.M/etc/bashrc'
The second one is to create $HOME/.OpenFOAM-release file with a version of OpenFOAM you'd like to use:
$ echo '2.N.M' > $HOME/.OpenFOAM-release
and then add the following lines to your $HOME/.profile:
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.sparsebundle && . $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
        else
                . $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
        fi
fi
And finally third one is to transform second version in the set of functions. I.e. instead of automatic attachment of disk image upon terminal start, you'll need to execute function which will mount necessary disk image and source bashrc:

of2xx() {
    local version=$1
    if [ ! -f $HOME/OpenFOAM/OpenFOAM-$version/etc/bashrc ]; then
        hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle &&
            . $HOME/OpenFOAM/OpenFOAM-$version/etc/bashrc
    else
        . $HOME/OpenFOAM/OpenFOAM-$version/etc/bashrc
    fi
}

of2NM() {
    of2xx '2.N.M'
}
Add this code to your $HOME/.profile and use of2NM command to setup environment.

And that's it.

vendredi 21 février 2014

Building OpenFOAM 2.3.0 on OS X. Tk.2

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

After I've made patches for OpenFOAM 2.3.0 to build it with clang I came upon post by Bernhard Gshaider where he decided to drop ThirdParty source packs as all necessary software can be installed with Macports. Since all software from ThirdParty package can be installed with Homebrew (except you don't need to install gcc with all the stuff Macports pull with it), I've made this patch.

Installation is more or less straight-forward:
  1. Download OpenFOAM-2.3.0.tgz source pack
  2. Download patch.
  3. Create disk image with CASE SENSITIVE file system. Guide with pictures is on OpenFOAM wiki. Usually guides suggest sparseimage format though sparsebundle format is more convenient for the systems with active backup software.
  4. Mount created image into $HOME/OpenFOAM (hdiutil attach -quiet -mountpoint $HOME/OpenFOAM <your disk image file>)
  5. Unpack source archive into $HOME/OpenFOAM. Assuming you've downloaded it in $HOME/Downloads you can do the following:
    $ cd $HOME/OpenFOAM
    $ tar xzf ~/Downloads/OpenFOAM-2.3.0.tgz
  6. Copy patch into $HOME/OpenFOAM/OpenFOAM-2.3.0 folder
    $ cd $HOME/OpenFOAM/OpenFOAM-2.3.0
    $ cp ~/Downloads/OpenFOAM-2.3.0-3.patch .
  7. Apply patch with git apply OpenFOAM-2.3.0-3.patch
  8. Install third party software. I assume you're using Homebrew as a package manager, so you need to do:
    $ brew install open-mpi gmp mpfr boost gcal
  9. Now you can initialize environment variables for OpenFOAM with $ source etc/bashrc
    (or you can first edit this file if you're installing OpenFOAM somewhere but $HOME/OpenFOAM/OpenFOAM-2.3.0)
  10. Now you are ready to execute ./Allwmake
And that's it.

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.

dimanche 22 décembre 2013

Building OpenFOAM 2.2.2 on OS X with clang

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

There are several instructions for building OpenFOAM on OS X (1, 2). They assume that you are using Macports which was not a case with me. So I've decided to build OpenFOAM with clang as it comes with developer tools. My patches are based upon ones by Bernhard Gschaider, basically I've applied his patches, removed Macports stuff and added clang stuff. Patches and 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)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

So, to build OpenFOAM you need:
  1. Download OpenFOAM and Third-Party source packs here.
  2. Create a disk image with Disk Utility. One needs this image to create case sensitive file system (see 1 or 2 for instructions with pictures).
  3. Download patches for OpenFOAM and Third-Party source packs. They assume you are building 64-bit version of the code as there're no wmake rules for 32-bit compilation.
  4. Mount created disk image to $HOME/OpenFOAM
  5. Unpack source packs to $HOME/OpenFOAM
  6. Copy patch files to source folders (OpenFOAM-2.2.2-1387556919.patch to OpenFOAM-2.2.2, ThirdParty-2.2.2-1387556964.patch to ThirdParty-2.2.2).
  7. Apply patches with git apply [patch file name] command. In addition to changing contents of the files git sets modes so you won't need to do chmod 0755 [file] on executable files created by the patches.
  8. Edit $HOME/OpenFOAM/OpenFOAM-2.2.2/ets/bashrc file to correspond to your system. I've tested build with OPENMPI (1.6.3, in ThirdParty source pack), and with SYSTEMOPENMPI (1.7.3, installed with Homebrew, I guess if you're using Macports you'll need to modify wmake rules).
  9. Source bashrc with source etc/bashrc
  10. Now you can execute Allwmake script to build OpenFOAM.
To mount disk image and source OpenFOAM's bashrc file automatically each time you launch Terminal one can add following lines to $HOME/.profile file:
# OpenFOAM
if [ -f $HOME/.OpenFOAM ]; then
    OF_VER=$(cat $HOME/.OpenFOAM)
    if [ ! -f $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc ]; then
        hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM-$OF_VER.dmg &&
            . $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
    else
        . $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
    fi
fi
And create $HOME/.OpenFOAM file with OpenFOAM version in it with:
echo '2.2.2' > $HOME/.OpenFOAM
Now you can test installation with standard icoFoam run:
$ mkdir -p $FOAM_RUN
$ run
$ cp -r $FOAM_TUTOTALS/incompressible/icoFoam/cavity .
$ cd cavity
$ blockMesh
$ icoFoam
Also maybe it's worth to move $FOAM_RUN folder somewhere outside of disk image and create symlink.

That's it.