diff --git a/hysop/simulation.py b/hysop/simulation.py index 9870ed7b2a346db08d3c070cbc1f863aa43b5ddf..ecf112e028542456201101a22245794137e1bc1c 100644 --- a/hysop/simulation.py +++ b/hysop/simulation.py @@ -47,7 +47,7 @@ class Simulation(object): def __init__(self, name=None, start=0.0, end=1.0, nb_iter=None, dt0=None, max_iter=None, t=None, dt=None, times_of_interest=None, - mpi_params=None, quiet=False, + mpi_params=None, quiet=False, clamp_t_to_end=True, **kwds): """ Parameters @@ -76,6 +76,8 @@ class Simulation(object): time dependent dumping. tstart < ti <= tend Defaults to empty set. + clamp_t_to_end : bool, optional + Specify if Simulation adjst dt for last iteration to have t=end Attributes ---------- @@ -114,6 +116,7 @@ class Simulation(object): self.current_iteration = -1 self._rank = main_rank if mpi_params is None else mpi_params.rank self._comm = main_comm if mpi_params is None else mpi_params.comm + self.clamp_t_to_end = clamp_t_to_end if (nb_iter is not None): self.nb_iter = nb_iter @@ -258,13 +261,14 @@ class Simulation(object): self.update_time_step(self.target_time_of_interest - self.t()) self._last_forced_timestep = self.dt() elif (self.tkp1 >= self.end): - msg = '** Next iteration is last iteration, clamping dt to achieve t={}. **' - msg = msg.format(self.end) - vprint() - self._print_banner(msg) self._next_is_last = True - self.tkp1 = self.end - self.update_time_step(self.end - self.t()) + if self.clamp_t_to_end: + msg = '** Next iteration is last iteration, clamping dt to achieve t={}. **' + msg = msg.format(self.end) + vprint() + self._print_banner(msg) + self.tkp1 = self.end + self.update_time_step(self.end - self.t()) elif (self.dt() == self._last_forced_timestep): self.update_time_step(self._dt0) self._last_forced_timestep = None