diff --git a/src/engine.c b/src/engine.c index 3f02b85f2b881522c8ff887a58b9813a7dd4d27b..35efcb1dafb1e50cfae9f418905d08715c171bbf 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3527,10 +3527,9 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs, /* Print the number of active tasks ? */ if (e->verbose) engine_print_task_counts(e); - /* Init the particle hydro data (by hand). */ - for (size_t k = 0; k < s->nr_parts; k++) - hydro_init_part(&s->parts[k], &e->s->hs); - for (size_t k = 0; k < s->nr_gparts; k++) gravity_init_gpart(&s->gparts[k]); + /* Init the particle data (by hand). */ + space_init_parts(s, e->verbose); + space_init_gparts(s, e->verbose); /* Now, launch the calculation */ TIMER_TIC; @@ -3542,9 +3541,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs, if (e->nodeID == 0) message("Converting internal energy variable."); - /* Apply the conversion */ - for (size_t i = 0; i < s->nr_parts; ++i) - hydro_convert_quantities(&s->parts[i], &s->xparts[i]); + space_convert_quantities(e->s, e->verbose); /* Correct what we did (e.g. in PE-SPH, need to recompute rho_bar) */ if (hydro_need_extra_init_loop) { @@ -3577,10 +3574,9 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs, /* No drift this time */ engine_skip_drift(e); - /* Init the particle hydro data (by hand). */ - for (size_t k = 0; k < s->nr_parts; k++) - hydro_init_part(&s->parts[k], &e->s->hs); - for (size_t k = 0; k < s->nr_gparts; k++) gravity_init_gpart(&s->gparts[k]); + /* Init the particle data (by hand). */ + space_init_parts(e->s, e->verbose); + space_init_gparts(e->s, e->verbose); /* Print the number of active tasks ? */ if (e->verbose) engine_print_task_counts(e); diff --git a/src/space.c b/src/space.c index c9db8c84ac3a04c2fc82fcce620e14dc2070b107..160952f05eabe3f39ecb96717cbc2edc668b23e2 100644 --- a/src/space.c +++ b/src/space.c @@ -2551,7 +2551,7 @@ void space_synchronize_particle_positions(struct space *s) { * * Calls hydro_first_init_part() on all the particles */ -void space_init_parts(struct space *s) { +void space_first_init_parts(struct space *s) { const size_t nr_parts = s->nr_parts; struct part *restrict p = s->parts; @@ -2583,7 +2583,7 @@ void space_init_parts(struct space *s) { * * Calls cooling_init_xpart() on all the particles */ -void space_init_xparts(struct space *s) { +void space_first_init_xparts(struct space *s) { const size_t nr_parts = s->nr_parts; struct part *restrict p = s->parts; @@ -2600,7 +2600,7 @@ void space_init_xparts(struct space *s) { * * Calls gravity_first_init_gpart() on all the particles */ -void space_init_gparts(struct space *s) { +void space_first_init_gparts(struct space *s) { const size_t nr_gparts = s->nr_gparts; struct gpart *restrict gp = s->gparts; @@ -2631,7 +2631,7 @@ void space_init_gparts(struct space *s) { * * Calls star_first_init_spart() on all the particles */ -void space_init_sparts(struct space *s) { +void space_first_init_sparts(struct space *s) { const size_t nr_sparts = s->nr_sparts; struct spart *restrict sp = s->sparts; @@ -2657,6 +2657,62 @@ void space_init_sparts(struct space *s) { } } +/** + * @brief Calls the #part initialisation function on all particles in the space. + * + * @param s The #space. + * @param verbose Are we talkative? + */ +void space_init_parts(struct space *s, int verbose) { + + const ticks tic = getticks(); + + for (size_t k = 0; k < s->nr_parts; k++) + hydro_init_part(&s->parts[k], &s->hs); + + if (verbose) + message("took %.3f %s.", clocks_from_ticks(getticks() - tic), + clocks_getunit()); +} + +/** + * @brief Calls the #gpart initialisation function on all particles in the + * space. + * + * @param s The #space. + * @param verbose Are we talkative? + */ +void space_init_gparts(struct space *s, int verbose) { + + const ticks tic = getticks(); + + for (size_t k = 0; k < s->nr_gparts; k++) gravity_init_gpart(&s->gparts[k]); + + if (verbose) + message("took %.3f %s.", clocks_from_ticks(getticks() - tic), + clocks_getunit()); +} + +/** + * @brief Calls the #part quantities conversion function on all particles in the + * space. + * + * @param s The #space. + * @param verbose Are we talkative? + */ +void space_convert_quantities(struct space *s, int verbose) { + + const ticks tic = getticks(); + + /* Apply the conversion */ + for (size_t i = 0; i < s->nr_parts; ++i) + hydro_convert_quantities(&s->parts[i], &s->xparts[i]); + + if (verbose) + message("took %.3f %s.", clocks_from_ticks(getticks() - tic), + clocks_getunit()); +} + /** * @brief Split the space into cells given the array of particles. * @@ -2845,11 +2901,15 @@ void space_init(struct space *s, const struct swift_params *params, hydro_space_init(&s->hs, s); + ticks tic = getticks(); + message("first init..."); /* Set the particles in a state where they are ready for a run */ - space_init_parts(s); - space_init_xparts(s); - space_init_gparts(s); - space_init_sparts(s); + space_first_init_parts(s); + space_first_init_xparts(s); + space_first_init_gparts(s); + space_first_init_sparts(s); + message("took %.3f %s.", clocks_from_ticks(getticks() - tic), + clocks_getunit()); /* 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 1ea841affece7b4863edf20468d1d71caec93ab8..c49dc37dc0df27cd3647044f219e36c299dcd73b 100644 --- a/src/space.h +++ b/src/space.h @@ -221,9 +221,9 @@ void space_synchronize_particle_positions(struct space *s); void space_do_parts_sort(); void space_do_gparts_sort(); void space_do_sparts_sort(); -void space_init_parts(struct space *s); -void space_init_gparts(struct space *s); -void space_init_sparts(struct space *s); +void space_init_parts(struct space *s, int verbose); +void space_init_gparts(struct space *s, int verbose); +void space_convert_quantities(struct space *s, int verbose); void space_link_cleanup(struct space *s); void space_check_drift_point(struct space *s, integertime_t ti_drift, int multipole);