Skip to content

Commit d8e6def

Browse files
Adding rudimentary computeTimeChunck functionality in particleset.execute
1 parent 4e58b2a commit d8e6def

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

parcels/field.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __init__(
147147
_assert_compatible_combination(data, grid)
148148

149149
self.name = name
150-
self.data = data
150+
self.data_full = data
151151
self.grid = grid
152152

153153
try:
@@ -186,7 +186,7 @@ def __init__(
186186
else:
187187
raise ValueError("Unsupported mesh type in data array attributes. Choose either: 'spherical' or 'flat'")
188188

189-
if "time" not in self.data.dims:
189+
if "time" not in data.dims:
190190
raise ValueError("Field is missing a 'time' dimension. ")
191191

192192
@property
@@ -201,27 +201,27 @@ def units(self, value):
201201

202202
@property
203203
def xdim(self):
204-
if type(self.data) is xr.DataArray:
204+
if type(self.data_full) is xr.DataArray:
205205
return self.grid.xdim
206206
else:
207207
raise NotImplementedError("xdim not implemented for unstructured grids")
208208

209209
@property
210210
def ydim(self):
211-
if type(self.data) is xr.DataArray:
211+
if type(self.data_full) is xr.DataArray:
212212
return self.grid.ydim
213213
else:
214214
raise NotImplementedError("ydim not implemented for unstructured grids")
215215

216216
@property
217217
def zdim(self):
218-
if type(self.data) is xr.DataArray:
218+
if type(self.data_full) is xr.DataArray:
219219
return self.grid.zdim
220220
else:
221-
if "nz1" in self.data.dims:
222-
return self.data.sizes["nz1"]
223-
elif "nz" in self.data.dims:
224-
return self.data.sizes["nz"]
221+
if "nz1" in self.data_full.dims:
222+
return self.data_full.sizes["nz1"]
223+
elif "nz" in self.data_full.dims:
224+
return self.data_full.sizes["nz"]
225225
else:
226226
return 0
227227

parcels/particleset.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,10 +805,16 @@ def execute(
805805

806806
time = start_time
807807
while sign_dt * (time - end_time) < 0:
808+
809+
for fld in [self.fieldset.U, self.fieldset.V]: # TODO generalise to all fields
810+
ti = np.argmin(fld.data_full.time.data <= self._data["time_nextloop"][0]) - 1 # TODO also implement dt < 0
811+
if not hasattr(fld, "data") or fld.data_full.time.data[ti] != fld.data.time.data[0]:
812+
fld.data = fld.data_full.isel({"time": slice(ti, ti + 2)}).load()
813+
808814
if sign_dt > 0:
809-
next_time = end_time # TODO update to min(next_output, end_time) when ParticleFile works
815+
next_time = min(time + dt, end_time)
810816
else:
811-
next_time = end_time # TODO update to max(next_output, end_time) when ParticleFile works
817+
next_time = max(time - dt, end_time)
812818
res = self._kernel.execute(self, endtime=next_time, dt=dt)
813819
if res == StatusCode.StopAllExecution:
814820
return StatusCode.StopAllExecution

0 commit comments

Comments
 (0)