Skip to content

Commit 05808ea

Browse files
committed
Adding a 'check if below the data' kernel to ensure we don't get OOB errors when particles are kicked below the test dataset.
1 parent b5c590c commit 05808ea

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

tests/test_kernels.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def make_standard_particleset(fieldset, settings):
3232

3333
return pset
3434

35+
def checkBelowDataDepth(particle, fieldset, time):
36+
# The vertical mixing kernel can push particles below the test dataset depth, throwing an
37+
# out of bounds error. This kernel will keep particles above the max depth.
38+
if particle.depth + particle_ddepth >= fieldset.max_depth:
39+
particle_ddepth = fieldset.max_depth - particle.depth - 0.5 # move half a meter above the max depth
40+
3541

3642
@pytest.mark.parametrize('use_3D', [True, False])
3743
def test_advection_only(use_3D):
@@ -215,22 +221,18 @@ def test_mixing():
215221
settings['use_stokes'] = False
216222

217223
fieldset = pp.constructors.create_fieldset(settings)
224+
fieldset.add_constant('max_depth', fieldset.U.depth[-1])
225+
218226
kernels = [parcels.application_kernels.AdvectionRK4_3D, pp.kernels.checkThroughBathymetry,
219227
pp.kernels.checkErrorThroughSurface, pp.kernels.deleteParticle]
220228

221229
kernels_mixing = [parcels.application_kernels.AdvectionRK4_3D, pp.kernels.VerticalMixing,
222-
pp.kernels.checkThroughBathymetry, pp.kernels.checkErrorThroughSurface,
223-
pp.kernels.deleteParticle]
230+
checkBelowDataDepth, pp.kernels.checkThroughBathymetry,
231+
pp.kernels.checkErrorThroughSurface, pp.kernels.deleteParticle]
224232

225233
pset = make_standard_particleset(fieldset, settings)
226234
pset_mixing = make_standard_particleset(fieldset, settings)
227235

228-
# Because vertical mixing can vertically push the particle large distances,
229-
# let's set the simulation time to 20 mins, and outputdt and dt to 10 mins
230-
settings['simulation']['runtime'] = timedelta(minutes=20)
231-
settings['simulation']['outputdt'] = timedelta(minutes=10)
232-
settings['simulation']['dt'] = timedelta(minutes=10)
233-
234236
pset.execute(kernels, runtime=settings['simulation']['runtime'], dt=settings['simulation']['dt'])
235237
pset_mixing.execute(kernels_mixing, runtime=settings['simulation']['runtime'], dt=settings['simulation']['dt'])
236238

0 commit comments

Comments
 (0)