diff --git a/src/common_io.c b/src/common_io.c index 2ad47f12beec32d0f3532c4107e4317f2c403ca4..fc524bacdb65b11b48e7f4299b55ac96a56f4759 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -545,7 +545,8 @@ static long long cell_count_non_inhibited_black_holes(const struct cell* c) { return count; } -void io_write_cell_offsets(hid_t h_grp, const int cdim[3], +void io_write_cell_offsets(hid_t h_grp, const int cdim[3], const double dim[3], + const double pos_dithering[3], const struct cell* cells_top, const int nr_cells, const double width[3], const int nodeID, const long long global_counts[swift_type_count], @@ -601,6 +602,17 @@ void io_write_cell_offsets(hid_t h_grp, const int cdim[3], centres[i * 3 + 1] = cells_top[i].loc[1] + cell_width[1] * 0.5; centres[i * 3 + 2] = cells_top[i].loc[2] + cell_width[2] * 0.5; + /* Undo the dithering since the particles will have this vector applied to + * them */ + centres[i * 3 + 0] = centres[i * 3 + 0] - pos_dithering[0]; + centres[i * 3 + 1] = centres[i * 3 + 1] - pos_dithering[1]; + centres[i * 3 + 2] = centres[i * 3 + 2] - pos_dithering[2]; + + /* Finish by box wrapping to match what is done to the particles */ + centres[i * 3 + 0] = box_wrap(centres[i * 3 + 0], 0.0, dim[0]); + centres[i * 3 + 1] = box_wrap(centres[i * 3 + 1], 0.0, dim[1]); + centres[i * 3 + 2] = box_wrap(centres[i * 3 + 2], 0.0, dim[2]); + /* Count real particles that will be written */ count_part[i] = cell_count_non_inhibited_gas(&cells_top[i]); count_gpart[i] = cell_count_non_inhibited_dark_matter(&cells_top[i]); diff --git a/src/common_io.h b/src/common_io.h index de73db3476eeefa1ca6db869ebb4f4de1bbb8906..024d6027c5cad097ece9ff820dda73055229ddbc 100644 --- a/src/common_io.h +++ b/src/common_io.h @@ -86,7 +86,8 @@ void io_write_attribute_s(hid_t grp, const char* name, const char* str); void io_write_code_description(hid_t h_file); void io_write_engine_policy(hid_t h_file, const struct engine* e); -void io_write_cell_offsets(hid_t h_grp, const int cdim[3], +void io_write_cell_offsets(hid_t h_grp, const int cdim[3], const double dim[3], + const double pos_dithering[3], const struct cell* cells_top, const int nr_cells, const double width[3], const int nodeID, const long long global_counts[swift_type_count], diff --git a/src/parallel_io.c b/src/parallel_io.c index 804013f1dd762491142c6e0aa472435c387bced5..154ec442c6435188874b0087a65150f84f6d7f03 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -1477,9 +1477,9 @@ void write_output_parallel(struct engine* e, const char* baseName, } /* Write the location of the particles in the arrays */ - io_write_cell_offsets(h_grp_cells, e->s->cdim, e->s->cells_top, - e->s->nr_cells, e->s->width, mpi_rank, N_total, offset, - internal_units, snapshot_units); + io_write_cell_offsets(h_grp_cells, e->s->cdim, e->s->dim, e->s->pos_dithering, + e->s->cells_top, e->s->nr_cells, e->s->width, mpi_rank, + N_total, offset, internal_units, snapshot_units); /* Close everything */ if (mpi_rank == 0) { diff --git a/src/serial_io.c b/src/serial_io.c index e291bf49ec18aa09f4fe96b7665a6120212e4ee7..9efa2e81aa42d8b71198d7e8a8c8991003f8a2cb 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -1157,9 +1157,9 @@ void write_output_serial(struct engine* e, const char* baseName, } /* Write the location of the particles in the arrays */ - io_write_cell_offsets(h_grp_cells, e->s->cdim, e->s->cells_top, - e->s->nr_cells, e->s->width, mpi_rank, N_total, offset, - internal_units, snapshot_units); + io_write_cell_offsets(h_grp_cells, e->s->cdim, e->s->dim, e->s->pos_dithering, + e->s->cells_top, e->s->nr_cells, e->s->width, mpi_rank, + N_total, offset, internal_units, snapshot_units); /* Close everything */ if (mpi_rank == 0) { diff --git a/src/single_io.c b/src/single_io.c index 6385b85988f90c29e6d99ed5f38944a1556611e6..05ccfa8fde3f55cf226f18dae35818ee2575f437 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -937,9 +937,10 @@ void write_output_single(struct engine* e, const char* baseName, if (h_grp < 0) error("Error while creating cells group"); /* Write the location of the particles in the arrays */ - io_write_cell_offsets(h_grp, e->s->cdim, e->s->cells_top, e->s->nr_cells, - e->s->width, e->nodeID, N_total, global_offsets, - internal_units, snapshot_units); + io_write_cell_offsets(h_grp, e->s->cdim, e->s->dim, e->s->pos_dithering, + e->s->cells_top, e->s->nr_cells, e->s->width, e->nodeID, + N_total, global_offsets, internal_units, + snapshot_units); H5Gclose(h_grp); /* Tell the user if a conversion will be needed */