# GANDALF

GANDALF is a hybrid self-gravitating fluid dynamics and collisional N-body code primarily designed for investigating star formation and planet formation problems that cannot be analysed by traditional `pen and paper' mathematics. Such problems require computer simulations to study the details of what happens in any given scenario.

GANDALF is the successor code to SEREN (Hubber et al. 2011), which itself was a self-gravitating hydrodynamical code with N-body components attached. Although based on many of the SEREN routines, GANDALF has been largely re-written from scratch in C++ using more optimal algorithms and data structures. For typical star formation problems, GANDALF runs approx. 3 times faster on similar architecture.

### Self-gravitating hydrodynamics

GANDALF uses various implementations of Smoothed Particle Hydrodynamics (SPH) to perform hydrodynamical simulations of gas clouds undergoing gravitational collapse to form new stars (or other objects). Such simulations include simulations of the gravo-turbulent fragmentation of molecular clouds and prestellar cores, the evolution, accretion and fragmentation of protoplanetary discs and mechanical and radiative feedback from young stars into the surrounding gas cloud.

### N-body dynamics

GANDALF can perform simulations of pure N-body dynamics using high accuracy N-body integrators. If the gas of a stellar system can be ignored, or it has already been ejected by stellar feedback, then the main dynamics of the system is governed principally by N-body dynamics. Such systems may include proto-multiple systems formed from individual star forming cores, or the large-scale dynamical evolution

### Hybrid hydrodynamics & N-body dynamics

GANDALF can model the intermediate phase of cluster evolution, where a significant fraction of the gas has formed stars, but the remaining gas is important gravitationally and can affect the long-term evolution of the cloud. Although many codes include both the gas and stars, GANDALF includes a conservative implementation of the coupled equations of motion that allows the gaseous component to be integrated to the high-accuracy required by many traditional N-body codes.

### Python interface and interactive simulations

GANDALF is not just restricted to being used as a `number-crunching' simulation code, but can also provide visualisation via its python interface as well as interactive `on-the-fly' simulations.

### Object-oriented design

GANDALF was written in C++ in order to take advantage of the benefits of object-oriented design in large projects. Since GANDALF has multiple implementations for the same feature (e.g. different hydrodynamics methods for the gas, different integration schemes to move particles), the code is designed so that each algorithmic feature has a standard format and interface. This makes adding additional implementations easier since each feature already has a well-defined structure that can be adhered to.

## Status & Features

The latest version of GANDALF contains the following features

- 2 `flavours' of SPH :
- Conservative 'grad-h' SPH (e.g. Springel & Hernquist 2002, Price & Monaghan 2004)
- `Density-independent' SPH (Saitoh & Makino 2013, Hopkins 2013)

- 1, 2 or 3 dimensions
- Barnes-Hut Octal tree for efficient neighbour finding and calculation of gravitational forces (Barnes & Hut 1986)
- Periodic boundary conditions (independent for each dimension)
- Ewald periodic gravity (Hernquist, Bouchet & Suto 1991, Klessen 1997)
- 2nd order Leapfrog kick-drift-kick and drift-kick-drift
- Block timesteps and neighbour-timestep checking for safety (Saitoh & Makino 2009)
- Various flavours of artificial dissipation :
- 'Riemann solver-based' artificial viscosity (Monaghan 1997)
- Time-dependent artificial viscosity (Morris & Monaghan 1997)
- Artificial conductivity (e.g. Price 2008)

- Sink particles (Bate, Bonnell & Price 1995) with smooth accretion (Hubber, Walch & Whitworth 2013)
- Various N-body algorithms and optimisations
- 4th-order Hermite integration, standard (Makino & Aarseth 1992) and time-symmetric (Hut, Makino & McMillan 1995)
- Automatic sub-system and binary identification algorithms
- Hybrid conservative SPH and N-body coupled integration ( Hubber, Allison, Smith & Goodwin 2013)

- Parallelized using OpenMP
- Produces output compatable with the SPLASH visualisation program.

## Current development

- Meshless Finite-Volume Hydrodynamics (Gaburov & Nitadori 2011, Hopkins 2015)
- MPI parallelization
- Improved sub-system integration

## Future development

- Ideal MHD (Price & Monaghan 2004)
- TreeCol (Clark, Glover & Klessen 2011) and TreeRay radiation cooling/transport algorithms