diff --git a/src/black_holes/Default/black_holes_io.h b/src/black_holes/Default/black_holes_io.h index e193f550bfd100077c33abdf6bdfcedb74d829da..41ca7c1cd0b3542959d8a7372179c7e0cb285285 100644 --- a/src/black_holes/Default/black_holes_io.h +++ b/src/black_holes/Default/black_holes_io.h @@ -22,6 +22,20 @@ #include "black_holes_part.h" #include "io_properties.h" +INLINE static void convert_bpart_pos(const struct engine *e, + const struct bpart *bp, double *ret) { + + if (e->s->periodic) { + ret[0] = box_wrap(bp->x[0], 0.0, e->s->dim[0]); + ret[1] = box_wrap(bp->x[1], 0.0, e->s->dim[1]); + ret[2] = box_wrap(bp->x[2], 0.0, e->s->dim[2]); + } else { + ret[0] = bp->x[0]; + ret[1] = bp->x[1]; + ret[2] = bp->x[2]; + } +} + /** * @brief Specifies which b-particle fields to read from a dataset * @@ -37,8 +51,9 @@ INLINE static void black_holes_read_particles(struct bpart *bparts, *num_fields = 5; /* List what we want to read */ - list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, - UNIT_CONV_LENGTH, bparts, x); + list[0] = io_make_output_field_convert_bpart( + "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, bparts, convert_bpart_pos); + list[1] = io_make_input_field("Velocities", FLOAT, 3, COMPULSORY, UNIT_CONV_SPEED, bparts, v); list[2] = io_make_input_field("Masses", FLOAT, 1, COMPULSORY, UNIT_CONV_MASS, diff --git a/src/black_holes/EAGLE/black_holes_io.h b/src/black_holes/EAGLE/black_holes_io.h index cc6cb962db61f9e45ded990b9dca7f00db075733..f5a8da344ffe0d37564710b9ce9bc3e0d8f3d705 100644 --- a/src/black_holes/EAGLE/black_holes_io.h +++ b/src/black_holes/EAGLE/black_holes_io.h @@ -22,6 +22,20 @@ #include "black_holes_part.h" #include "io_properties.h" +INLINE static void convert_bpart_pos(const struct engine *e, + const struct bpart *bp, double *ret) { + + if (e->s->periodic) { + ret[0] = box_wrap(bp->x[0], 0.0, e->s->dim[0]); + ret[1] = box_wrap(bp->x[1], 0.0, e->s->dim[1]); + ret[2] = box_wrap(bp->x[2], 0.0, e->s->dim[2]); + } else { + ret[0] = bp->x[0]; + ret[1] = bp->x[1]; + ret[2] = bp->x[2]; + } +} + /** * @brief Specifies which b-particle fields to read from a dataset * @@ -66,8 +80,8 @@ INLINE static void black_holes_write_particles(const struct bpart *bparts, *num_fields = 12; /* List what we want to write */ - list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - bparts, x); + list[0] = io_make_output_field_convert_bpart( + "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, bparts, convert_bpart_pos); list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, bparts, v); list[2] = diff --git a/src/stars/Default/stars_io.h b/src/stars/Default/stars_io.h index 5ff57549b9d0db37d6929c1e9fbb8da8372d7e6c..a8ec1cfa55728f9ca8a348d8fd6ec07d06b72185 100644 --- a/src/stars/Default/stars_io.h +++ b/src/stars/Default/stars_io.h @@ -22,6 +22,20 @@ #include "io_properties.h" #include "stars_part.h" +INLINE static void convert_spart_pos(const struct engine *e, + const struct spart *sp, double *ret) { + + if (e->s->periodic) { + ret[0] = box_wrap(sp->x[0], 0.0, e->s->dim[0]); + ret[1] = box_wrap(sp->x[1], 0.0, e->s->dim[1]); + ret[2] = box_wrap(sp->x[2], 0.0, e->s->dim[2]); + } else { + ret[0] = sp->x[0]; + ret[1] = sp->x[1]; + ret[2] = sp->x[2]; + } +} + /** * @brief Specifies which s-particle fields to read from a dataset * @@ -64,8 +78,8 @@ INLINE static void stars_write_particles(const struct spart *sparts, *num_fields = 5; /* List what we want to write */ - list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - sparts, x); + list[0] = io_make_output_field_convert_spart( + "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, sparts, convert_spart_pos); list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v); list[2] = diff --git a/src/stars/EAGLE/stars_io.h b/src/stars/EAGLE/stars_io.h index 0c03bee3007066c7c51c7ce0fb3d88d37a1b2ae3..cfacd52106398f435e56a9a2a67d1016726e2295 100644 --- a/src/stars/EAGLE/stars_io.h +++ b/src/stars/EAGLE/stars_io.h @@ -23,6 +23,20 @@ #include "io_properties.h" #include "stars_part.h" +INLINE static void convert_spart_pos(const struct engine *e, + const struct spart *sp, double *ret) { + + if (e->s->periodic) { + ret[0] = box_wrap(sp->x[0], 0.0, e->s->dim[0]); + ret[1] = box_wrap(sp->x[1], 0.0, e->s->dim[1]); + ret[2] = box_wrap(sp->x[2], 0.0, e->s->dim[2]); + } else { + ret[0] = sp->x[0]; + ret[1] = sp->x[1]; + ret[2] = sp->x[2]; + } +} + /** * @brief Specifies which s-particle fields to read from a dataset * @@ -67,8 +81,8 @@ INLINE static void stars_write_particles(const struct spart *sparts, *num_fields = 10; /* List what we want to write */ - list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, - sparts, x); + list[0] = io_make_output_field_convert_spart( + "Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, sparts, convert_spart_pos); list[1] = io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, sparts, v); list[2] =