Dark energy perturbations in $N$-body simulations
  We present $N$-body simulations which are fully compatible with general
relativity, with dark energy consistently included at both the background and
perturbation level. We test our approach for dark energy parameterised as both
a fluid, and using the parameterised post-Friedmann (PPF) formalism. In most
cases, dark energy is very smooth relative to dark matter so that its leading
effect on structure formation is the change to the background expansion rate.
This can be easily incorporated into Newtonian $N$-body simulations by changing
the Friedmann equation. However, dark energy perturbations and relativistic
corrections can lead to differences relative to Newtonian $N$-body simulations
at the tens of percent level for scales $k < (10^{-3} \unicode{x2013}
10^{-2})\,\mathrm{Mpc}^{-1}$, and given the accuracy of upcoming large scale
structure surveys such effects must be included. In this paper we will study
both effects in detail and highlight the conditions under which they are
important. We also show that our $N$-body simulations exactly reproduce the
results of the Boltzmann solver CLASS for all scales which remain linear.
