diff --git a/examples/main.c b/examples/main.c
index 6422ccceef0a5f5c5f3b5acce9ba60b957986aac..e1df978109174778919f022718e079fe9798774d 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -375,8 +375,8 @@ int main(int argc, char *argv[]) {
   /* Initialize the space with these data. */
   if (myrank == 0) clocks_gettime(&tic);
   struct space s;
-  space_init(&s, params, dim, parts, gparts, Ngas, Ngpart, periodic, talking,
-             dry_run);
+  space_init(&s, params, dim, parts, gparts, Ngas, Ngpart, periodic,
+             with_self_gravity, talking, dry_run);
   if (myrank == 0) {
     clocks_gettime(&toc);
     message("space_init took %.3f %s.", clocks_diff(&tic, &toc),
diff --git a/src/space.c b/src/space.c
index 0af5009c9a33ac63851a479b82afca355186faac..19c0997421846d2fc0ce7cdcaa8eff76ffbcac5e 100644
--- a/src/space.c
+++ b/src/space.c
@@ -205,6 +205,12 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
         "Must have at least 3 cells in each spatial dimension when periodicity "
         "is switched on.");
 
+  /* Check if we have enough cells for gravity. */
+  if (s->gravity && (cdim[0] < 8 || cdim[1] < 8 || cdim[2] < 8))
+    error(
+        "Must have at least 8 cells in each spatial dimension when gravity "
+        "is switched on.");
+
 /* In MPI-Land, changing the top-level cell size requires that the
  * global partition is recomputed and the particles redistributed.
  * Be prepared to do that. */
@@ -1415,8 +1421,8 @@ struct cell *space_getcell(struct space *s) {
 
 void space_init(struct space *s, const struct swift_params *params,
                 double dim[3], struct part *parts, struct gpart *gparts,
-                size_t Npart, size_t Ngpart, int periodic, int verbose,
-                int dry_run) {
+                size_t Npart, size_t Ngpart, int periodic, int gravity,
+                int verbose, int dry_run) {
 
   /* Clean-up everything */
   bzero(s, sizeof(struct space));
@@ -1426,6 +1432,7 @@ void space_init(struct space *s, const struct swift_params *params,
   s->dim[1] = dim[1];
   s->dim[2] = dim[2];
   s->periodic = periodic;
+  s->gravity = gravity;
   s->nr_parts = Npart;
   s->size_parts = Npart;
   s->parts = parts;
diff --git a/src/space.h b/src/space.h
index d53c0f2a5784ef25654309741b4455e3dbcc3e0c..fdd90393e39fb1e6fb228cff20febbc92938a863 100644
--- a/src/space.h
+++ b/src/space.h
@@ -96,6 +96,9 @@ struct space {
   /* Is the space periodic? */
   int periodic;
 
+  /* Are we doing gravity? */
+  int gravity;
+
   /* General-purpose lock for this space. */
   swift_lock_type lock;
 
@@ -139,8 +142,8 @@ int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
                  double *shift);
 void space_init(struct space *s, const struct swift_params *params,
                 double dim[3], struct part *parts, struct gpart *gparts,
-                size_t Npart, size_t Ngpart, int periodic, int verbose,
-                int dry_run);
+                size_t Npart, size_t Ngpart, int periodic, int gravity,
+                int verbose, int dry_run);
 void space_map_cells_pre(struct space *s, int full,
                          void (*fun)(struct cell *c, void *data), void *data);
 void space_map_parts(struct space *s,