diff --git a/parcels/particleset.py b/parcels/particleset.py index a5e058f11a..adeddc44b8 100644 --- a/parcels/particleset.py +++ b/parcels/particleset.py @@ -1158,6 +1158,12 @@ def execute( time = starttime while (time < endtime and dt > 0) or (time > endtime and dt < 0): + # Check if we can fast-forward to the next time needed for the particles + if dt > 0: + skip_kernel = True if min(self.time) > (time + dt) else False + else: + skip_kernel = True if max(self.time) < (time + dt) else False + time_at_startofloop = time next_input = self.fieldset.computeTimeChunk(time, dt) @@ -1170,9 +1176,10 @@ def execute( # If we don't perform interaction, only execute the normal kernel efficiently. if self._interaction_kernel is None: - res = self._kernel.execute(self, endtime=next_time, dt=dt) - if res == StatusCode.StopAllExecution: - return StatusCode.StopAllExecution + if not skip_kernel: + res = self._kernel.execute(self, endtime=next_time, dt=dt) + if res == StatusCode.StopAllExecution: + return StatusCode.StopAllExecution # Interaction: interleave the interaction and non-interaction kernel for each time step. # E.g. Normal -> Inter -> Normal -> Inter if endtime-time == 2*dt else: @@ -1188,6 +1195,10 @@ def execute( # End of interaction specific code time = next_time + # Check for empty ParticleSet + if np.isinf(next_prelease) and len(self) == 0: + return StatusCode.StopAllExecution + if abs(time - next_output) < tol: for fld in self.fieldset.get_fields(): if hasattr(fld, "to_write") and fld.to_write: