\chapter{Detailed Installation Instructions} \label{install}

\section{Preliminary remarks}
In this section about the installation of \Dumux it is assumed that you work with a Linux or Apple OS X operating system
and that you are familiar with the use of a command line shell. Installation means that you unpack \Dune together with \Dumux in a certain directory.
Then, you compile it in that directory tree in which you do the further work, too. You also should know how to install new software packages
or you should have a person on hand who can give you assistance with that. In section \ref{sec:prerequisites} we list some prerequisites for running \Dune and \Dumux. 
Please check in said paragraph whether you can fulfill them. In addition, section \ref{sec:external-modules-libraries} provides some details on optional libraries and modules.

In a technical sense \Dumux is a module of \Dune. 
Thus, the installation procedure of \Dumux is the same as that of \Dune. 
Details regarding the installation of \Dune are provided on the \Dune website \cite{DUNE-INST}. 
If you are interested in more details about the build system that is used,
they can be found in the {\Dune} Buildsystem Howto \cite{DUNE-BS}.

All \Dune modules, including \Dumux, get extracted into a common directory, as it is done in an ordinary \Dune installation. 
We refer to that directory abstractly as {\Dune} root directory or, in short, as {\Dune}-Root. 
If it is used as directory's path of a shell command it is typed as \texttt{\Dune-Root}. 
For the real {\Dune} root directory on your file system any valid directory name can be chosen.

Source code files for each \Dune module are contained in their own subdirectory within {\Dune}-Root.
We name this directory of a certain module \emph{module root directory} or \texttt{module-root-directory} if it is a directory path,
e.\,g. for the module \texttt{dumux} these names are  \emph{dumux root directory} respective \texttt{dumux-root-directory}.
The real directory names for the modules can be chosen arbitrarily. In this manual they are the same as the
module name or the module name extended by a version number suffix.
The name of each \Dune module is defined in the file \texttt{dune.module}, which is in the root
directory of the respective module. This should not be changed by the user.

After extracting the source code for all relevant \Dune modules, including \Dumux, \Dune has to be built
by the shell-command \texttt{dunecontrol} which is part of the \Dune build system.

\section{Prerequisites} \label{sec:prerequisites}
The GNU tool chain of \texttt{g++}  and the tools of the GNU build system \cite{GNU-BS}, also known as GNU autotools
(\texttt{autoconf}, \texttt{automake}, \texttt{autogen}, \texttt{libtool}), as well as \texttt{make}
must be available in a recent version. For a list of prerequisite software packages to install,see
\cite{DUNE-WIKI-PREREQUISITE-SOFTWARE}.

The building of included documentation like this handbook requires \LaTeX{} and auxiliary tools
\texttt{bibtex}. One usually chooses a \LaTeX{} distribution like \texttt{texlive} for this purpose.
It is possible to switch off the building of the documentation by setting the switch \texttt{--disable-documentation} 
in the \texttt{CONFIGURE\_FLAGS} of the building options, see Chapter \ref{buildIt}.
Additional parts of documentation are contained within the source code files as special formatted comments.
Extracting them can be done using \texttt{doxygen}, cf. Section \ref{sec:build-doxy-doc}.

Depending on whether you are going to use external libraries and modules for additional \Dune features, 
additional software packages may be required. Some hints on that are given in Section \ref{sec:external-modules-libraries}.

Subversion (SVN) and a Git clients must be installed to download modules from Subversion and Git repositories.

\section{Obtaining source code for \Dune and \Dumux}
As stated above, the \Dumux release and trunk (developer tree) are based on the most recent
\Dune release 2.3, comprising the core modules dune-common, dune-geometry, dune-grid,
dune-istl and dune-localfunctions. For working with \Dumux, these modules are required. The
external module dune-PDELab is recommended and required for several \Dumux features.

Two possibilities exist to get the source code of \Dune and \Dumux.
Firstly, \Dune and \Dumux can be downloaded as tar files from the respective \Dune and \Dumux website.
They have to be extracted as described in the next paragraph.
Secondly, a method to obtain the most recent source code (or, more generally, any of its previous revisions) by direct access 
to the software repositories of the revision control system is described in the subsequent part. 

However, if a user does not want to use the most recent version,
certain version tags or branches (i.\,e. special names) are means 
of the software revision control system to provide access to different versions of the software.

\paragraph{Obtaining the software by installing tar files}
The slightly old-fashionedly named tape-archive-file, shortly named tar file or tarball, is a common file format for distributing collections of files contained within these archives.
The extraction from the tar files is done as follows: 
Download the tarballs from the respective \Dune (version 2.3) and \Dumux websites to a certain folder in your file system.
Create the {\Dune} root directory, named \texttt{dune} in the example below.
Then extract the content of the tar files, e.\,g. with the command-line program \texttt{tar}.
This can be achieved by the following shell commands. Replace \texttt{path\_to\_tarball} with the directory name where the downloaded files are actually located.
After extraction, the actual name of the \emph{dumux root directory} is \texttt{dumux-2.5}
(or whatever version you downloaded).

