From 2a8584205481a81337c2e61b85a4fb917a65949a Mon Sep 17 00:00:00 2001
From: JM Etancelin <jean-matthieu.etancelin@univ-pau.fr>
Date: Wed, 8 Apr 2020 10:06:28 +0200
Subject: [PATCH] add simulation flag not to clamp to tend (avoid tiny and
 possibliy negative irrelevant dt)

---
 hysop/simulation.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/hysop/simulation.py b/hysop/simulation.py
index 9870ed7b2..ecf112e02 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
-- 
GitLab