diff --git a/src/engine.c b/src/engine.c index 2fd463347c758ae518b3c7151a6b22ffea330806..c14f5c1af5ac72364fe71cc55c2b7323db2cc177 100644 --- a/src/engine.c +++ b/src/engine.c @@ -4133,6 +4133,26 @@ void engine_launch(struct engine *e) { clocks_getunit()); } +/** + * @brief Calls the 'first init' function on the particles of all types. + * + * @param e The #engine. + */ +void engine_first_init_particles(struct engine *e) { + + const ticks tic = getticks(); + + /* Set the particles in a state where they are ready for a run */ + space_first_init_parts(e->s, e->chemistry); + space_first_init_xparts(e->s, e->cooling_func); + space_first_init_gparts(e->s, e->gravity_properties); + space_first_init_sparts(e->s); + + if (e->verbose) + message("took %.3f %s.", clocks_from_ticks(getticks() - tic), + clocks_getunit()); +} + /** * @brief Initialises the particles and set them in a state ready to move *forward in time. @@ -4152,26 +4172,11 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs, clocks_gettime(&time1); /* Start by setting the particles in a good state */ - ticks my_tic = getticks(); - if (e->nodeID == 0) message("first init..."); - /* Set the particles in a state where they are ready for a run */ - space_first_init_parts(s, e->chemistry); - space_first_init_xparts(s, e->cooling_func); - space_first_init_gparts(s); - space_first_init_sparts(s); - if (e->verbose) - message("took %.3f %s.", clocks_from_ticks(getticks() - my_tic), - clocks_getunit()); + if (e->nodeID == 0) message("Setting particles to a valid state..."); + engine_first_init_particles(e); if (e->nodeID == 0) message("Computing initial gas densities."); - /* Initialise the softening lengths */ - if (e->policy & engine_policy_self_gravity) { - - for (size_t i = 0; i < s->nr_gparts; ++i) - gravity_init_softening(&s->gparts[i], e->gravity_properties); - } - /* Construct all cells and tasks to start everything */ engine_rebuild(e, clean_h_values); @@ -4245,7 +4250,9 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs, if (e->nodeID == 0) scheduler_write_dependencies(&e->sched, e->verbose); /* Run the 0th time-step */ + TIMER_TIC2; engine_launch(e); + TIMER_TOC2(timer_runners); #ifdef SWIFT_GRAVITY_FORCE_CHECKS /* Check the accuracy of the gravity calculation */ diff --git a/src/gravity/Default/gravity.h b/src/gravity/Default/gravity.h index 1eee6e678288a209b669c46f7c87fbb5c399b6c7..94192321440cd6fcb49722a5c69f1f121f24cd1e 100644 --- a/src/gravity/Default/gravity.h +++ b/src/gravity/Default/gravity.h @@ -147,27 +147,15 @@ gravity_reset_predicted_values(struct gpart* gp) {} * read in to do some conversions. * * @param gp The particle to act upon + * @param grav_props The global properties of the gravity calculation. */ __attribute__((always_inline)) INLINE static void gravity_first_init_gpart( - struct gpart* gp) { + struct gpart* gp, const struct gravity_props* grav_props) { gp->time_bin = 0; - gp->epsilon = 0.f; + gp->epsilon = grav_props->epsilon; gravity_init_gpart(gp); } -/** - * @brief Initialises the softening of the g-particles - * - * @param gp The particle to act upon. - * @param grav_props The properties of the gravity scheme. - */ -__attribute__((always_inline)) INLINE static void gravity_init_softening( - struct gpart* gp, const struct gravity_props* grav_props) { - - /* Note 3 is the Plummer-equivalent correction */ - gp->epsilon = grav_props->epsilon; -} - #endif /* SWIFT_DEFAULT_GRAVITY_H */ diff --git a/src/space.c b/src/space.c index c772f86a083230fcc3a6cc1c9659dfd815b2fd2c..9e3bd998d82a8dcef851f67c9a39c024a464ef94 100644 --- a/src/space.c +++ b/src/space.c @@ -2618,6 +2618,7 @@ void space_synchronize_particle_positions(struct space *s) { * @brief Initialises all the particles by setting them into a valid state * * Calls hydro_first_init_part() on all the particles + * Calls chemistry_first_init_part() on all the particles */ void space_first_init_parts(struct space *s, const struct chemistry_data *chemistry) { @@ -2673,7 +2674,8 @@ void space_first_init_xparts(struct space *s, * * Calls gravity_first_init_gpart() on all the particles */ -void space_first_init_gparts(struct space *s) { +void space_first_init_gparts(struct space *s, + const struct gravity_props *grav_props) { const size_t nr_gparts = s->nr_gparts; struct gpart *restrict gp = s->gparts; @@ -2690,7 +2692,7 @@ void space_first_init_gparts(struct space *s) { gp[i].v_full[1] = gp[i].v_full[2] = 0.f; #endif - gravity_first_init_gpart(&gp[i]); + gravity_first_init_gpart(&gp[i], grav_props); #ifdef SWIFT_DEBUG_CHECKS gp->ti_drift = 0; diff --git a/src/space.h b/src/space.h index 3edf81b50ea14bc9400fa9091ec369fffee15e82..06faf6bb7f25cce4b4a7799d6990d1618480349c 100644 --- a/src/space.h +++ b/src/space.h @@ -30,11 +30,11 @@ #include <stddef.h> /* Includes. */ +#include "gravity_properties.h" #include "hydro_space.h" #include "lock.h" #include "parser.h" #include "part.h" -#include "space.h" /* Avoid cyclic inclusions */ struct cell; @@ -227,7 +227,8 @@ void space_first_init_parts(struct space *s, const struct chemistry_data *chemistry); void space_first_init_xparts(struct space *s, const struct cooling_function_data *cool_func); -void space_first_init_gparts(struct space *s); +void space_first_init_gparts(struct space *s, + const struct gravity_props *grav_props); void space_first_init_sparts(struct space *s); void space_init_parts(struct space *s, int verbose); void space_init_gparts(struct space *s, int verbose);