\begin{lstlisting}[style=Bash]
$ mkdir dune
$ cd dune
$ tar xzvf path_to_tarball_of/dune-common-2.3.1.tar.gz 
$ tar xzvf path_to_tarball_of/dune-geometry-2.3.1.tar.gz 
$ tar xzvf path_to_tarball_of/dune-grid-2.3.1.tar.gz 
$ tar xzvf path_to_tarball_of/dune-istl-2.3.1.tar.gz 
$ tar xzvf path_to_tarball_of/dune-localfunctions-2.3.1.tar.gz
$ tar xzvf path_to_tarball_of/dune-pdelab-2.0.0.tar.gz
$ tar xzvf path_to_tarball_of/dune-typetree-2.3.1.tar.gz
$ tar xzvf path_to_tarball_of/dumux-2.6.tar.gz
\end{lstlisting}

Furthermore, if you wish to install the optional \Dune Grid-Howto which provides a tutorial
on the Dune grid interface, act similar.

\paragraph{Obtaining \Dune and \Dumux from software repositories} 
Direct access to a software revision control system for downloading code can be of advantage for the user later on. 
It can be easier for him to keep up with code changes and to receive important bug fixes using
the update or pull command of the revision control system. \Dune uses Git and \Dumux uses Apache
Subversion for their software repositories. To access them a certain programs are needed which
is referred to here shortly as Subversion client or Git client. In our description, we use the
Subversion client \texttt{svn} of the Apache Subversion software itself.

In the technical language of Apache Subversion \emph{checking out a certain software version} means nothing more then fetching 
a local copy from the software repository and laying it out in the file system.
In addition to the software some more files for the use of the software revision
control system itself are created. If you have developer access to \Dumux, it is
also possible to do the opposite, i.\,e. to load up a modified revision of software
into the software repository. This is usually termed as \emph{commit}.

The installation procedure is done as follows:
Create a  {\Dune} root directory, named \texttt{dune} in the lines below.
Then, enter the previously created directory and check out the desired modules. 
As you see below, the check-out uses two different servers for getting the sources,
one for \Dune and one for {\Dumux}.
The \Dune modules of the stable 2.3 release branch are checked out as described
on the \Dune website \cite{DUNE-DOWNLOAD-GIT}:

\begin{lstlisting}[style=Bash]
$ mkdir DUMUX
$ cd DUMUX
$ git clone http://git.dune-project.org/repositories/dune-common
$ cd dune-common
$ git checkout releases/2.3
$ cd ..
$ git clone http://git.dune-project.org/repositories/dune-geometry
$ cd dune-geometry
$ git checkout releases/2.3
$ cd ..
$ git clone http://git.dune-project.org/repositories/dune-grid
$ cd dune-grid
$ git checkout releases/2.3
$ cd ..
$ git clone http://git.dune-project.org/repositories/dune-istl
$ cd dune-istl
$ git checkout releases/2.3
$ cd ..
$ git clone http://git.dune-project.org/repositories/dune-localfunctions
$ cd dune-localfunctions
$ git checkout releases/2.3
$ cd ..
$ git clone http://git.dune-project.org/repositories/dune-pdelab
$ cd dune-pdelab
$ git checkout releases/2.0
$ cd ..
$ git clone http://git.dune-project.org/repositories/dune-typetree
$ cd dune-typetree
$ git checkout releases/2.3
$ cd ..
\end{lstlisting}

The newest and maybe unstable developments are also provided in these repositories and is called \emph{master}.
Please check the \Dune website \cite{DUNE-DOWNLOAD-GIT} for further information. However, the current \Dumux release
is based on the stable 2.3 release and it might not compile without further adaptations using the the newest versions of \Dune.

Furthermore, if you wish to install the optional \Dune Grid-Howto which provides a tutorial
on the Dune grid interface, act similar.

The \texttt{dumux} module is checked out as described below (see also the \Dumux website \cite{DUMUX-HP}).
Its file tree has to be created in the \Dune-Root directory, where the \Dune modules have also been checked out to. Subsequently, the next command
is executed there, too. The dumux root directory is called \texttt{dumux} here.

\begin{lstlisting}[style=Bash]
$ # make sure you are in DUNE-Root
$ svn checkout --username=anonymous --password='' svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk dumux
\end{lstlisting}

