diff --git a/src/space.c b/src/space.c index 268f4f3525292ca2bfd08c3f6e5357e9fdb2947b..f94b7cf8f3565413793c16caa5bde26feef58dec 100644 --- a/src/space.c +++ b/src/space.c @@ -1166,6 +1166,30 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) { /* Allocate extra space for particles that will be created */ if (s->with_star_formation) space_allocate_extras(s, verbose); + if (s->dithering) { + + /* Store the old dithering vector */ + s->pos_dithering_old[0] = s->pos_dithering[0]; + s->pos_dithering_old[1] = s->pos_dithering[1]; + s->pos_dithering_old[2] = s->pos_dithering[2]; + + if (s->e->nodeID == 0) { + + /* Compute the new dithering vector */ + s->pos_dithering[0] = + s->dithering_ratio * s->width[0] * rand() / ((double)RAND_MAX); + s->pos_dithering[1] = + s->dithering_ratio * s->width[1] * rand() / ((double)RAND_MAX); + s->pos_dithering[2] = + s->dithering_ratio * s->width[2] * rand() / ((double)RAND_MAX); + +#ifdef WITH_MPI + /* Tell everyone what value to use */ + MPI_Bcast(s->pos_dithering, 3, MPI_DOUBLE, 0, MPI_COMM_WORLD); +#endif + } + } + struct cell *cells_top = s->cells_top; const integertime_t ti_current = (s->e != NULL) ? s->e->ti_current : 0; const int local_nodeID = s->e->nodeID; @@ -4650,6 +4674,9 @@ void space_init(struct space *s, struct swift_params *params, s->sum_bpart_vel_norm = 0.f; s->nr_queues = 1; /* Temporary value until engine construction */ + /* Initialise some randomness */ + srand(42); + /* Are we generating gas from the DM-only ICs? */ if (generate_gas_in_ics) { space_generate_gas(s, cosmo, periodic, dim, verbose); diff --git a/src/space.h b/src/space.h index 7347df8336fea38d05b275acb4cb04fb7f1a872a..9d93b823f5e657558b1cae58da1df34a391ef1da 100644 --- a/src/space.h +++ b/src/space.h @@ -123,6 +123,9 @@ struct space { time (value at the previous rebuild) */ double pos_dithering_old[3]; + /*! Max dithering distance in units of the top-level cell sizes */ + double dithering_ratio; + /*! The minimum top-level cell width allowed. */ double cell_min;