diff --git a/src/engine.c b/src/engine.c index ebd589bbb0af01cec3196c658c4d014daca8df38..a980bcbc9c2f42127fb43b30c7d5573a8e9957ef 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2411,17 +2411,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) { struct clocks_time time1, time2; clocks_gettime(&time1); - if (e->nodeID == 0) message("Initialising particles"); - - /* Make sure all particles are ready to go */ - /* i.e. clean-up any stupid state in the ICs */ - if (e->policy & engine_policy_hydro) { - space_map_cells_pre(s, 0, cell_init_parts, NULL); - } - if ((e->policy & engine_policy_self_gravity) || - (e->policy & engine_policy_external_gravity)) { - space_map_cells_pre(s, 0, cell_init_gparts, NULL); - } + if (e->nodeID == 0) message("Running initialisation fake time-step."); engine_prepare(e); diff --git a/src/gravity/Default/gravity.h b/src/gravity/Default/gravity.h index 5903ce1384f616a123c74b579539fe53747d17e4..755d4be527e4a81b2b4d2b3b829ea16a74ccc7c5 100644 --- a/src/gravity/Default/gravity.h +++ b/src/gravity/Default/gravity.h @@ -81,6 +81,9 @@ gravity_compute_timestep_self(const struct phys_const* const phys_const, */ __attribute__((always_inline)) INLINE static void gravity_first_init_gpart( struct gpart* gp) { + + gp->ti_begin = 0; + gp->ti_end = 0; gp->epsilon = 0.; // MATTHIEU } diff --git a/src/hydro/Default/hydro.h b/src/hydro/Default/hydro.h index 240696251e237e7bc3309857dda580aeff6b29ec..51e09a5d943a7f3782e484289faddece2567f15d 100644 --- a/src/hydro/Default/hydro.h +++ b/src/hydro/Default/hydro.h @@ -137,7 +137,15 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( * @param xp The extended particle data to act upon */ __attribute__((always_inline)) INLINE static void hydro_first_init_part( - struct part *restrict p, struct xpart *restrict xp) {} + struct part *restrict p, struct xpart *restrict xp) { + + p->ti_begin = 0; + p->ti_end = 0; + xp->v_full[0] = p->v[0]; + xp->v_full[1] = p->v[1]; + xp->v_full[2] = p->v[2]; + xp->u_full = p->u; +} /** * @brief Prepares a particle for the density calculation. diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h index dafec2939eebabcad809da8f75987618fae0c3f0..0573e48f414e62a8a824d2f76c1a56b4ecc01ecd 100644 --- a/src/hydro/Gadget2/hydro.h +++ b/src/hydro/Gadget2/hydro.h @@ -134,7 +134,14 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( * @param xp The extended particle data to act upon */ __attribute__((always_inline)) INLINE static void hydro_first_init_part( - struct part *restrict p, struct xpart *restrict xp) {} + struct part *restrict p, struct xpart *restrict xp) { + + p->ti_begin = 0; + p->ti_end = 0; + xp->v_full[0] = p->v[0]; + xp->v_full[1] = p->v[1]; + xp->v_full[2] = p->v[2]; +} /** * @brief Prepares a particle for the density calculation. diff --git a/src/hydro/Minimal/hydro.h b/src/hydro/Minimal/hydro.h index 1433136ad906beba491636716f38b98da2699b26..842a028b9031b3c1cf36e4735089d05e038abdca 100644 --- a/src/hydro/Minimal/hydro.h +++ b/src/hydro/Minimal/hydro.h @@ -145,6 +145,11 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( __attribute__((always_inline)) INLINE static void hydro_first_init_part( struct part *restrict p, struct xpart *restrict xp) { + p->ti_begin = 0; + p->ti_end = 0; + xp->v_full[0] = p->v[0]; + xp->v_full[1] = p->v[1]; + xp->v_full[2] = p->v[2]; xp->u_full = p->u; } diff --git a/src/space.c b/src/space.c index 8b7e5f81b539fb02da44dac67a3575356c08c45e..90dfe9c9fa84ebaa27b514a26f71fdc841935fed 100644 --- a/src/space.c +++ b/src/space.c @@ -43,6 +43,8 @@ #include "atomic.h" #include "engine.h" #include "error.h" +#include "gravity.h" +#include "hydro.h" #include "kernel_hydro.h" #include "lock.h" #include "minmax.h" @@ -1416,6 +1418,23 @@ struct cell *space_getcell(struct space *s) { return c; } +void space_init_parts(struct space *s) { + + const size_t nr_parts = s->nr_parts; + struct part *restrict p = s->parts; + struct xpart *restrict xp = s->xparts; + + for (size_t i = 0; i < nr_parts; ++i) hydro_first_init_part(&p[i], &xp[i]); +} + +void space_init_gparts(struct space *s) { + + const size_t nr_gparts = s->nr_gparts; + struct gpart *restrict gp = s->gparts; + + for (size_t i = 0; i < nr_gparts; ++i) gravity_first_init_gpart(&gp[i]); +} + /** * @brief Split the space into cells given the array of particles. * @@ -1549,6 +1568,10 @@ void space_init(struct space *s, const struct swift_params *params, bzero(s->xparts, Npart * sizeof(struct xpart)); } + /* Set the particles in a state where they are ready for a run */ + space_init_parts(s); + space_init_gparts(s); + /* Init the space lock. */ if (lock_init(&s->lock) != 0) error("Failed to create space spin-lock."); diff --git a/src/space.h b/src/space.h index 180759f2af69dd0d77e6e681229353358d554291..6fe3681c85068979a555ff1d78e32ba7577cf3f0 100644 --- a/src/space.h +++ b/src/space.h @@ -162,6 +162,8 @@ void space_split(struct space *s, struct cell *cells, int verbose); void space_do_split(struct space *s, struct cell *c); void space_do_parts_sort(); void space_do_gparts_sort(); +void space_init_parts(struct space *s); +void space_init_gparts(struct space *s); void space_link_cleanup(struct space *s); void space_clean(struct space *s); diff --git a/tests/test125cells.c b/tests/test125cells.c index 304b26ec94419bffdd04be3fc0361213d8b5a785..cbb3ec87c735164bb64a67d51e1f891a9030d50b 100644 --- a/tests/test125cells.c +++ b/tests/test125cells.c @@ -247,9 +247,6 @@ struct cell *make_cell(size_t n, const double offset[3], double size, double h, part->ti_begin = 0; part->ti_end = 1; - xpart->v_full[0] = part->v[0]; - xpart->v_full[1] = part->v[1]; - xpart->v_full[2] = part->v[2]; hydro_first_init_part(part, xpart); ++part; ++xpart;