\paragraph{Hints for \Dumux-Developers}
If you also want to actively participate in the development of \Dumux, you can allways send patches
to the Mailing list.

To get more involved, you can apply either for full developer
access or for developer access on certain parts of \Dumux. Granted developer access means that
you are allowed to commit own code and that you can access the \texttt{dumux-devel} module.
This enhances \texttt{dumux} by providing maybe unstable code from the developer group.
A developer usually checks out non-anonymously the modules \texttt{dumux} and \texttt{dumux-devel}. 
\texttt{Dumux-devel} itself makes use of the stable part \texttt{dumux}. Hence, the two parts have to be checked out together.
This is done using the commands below. But \texttt{joeuser} needs to be replaced by
the actual user name of the developer for accessing the software repository. 
One can omit the \texttt{--username} option in the commands above if the user name for the repository access is
identical to the one for the system account.

\begin{lstlisting}[style=Bash]
$ svn co --username=joeuser svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk dumux
$ svn co --username=joeuser svn://svn.iws.uni-stuttgart.de/DUMUX/dune-mux/trunk dumux-devel
\end{lstlisting}

Please choose either not to store the password by subversion in an insecure way or
choose to store it by subversion in a secure way, e.\,g. together with KDE's KWallet or GNOME Keyring.
Check the documentation of Subversion for info on how this is done.
A leaked out password can be used by evil persons to abuse a software repository.

\section{Patching \Dune or external libraries}
Patching of \Dune modules in order to work together with \Dumux can be necessary for several reasons.
Software like a compiler or even a standard library
changes at times. But, for example, a certain release of a software component that we depend on, 
may not reflect that change and thus it has to be modified.
In the dynamic developing process of software which depends on other modules it is not always feasible 
to adapt everything to the most recent version of each module. They may fix problems with a certain module
of a certain release without introducing too much structural change.

\Dumux contains patches and documentation about their usage and application within the 
directory \texttt{dumux/patches}.
Please check the README file in that directory for recent information. 
In general, a patch can be applied as follows 
(the exact command or the used parameters may be slightly different).
We include here an example of a patch against \Dune-PDELab 1.1
for the \Dumux release 2.3 for purpose of showing how a patch gets applied. 

\begin{lstlisting}[style=Bash]
$ # make sure you are in DUNE-Root
$ cd dune-pdelab
$ patch -p0 < ../dumux/patches/pdelab-1.1.0.patch
\end{lstlisting}

It can be removed by 
\begin{lstlisting}[style=Bash]
$ path -p0 -R < ../dumux/patches/pdelab-1.1.0.patch
\end{lstlisting}

The \texttt{checkout-dumux} script also applies patches, if not explicitly requested not to do so.

\section{Building doxygen documentation} \label{sec:build-doxy-doc}
Doxygen documentation is done by especially formatted comments integrated in the source code, which can get extracted by the program 
\texttt{doxygen}. Beside extracting these comments, \texttt{doxygen} builds up a web-browsable code structure documentation
like class hierarchy of code displayed as graphs, see \cite{DOXYGEN-HP}.

The Doxygen documentation of a module can be built, provided the program \texttt{doxygen} is installed,
by running \texttt{dunecontrol}, entering the module's root directory, and execute \texttt{make doc}.
Point your web browser to the file 
\texttt{module-root-directory/doc/doxygen/html/index.html} to read the generated documentation.

\section{Building documentation of other \Dune modules}
If the \texttt{--enable-documentation} switch has been set in the configure flags of
\texttt{dunecontrol}, this does not necessarily mean that for every 
\Dune module the documentation is automatically being built. Run the target \texttt{make doc}
in the module's root directory to generate to build the module's documentation.

\section{External libraries and modules} \label{sec:external-modules-libraries}
The libraries described below provide additional functionality but are not generally required to run \Dumux. 
If you are going to use an external library check the information provided on the \Dune website \cite{DUNE-EXT-LIB}.
If you are going to use an external \Dune module the website on external modules \cite{DUNE-EXT-MOD} can be helpful.

Installing an external library can require additional libraries which are also used by \Dune. 
For some libraries, such as BLAS or MPI, multiple versions can be installed on the system.
Make sure that it uses the same library as \Dune when configuring the external library.

In the following list, you can find some external modules and external libraries, and some more libraries and tools which are prerequisites for their use.

