diff --git a/examples/main.c b/examples/main.c index 42419d7896298de8ecbcea462b16b599934d08a3..0f30668da6a1c2d308c1c51ded4d8c963fe0df8d 100644 --- a/examples/main.c +++ b/examples/main.c @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) { case 'd': if (sscanf(optarg, "%f", &dt_min) != 1) error("Error parsing minimal timestep."); - if (myrank == 0) message("dt_min set to %e.", dt_max); + if (myrank == 0) message("dt_min set to %e.", dt_min); fflush(stdout); break; case 'e': @@ -194,8 +194,8 @@ int main(int argc, char *argv[]) { with_outputs = 0; break; case 'P': - /* Partition type is one of "g", "m", "w", or "v"; "g" can be - * followed by three numbers defining the grid. */ +/* Partition type is one of "g", "m", "w", or "v"; "g" can be + * followed by three numbers defining the grid. */ #ifdef WITH_MPI switch (optarg[0]) { case 'g': @@ -487,7 +487,7 @@ int main(int argc, char *argv[]) { "[ms]\n"); /* Let loose a runner on the space. */ - for (j = 0; e.time < time_end; j++) { + for (j = 0; !engine_is_done(&e); j++) { /* Repartition the space amongst the nodes? */ #ifdef WITH_MPI diff --git a/src/engine.c b/src/engine.c index 18068f8e9a2ff30eeffec35f7bd60252f17d373e..993320b48a43da8e0503b70602a41701f8c4831e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -286,7 +286,6 @@ void engine_redistribute(struct engine *e) { #endif } - /** * @brief Repartition the cells amongst the nodes. * @@ -1394,7 +1393,7 @@ void engine_init_particles(struct engine *e) { struct space *s = e->s; - if(e->nodeID == 0) message("Initialising particles"); + 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 */ @@ -1631,6 +1630,13 @@ void engine_step(struct engine *e) { // printParticle(e->s->parts, e->s->xparts,515050, e->s->nr_parts); } +/** + * @brief Returns 1 if the simulation has reached its end point, 0 otherwise + */ +int engine_is_done(struct engine *e) { + return !(e->ti_current < max_nr_timesteps); +} + /** * @brief Create and fill the proxies. * @@ -1837,7 +1843,7 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads, int home = numa_node_of_cpu(sched_getcpu()), half = nr_cores / 2; bool done = false, swap_hyperthreads = hyperthreads_present(); if (swap_hyperthreads && nodeID == 0) - message("prefer physical cores to hyperthreads"); + message("prefer physical cores to hyperthreads"); while (!done) { done = true; @@ -1934,15 +1940,25 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads, engine_print_policy(e); /* Print information about the hydro scheme */ - if (e->nodeID == 0) - message("Hydrodynamic scheme: %s", SPH_IMPLEMENTATION); + if (e->nodeID == 0) message("Hydrodynamic scheme: %s", SPH_IMPLEMENTATION); + + /* Check we have sensible time bounds */ + if (timeBegin >= timeEnd) + error( + "Final simulation time (t_end = %e) must be larger than the start time " + "(t_beg = %e)", + timeEnd, timeBegin); + + /* Check we have sensible time step bounds */ + if (e->dt_min > e->dt_max) + error( + "Minimal time step size must be smaller than maximal time step size "); /* Deal with timestep */ e->timeBase = (timeEnd - timeBegin) / max_nr_timesteps; e->ti_current = 0; - if (e->nodeID == 0) - message("Absolute minimal timestep size: %e", e->timeBase); + /* Fixed time-step case */ if ((e->policy & engine_policy_fixdt) == engine_policy_fixdt) { e->dt_min = e->dt_max; @@ -1953,11 +1969,32 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads, e->dt_min = e->dt_max = dti_timeline * e->timeBase; if (e->nodeID == 0) message("Timestep set to %e", e->dt_max); + } else { + + if (e->nodeID == 0) { + message("Absolute minimal timestep size: %e", e->timeBase); + + float dt_min = timeEnd - timeBegin; + while (dt_min > e->dt_min) dt_min /= 2.f; + + message("Minimal timestep size (on time-line): %e", dt_min); + + float dt_max = timeEnd - timeBegin; + while (dt_max > e->dt_max) dt_max /= 2.f; + + message("Maximal timestep size (on time-line): %e", dt_max); + } } if (e->dt_min < e->timeBase && e->nodeID == 0) - error("Minimal timestep smaller than the absolue possible minimum dt=%e", - e->timeBase); + error( + "Minimal time-step size smaller than the absolute possible minimum " + "dt=%e", + e->timeBase); + + if (e->dt_max > (e->timeEnd - e->timeBegin) && e->nodeID == 0) + error("Maximal time-step size larger than the simulation run time t=%e", + e->timeEnd - e->timeBegin); /* Construct types for MPI communications */ #ifdef WITH_MPI diff --git a/src/engine.h b/src/engine.h index 13c7ec40612713d3771543150763da6924144c1a..cd189f6ac64b0809eec7f9db8cba898a6377cf27 100644 --- a/src/engine.h +++ b/src/engine.h @@ -63,7 +63,6 @@ extern const char *engine_policy_names[]; #define engine_maxproxies 64 #define engine_tasksreweight 10 - /* The rank of the engine as a global variable (for messages). */ extern int engine_rank; @@ -186,5 +185,6 @@ void engine_makeproxies(struct engine *e); void engine_redistribute(struct engine *e); struct link *engine_addlink(struct engine *e, struct link *l, struct task *t); void engine_print_policy(struct engine *e); +int engine_is_done(struct engine *e); #endif /* SWIFT_ENGINE_H */