Working with user routines

FLUKA provides a range of user routines, written in Fortran 77, which can be customized according to the needs of the user application. The use of such routines might be necessary if the required functionality is not available through built-in user commands (e.g. special source distributions, customized magnetic fields). The routines can also be used to customize the scoring setup, to adjust the biasing, or to obtain details about single-particle tracks and interactions which would otherwise not be accessible through standard input cards. A glimpse of the different functionalities offered by user routines is provided below together with instructions on how to compile, link and activate the routines.

Compiling and linking user routines

The user routines can be found in the /pathtofluka/src/user/ directory, where /pathtofluka/ is the directory where FLUKA has been installed. It is recommended not to modify the user routines directly in the installation directory, but to copy the required routines into a separate working directory outside of the FLUKA installation tree.

For example, to create a new directory called myworkdir inside the home directory and to copy the user source routine to this directory, type:

cd ~
mkdir myworkdir
cd myworkdir
cp /pathtofluka/src/user/source.f mysource.f

As indicated in this example, the name of the Fortran files can be changed (here from source.f to mysource.f), however the routine name in the file must be kept.

Modified routines need to compiled and a new executable needs to be created by linking the routines against the FLUKA library. It is recommended to name the executable differently than the standard executables (fluka and flukadpm). Auxiliary scripts for compiling and linking user routines can be found in the /pathtofluka/bin/ directory. Each user routine needs to be compiled separately using the fff script, e.g.:

/pathtofluka/bin/fff mysource.f

This will create the corresponding object file (here mysource.o). Once all routines have been compiled, they can be linked using the lfluka script:

/pathtofluka/bin/lfluka -m fluka -o myfluka mysource.o mymagfld.o mymgdraw.o ...

where -m specifies the main program which will be extracted from the fluka library (use fluka) and -o indicates the new executable name (here myfluka). At the end of the command, all the object files (.o) created in the first step must be specified.

For simulations requiring the DPMJET and RQMD packages (see the manual for details), add also the option -d, or use ldpmqmd instead of the lfluka script.

In case that the /pathtofluka/bin/ directory has been added to the PATH environment variable (see installation procedure) one does not need to specify the full path but can just type fff, lfluka or ldpmqmd.

Activating user routines in simulations

Most user routines are not active by default but must be invoked by input directives. The following table provides an overview of the cards which are needed to activate different routines (see the manual for details, N/A means no card is needed to activate the routine):

Card Routines Invoked when?
USRGCALL usrglo.f Global Initialization
USRICALL usrini.f Before START
N/A usrein.f History loop
SOURCE source.f History loop
MAT-PROP usrmed.f History loop
USERDUMP mgdraw.f History loop
USERWEIG comscw.f, fluscw.f, usrrnc.f History loop
USROCALL usrout.f