mercredi 25 décembre 2013

Building hexagonal meshes with Gmsh

OpenFOAM's blockMesh is rather simple and efficient way of building meshes but it has certain annoying features:
  1. Entities numbering. To construct a block, an edge or a boundary one has to know its vertices numbers, they are numbered automatically stating with 0. So while constructing a mesh one can, for example, use vim with +relativenumber and blockMeshDict opened in two splits (see screenshot). But when blockMesh reports about errors in the mesh description it also uses these automatic numbers of entities. Soon it becomes rather annoying to look for the block #4 or #17 to correct gradings or densities.
  2. Mesh grading is a good thing but for example to make a cube mesh with a higher density near the walls, one has to cut the cube into 4 blocks and make consistent grading in each block.
  3. Curved edges is something special. For a 2D case it's rather simple to make an utility to calculate coordinates of a point on the arc of a given radius passing through two vertices, in a 3D case it's less obvious.
  4. And finally workflow vim -> blockMesh -> paraFoam is rather slow.
Gmsh usually used with the finite-element code GetDP so by default it generates tetrahedral meshes, like one below.
Tetrahedral mesh
But it is possible to make hexagonal meshes with it. All GEO files from the sections below can be found in the repository.


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.

samedi 13 juillet 2013

Fun with buoyantBosinesqFoam

This simulation was a part of seminar at IJL to show the capabilities of raw
OpenFOAM simulating flow of incompressible heat conducting fluid. So imagine
we'd like to simulate "cooler" - bended partly adiabatic tube part of which is
imposed to winter street:





Mesh will have 4 patches: inlet, outlet, adiabatic part (inside
a room), cooler part (outside a room). At the inlet we'll have a liquid with
constant velocity and temperature. Adiabatic part has non-slip BC for velocity
and zero-gradient for temperature. At the outlet we'll have zero-gradient for
velicity and temperature. Final graded version of the mesh is shown below.




And finally after running buoyantBossinesqFoam we'll get following movie of
themperature evolution inside the tube. And it'd be better to make outside
part coil.


Case files for the problem can be found on Bitbucket.

dimanche 19 mai 2013

Tumblr backup

Exercise in Python and threads. Small script to create Tumblr blog backups. For now it just downloads all photo posts of a given blog (primary reason for this script to appear). Later maybe I will extend it to other types of posts.

https://bitbucket.org/mrklein/tumblr-backup

dimanche 5 mai 2013

Number 123456 again

And prize for the best usage of GMP goes to Bigloo Scheme.




alexey at daphne in ~/Projects/tests$ bigloo -O3 fact.scm
ld: warning: option -s is obsolete and being ignored
alexey at daphne in ~/Projects/tests$ ./a.out
Recursive factorial: 4.44 sec
Iterative factorial: 3.96 sec
It has only factor of 2 compared to C version.