FLUKA and flair on macOS

FLUKA and flair can both be installed under macOS, though some additional software is needed. This document describes the process for macOS 10.14 (Mojave) as of November 2019.

Installing FLUKA

You can download FLUKA from http://www.fluka.org after registering as a user. Several packages are available; you should download the Mac version associated with the compiler you will be using (see below). This will usually be the one compiled with the most recent version of gfortran. At the time of writing this is fluka2011.2x-mac-gfor64bit-9.2-AA.tar.gz, which is compiled with gfortran 9.2.

The installation process needs a Fortran compiler; we recommend installing MacPorts to obtain this and other useful tools. MacPorts can be installed by following the instructions at https://www.macports.org.

In what follows, we assume that files have been downloaded to the user’s Downloads directory, and FLUKA is to be installed under ~/fluka/. You may have to adjust some paths to suit your machine, or if downloaded filenames have changed. Commands given here should be entered in Terminal.app. Those prefixed with “sudo” require password authentication from an admin account. (If using a standard account, you can install MacPorts in your home directory, and avoid the need for sudo.) If you are not familiar with system administration, make sure you have access to competent help in case something goes wrong.

We will install a recent version of the GNU Compiler Collection to obtain gfortran. Version 9 is available through MacPorts as the package gcc9. At the time of writing, the most reliable way of getting a working gcc installation is to install it from source by using the ‘-s’ option. This may take hours to complete.

sudo port install -s gcc9

We need to set some environment variables before using FLUKA. You should add these to your shell’s startup file so that they are automatically set in future. The correct startup file is usually ~/.profile (or ~/.bash_profile if it exists).

export FLUPRO=~/fluka/FLUKA
export FLUFOR=gfortran
export GFORFLU=gfortran-mp-9

We create the directory named in FLUPRO if it doesn’t exist, extract FLUKA there, and then build it with “make”.

mkdir -p $FLUPRO
cd $FLUPRO
tar xvf ~/Downloads/fluka2011.2x-mac-gfor64bit-9.2-AA.tar.gz
make

If there are no errors, FLUKA should now be installed. There are example input files in the FLUKA directory which can be used for testing. (Copy these elsewhere before running; you should never run jobs in the FLUKA directory.) Consult the FLUKA documentation for instructions on running jobs.

Installing flair

Download the flair source code (currently flair-2.3-0.tgz) from http://www.fluka.org/flair. If you follow the included installation instructions using the python interpreter included with macOS, the base functionality will be usable. If you need more features, including the geometry viewer, you must follow a more complicated build process. If you don’t need the features, stop here, as using macOS python gives better performance.

Before the next step, we’ll need XQuartz, an X Window system for macOS. School machines should already have this installed. For other machines, you can obtain it from https://www.xquartz.org. Once XQuartz is installed, we’ll use MacPorts to install some other pre-requisites.

sudo port install python27 py27-tkinter py27-pydicom py27-numpy py27-Pillow gnuplot

This can be a slow process. If you don’t need DICOM support, you can speed it up by omitting py27-pydicom and py27-numpy.

We’ll install flair to a directory beside FLUKA.

export FLAIR_INSTALL=~/fluka/flair
mkdir -p $FLAIR_INSTALL
cd ~/fluka/
tar xvf ~/Downloads/flair-2.3-0.tgz
cd flair-2.3
make PYTHON=python2.7 DESTDIR=$FLAIR_INSTALL install

This gives us a version of flair without the geometry viewer. It can be run with either the macOS python or MacPorts python. To add the geometry viewer, first download the flair-geoviewer archive (currently flair-geoviewer-2.3-0.tgz) from the flair website and extract it.

cd ~/fluka/
tar xvf ~/Downloads/flair-geoviewer-2.3-0.tgz
cd flair-geoviewer-2.3/

We’ll need to modify the code to use the correct libraries. Find the makefile at the root of the extracted directory and edit it with a text editor. Find the line “TKLIBS = -undefined dynamic_lookup” and replace it so that this:

else ifeq ($(SYSTEM),Darwin)
        TKLIBS = -undefined dynamic_lookup
endif

becomes:

else ifeq ($(SYSTEM),Darwin)
        INCDIR += -I/opt/X11/include
        LIBDIR += -L/opt/X11/lib
        LIBDIR += -L/opt/local/lib
        TKLIBS = -ltk -ltcl
        PYTHONLIB = -L$(PYTHON_LIB) -lpython$(PYTHON_VER)
endif

When the edited makefile is saved, we can build the geoviewer plugin and install it to the flair installation directory.

make PYTHON=python2.7 DESTDIR=$FLAIR_INSTALL
make PYTHON=python2.7 DESTDIR=$FLAIR_INSTALL install

The script included with flair to run it will not work correctly, so we will create a wrapper script to launch the program. Create a text file ~/fluka/flair/runflair and add the following to it:

#!/bin/sh
PYTHON=python2.7 ~/fluka/flair/flair $*

Make this script executable with the command:

chmod a+x ~/fluka/flair/runflair

You can now launch flair by executing the script:

~/fluka/flair/runflair