Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pset.execute time management #1627

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=

tol = 1e-12
while (time < endtime and dt > 0) or (time > endtime and dt < 0) or 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

if dt > 0:
Expand All @@ -953,9 +958,10 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=

# 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:
Expand All @@ -973,6 +979,10 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
# 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 or dt == 0:
for fld in self.fieldset.get_fields():
if hasattr(fld, 'to_write') and fld.to_write:
Expand Down
Loading