OpenFOAM on Mac OS X

OpenFOAM is an open source C++ library for running CFD simulations using the finite volume method. It's hard to install and even harder to use, but at least we can make the installation easier!

If you use a version of Mac OS X (probably >= 10.6), all you need to do is download a pre-compiled image of OpenFOAM. They aren't too easy to come by, so I've decided to make the one I use available for everybody's enjoyment. I've also compiled swak4foam with it which is an added bonus.

Step 1. Download the image and save it to your home directory (ie. /Users/[username]):
OpenFOAM-1.6-ext-swak4foam.dmg (version released Feb 2011)

Step 2. Next, you have to add a couple of lines to your .bash_profile. Open up the terminal and add the following lines to ~/.bash_profile (you might have to create the file first if it doesn't exist):

alias source16ext='hdiutil mount ~/OpenFOAM-1.6-ext-swak-Feb4.dmg;source ~/OpenFOAM/OpenFOAM-1.6-ext/etc/bashrc'
This is a single command that mounts the image file containing all of the OpenFOAM goodness, and at the same time sources the bashrc file which you always have to do in order to run OpenFOAM. To add this command, you can alternatively just copy and paste this into the terminal:
you@yourTerminal: echo "alias source16ext='hdiutil mount ~/OpenFOAM-1.6-ext-swak-Feb4.dmg;source ~/OpenFOAM/OpenFOAM-1.6-ext/etc/bashrc'" >> ~/.bash_profile

Step 3. Create a directory structure that OpenFOAM is expecting which links to the image file that you just downloaded.

you@yourTerminal: mkdir -p ~/OpenFOAM/$USER-1.6-ext/{run,applications,lib};
ln -s /Volumes/OpenFOAM-1.6-ext ~/OpenFOAM/OpenFOAM-1.6-ext

Step 4. Install open-mpi. OpenFOAM depends on the open-mpi interface. In my opinion, the easiest way to install this is through homebrew. First, install homebrew (actually, first install Xcode from the Apple App Store, then install the command line tools to get gcc, g++ etc., then do this):

you@yourTerminal: ruby <(curl -fsS
Assuming homebrew installed properly, you can go ahead and install gfortran and open-mpi 1.4.5. As of this writing, open-mpi 1.6 is available, but you have to fiddle around with the installation on homebrew (depending on your processor type) and then you'll have to manually add some symlinks to some .dylb files. So I recommend using open-mpi 1.4.5 which works.
you@yourTerminal: brew install gfortran
you@yourTerminal: brew versions openmpi
you@yourTerminal: cd /usr/local
you@yourTerminal: git checkout 8bbd52d /usr/local/Library/Formula/open-mpi.rb
you@yourTerminal: brew install openmpi
where the sequence "8bbd52d" refers to whatever version you want from the "brew versions openmpi" command.

Step 5. That's it! If everything worked, you should be able to run OpenFOAM. Start up a new terminal and type "source16ext". You'll notice that this will mount the OpenFOAM image file. Then you can change into your run directory by typing "cd $FOAM_RUN" which should put you in the directory ~/OpenFOAM/[username]-1.6-ext/run