Skip to content

Commit b09927e

Browse files
Merge pull request #1073 from AdriaLlealS/duplicate-times-fix
Fix: prevent duplicate exports by popping matched time in is_it_time_…
2 parents d7d8372 + 74c28a6 commit b09927e

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/festim/exports/profile_1d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
self.t = []
4646
self.x = None
4747
self.subdomain = subdomain
48-
self.times = times
48+
self.times = times.copy() if times is not None else None
4949

5050
self._dofs = None
5151
self._sort_coords = None

src/festim/helpers.py

Lines changed: 7 additions & 2 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
@@ -338,8 +342,9 @@ def is_it_time_to_export(
338342
if times is None:
339343
return True
340344

341-
for time in times:
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

0 commit comments

Comments
 (0)