From 3d2cea03679e899d71534b38e7a5737ddcb89b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Lleal=20Sirvent?= Date: Mon, 23 Feb 2026 11:47:59 +0100 Subject: [PATCH] Fix: prevent duplicate exports by popping matched time in is_it_time_to_export This updates `is_it_time_to_export` so that when a timestep matches a desired export time (within the `np.isclose` tolerances), the corresponding entry in `times` is popped. Previously, multiple consecutive timesteps within the tolerance window could all trigger `True`, leading to repeated exports for the same target time, especially at high simulation times where the relative tolerance (rtol) allows larger absolute differences. With this change: - only the first matching timestep triggers an export - the matched time is removed, preventing any subsequent exports for it This ensures a 1-to-1 mapping between requested and actual exports, provided the simulation reaches timesteps sufficiently close to the target times. --- src/festim/helpers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/festim/helpers.py b/src/festim/helpers.py index 53e2cf700..c0bb6f2c6 100644 --- a/src/festim/helpers.py +++ b/src/festim/helpers.py @@ -324,7 +324,11 @@ def is_it_time_to_export( ) -> bool: """ Checks if the exported field should be written to a file or not based on the - current time and the times in `export.times` + current time and the times in `export.times' + + After a successful match, the corresponding time is removed from the list to + prevent multiple exports for the same target time. + Args: current_time: the current simulation time @@ -337,14 +341,16 @@ def is_it_time_to_export( """ if times is None: return True - - for time in times: + + for i, time in enumerate(times): if np.isclose(time, current_time, atol=atol, rtol=rtol): + times.pop(i) # consume the time so it is not exported again return True return False + _residual0 = 0 _prev_xnorm = 0