Skip to content

Commit 3d2cea0

Browse files
authored
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.
1 parent d7d8372 commit 3d2cea0

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/festim/helpers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ def is_it_time_to_export(
324324
) -> bool:
325325
"""
326326
Checks if the exported field should be written to a file or not based on the
327-
current time and the times in `export.times`
327+
current time and the times in `export.times'
328+
329+
After a successful match, the corresponding time is removed from the list to
330+
prevent multiple exports for the same target time.
331+
328332
329333
Args:
330334
current_time: the current simulation time
@@ -337,14 +341,16 @@ def is_it_time_to_export(
337341
"""
338342
if times is None:
339343
return True
340-
341-
for time in times:
344+
345+
for i, time in enumerate(times):
342346
if np.isclose(time, current_time, atol=atol, rtol=rtol):
347+
times.pop(i) # consume the time so it is not exported again
343348
return True
344349

345350
return False
346351

347352

353+
348354
_residual0 = 0
349355
_prev_xnorm = 0
350356

0 commit comments

Comments
 (0)