lundi 24 février 2014

Matplotlib's tricontour interesting behaviour

Matplotlib was happy to plot contours of triangular meshes in the past. Though they were not actually triangular, they were triangulated (by OpenFOAM's sample utility) rectangular meshes. Recently I've encountered rather strange thing, all my attempts to plot isoline of a value on a triangular mesh which initially wasn't rec ended up with while if I try to use scipy triangulation everything goes more or less OK.

Thought matplotlib and scipy use the same algorithm for triangulation appears I was wrong.

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.