Skip to content

Commit 8f9e9d4

Browse files
Merge pull request #1627 from OceanParcels/pset_execute_time_management
Improve pset.execute time management
2 parents e91a571 + 35c4f2c commit 8f9e9d4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

parcels/particleset.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,12 @@ def execute(
11581158
time = starttime
11591159

11601160
while (time < endtime and dt > 0) or (time > endtime and dt < 0):
1161+
# Check if we can fast-forward to the next time needed for the particles
1162+
if dt > 0:
1163+
skip_kernel = True if min(self.time) > (time + dt) else False
1164+
else:
1165+
skip_kernel = True if max(self.time) < (time + dt) else False
1166+
11611167
time_at_startofloop = time
11621168

11631169
next_input = self.fieldset.computeTimeChunk(time, dt)
@@ -1170,9 +1176,10 @@ def execute(
11701176

11711177
# If we don't perform interaction, only execute the normal kernel efficiently.
11721178
if self._interaction_kernel is None:
1173-
res = self._kernel.execute(self, endtime=next_time, dt=dt)
1174-
if res == StatusCode.StopAllExecution:
1175-
return StatusCode.StopAllExecution
1179+
if not skip_kernel:
1180+
res = self._kernel.execute(self, endtime=next_time, dt=dt)
1181+
if res == StatusCode.StopAllExecution:
1182+
return StatusCode.StopAllExecution
11761183
# Interaction: interleave the interaction and non-interaction kernel for each time step.
11771184
# E.g. Normal -> Inter -> Normal -> Inter if endtime-time == 2*dt
11781185
else:
@@ -1188,6 +1195,10 @@ def execute(
11881195
# End of interaction specific code
11891196
time = next_time
11901197

1198+
# Check for empty ParticleSet
1199+
if np.isinf(next_prelease) and len(self) == 0:
1200+
return StatusCode.StopAllExecution
1201+
11911202
if abs(time - next_output) < tol:
11921203
for fld in self.fieldset.get_fields():
11931204
if hasattr(fld, "to_write") and fld.to_write:

0 commit comments

Comments
 (0)