From ea0c9ca3cce8cf992bd12ec16dd4607bd8c0334a Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Tue, 14 Jun 2016 17:43:35 +0100 Subject: [PATCH] Make sure we have at least 8 cells on a side when using gravity --- examples/main.c | 4 ++-- src/space.c | 11 +++++++++-- src/space.h | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/main.c b/examples/main.c index 6422ccceef..e1df978109 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 0af5009c9a..19c0997421 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 d53c0f2a57..fdd90393e3 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, -- GitLab