\begin{itemize}
\item \textbf{ALBERTA}: External grid library. Adaptive multi-level grid manager using bisectioning
  refinement and error control by residual techniques for scientific Applications. Requires a Fortran
  compiler like \texttt{gfortran}. Download: \texttt{\url{http://www.alberta-fem.de}} or for version 3.0
  \texttt{\url{http://www.mathematik.uni-stuttgart.de/fak8/ians/lehrstuhl/nmh/downloads/alberta/}}.

\item \textbf{ALUGrid}: External grid library. ALUGrid is built by a \Cplusplus compiler like \texttt{g++}.
  If you want to build a parallel version, you will need \texttt{MPI}. It was successfully run with \texttt{openmpi}.
  The parallel version needs also a graph partitioner, such as \texttt{ParMETIS}.
  Download: \texttt{\url{http://aam.mathematik.uni-freiburg.de/IAM/Research/alugrid}}

\item \textbf{\Dune-multidomaingrid} and \textbf{\Dune-multidomain}: External modules which offer a meta grid that
  has different sub-domains. Each sub-domain can have a local operator that is coupled by a coupling condition. They are
  used for multi-physics approaches or domain decomposition methods. Download:
  \texttt{\url{https://github.com/smuething/dune-multidomaingrid}}
  and \texttt{\url{https://github.com/smuething/dune-multidomain}}

\item \textbf{\Dune-PDELab}: External module to write more easily discretizations. PDELab provides
  a sound number of discretizations like FEM or discontinuous Galerkin methods.
  Download: \texttt{\url{http://www.dune-project.org/pdelab}}

\item \textbf{PARDISO}: External library for solving linear equations. The package PARDISO is a thread-safe,
  high-performance, robust, memory efficient and easy to use software for solving large sparse symmetric
  and asymmetric linear systems of equations on shared memory multiprocessors. The precompiled binary
  can be downloaded after personal registration from the PARDISO website: \texttt{\url{http://www.pardiso-project.org}}

\item \textbf{SuperLU}: External library for solving linear equations. SuperLU is a general purpose
  library for the direct solution of large, sparse, non-symmetric systems of linear equations.
  Download: \texttt{\url{http://crd.lbl.gov/~xiaoye/SuperLU}}

\item \textbf{UG}: External library for use as grid. UG is a toolbox for unstructured grids, released under GPL.
  To build UG the tools \texttt{lex}/\texttt{yacc} or the GNU variants of \texttt{flex}/\texttt{bison} must be provided.
  Download: \texttt{\url{http://www.iwr.uni-heidelberg.de/frame/iwrwikiequipment/software/ug}}
\end{itemize}

The following are dependencies of some of the used libraries. You will need them depending on which modules of \Dune and which external libraries you use.

\begin{itemize}
\item \textbf{MPI}: The parallel version of \Dune and also some of the external dependencies need MPI
  when they are going to be built for parallel computing. \texttt{OpenMPI} and \texttt{MPICH} in a recent
  version have been reported to work.

\item \textbf{BLAS}: Alberta and SuperLU make use of BLAS. Thus install GotoBLAS2, ATLAS, non-optimized BLAS
  or BLAS provided by a chip manufacturer. Take care that the installation scripts select the intended
  version of BLAS.

\item \textbf{METIS} and \textbf{ParMETIS}: This are dependencies of ALUGrid and can be used with UG, if run in parallel.

\item \textbf{Compilers}: Beside \texttt{g++}, \Dune can be built with Clang from the LLVM project and
  Intel \Cplusplus compiler. C and Fortran compilers are needed for some external libraries. As code of
  different compilers is linked together they have to be be compatible with each other. A good choice
  is the GNU compiler suite consisting of \texttt{gcc}, \texttt{g++} and \texttt{gfortran}.
\end{itemize}

\section{Hints for Users from IWS}
We provide some features to make life a little bit easier for
users from the Institute for Modelling Hydraulic and Environmental Systems, University of Stuttgart.

There exists internally a Subversion repository made for several external libraries.
If you are allowed to access it, go to the {\Dune}-Root, then the following.

Prepared external directory:
\begin{lstlisting}[style=Bash]
$ # Make sure you are in DUNE-Root
$ svn checkout svn://svn.iws.uni-stuttgart.de/DUMUX/external/trunk external
\end{lstlisting}

This directory \texttt{external} contains a script to install external libraries, such as 
ALBERTA, ALUGrid, UG, and METIS:
\begin{lstlisting}[style=Bash]
$ cd external
$ ./installExternal.sh all
\end{lstlisting}

It is also possible to install only the actually needed external libraries:
\begin{lstlisting}[style=Bash]
$ ./installExternal.sh -h      # show, what options this script provide
$ ./installExternal.sh --parallel alu
\end{lstlisting}

The libraries are then compiled within that directory and are not installed in a different place. 
A \Dune build may need to know their location. Thus, one may have to refer to them as options for \texttt{dunecontrol}, 
for example via the options file \texttt{my-debug.opts}. Make sure you compile the required external libraries before 
you run \texttt{dunecontrol}.
