diff --git a/src/engine.c b/src/engine.c index 44d04364da4df826745ff3f879a41871eac489af..f87e4eb6f7d0280582bdbc44db0784b1d32a8012 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2340,6 +2340,7 @@ void engine_dump_snapshot(struct engine *e, struct UnitSystem *us, struct clocks_time time1, time2; clocks_gettime(&time1); +/* Dump... */ #if defined(WITH_MPI) #if defined(HAVE_PARALLEL_HDF5) write_output_parallel(e, baseName, us, myrank, nr_nodes, MPI_COMM_WORLD, @@ -2356,6 +2357,9 @@ void engine_dump_snapshot(struct engine *e, struct UnitSystem *us, if (e->verbose) message("writing particle properties took %.3f %s.", (float)clocks_diff(&time1, &time2), clocks_getunit()); + + /* ... and find the next output time */ + engine_compute_next_snapshot_time(e); } #if defined(HAVE_LIBNUMA) && defined(_GNU_SOURCE) @@ -2426,6 +2430,7 @@ void engine_init(struct engine *e, struct space *s, parser_get_param_double(params, "Snapshots:time_first"); e->deltaTimeSnapshot = parser_get_param_double(params, "Snapshots:delta_time"); + e->ti_nextSnapshot = 0; e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min"); e->dt_max = parser_get_param_double(params, "TimeIntegration:dt_max"); e->file_stats = NULL; @@ -2716,3 +2721,25 @@ void engine_print_policy(struct engine *e) { fflush(stdout); #endif } + +/** + * @brief Computes the next time (on the time line) for a dump + * + * @param e The #engine. + */ +void engine_compute_next_snapshot_time(struct engine *e) { + + for (double time = e->timeFirstSnapshot; time < e->timeEnd; + time += e->deltaTimeSnapshot) { + + /* Output time on the integer timeline */ + e->ti_nextSnapshot = (time - e->timeBegin) / e->timeBase; + + if (e->ti_nextSnapshot > e->ti_current) break; + } + + /* Be nice, talk... */ + const float next_snapshot_time = + e->ti_nextSnapshot * e->timeBase + e->timeBegin; + if (e->verbose) message("Next output time set to t=%f", next_snapshot_time); +} diff --git a/src/engine.h b/src/engine.h index 8a6f3e04474d322f26457350170ad85166613d3b..ca262dc224e6cba77b68a9415a83cfd9f6bb203d 100644 --- a/src/engine.h +++ b/src/engine.h @@ -134,6 +134,7 @@ struct engine { /* Snapshot times */ double timeFirstSnapshot; double deltaTimeSnapshot; + int ti_nextSnapshot; /* File for statistics */ FILE *file_stats; @@ -185,6 +186,7 @@ struct engine { /* Function prototypes. */ void engine_barrier(struct engine *e, int tid); +void engine_compute_next_snapshot_time(struct engine *e); void engine_dump_snapshot(struct engine *e, struct UnitSystem *us, const char *baseName); void engine_init(struct engine *e, struct space *s,