Skip to content

Commit e7a8f86

Browse files
Throwing an error when dt has too high precision
1 parent a0ea404 commit e7a8f86

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

docs/examples/example_globcurrent.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,22 @@ def test_globcurrent_pset_fromfile(mode, dt, pid_offset, tmpdir):
260260

261261
for var in ['lon', 'lat', 'depth', 'time', 'id']:
262262
assert np.allclose([getattr(p, var) for p in pset], [getattr(p, var) for p in pset_new])
263+
264+
265+
@pytest.mark.parametrize('mode', ['scipy', 'jit'])
266+
def test_error_outputdt_not_multiple_dt(mode, tmpdir):
267+
# Test that outputdt is a multiple of dt
268+
fieldset = set_globcurrent_fieldset()
269+
270+
filepath = tmpdir.join("pfile_error_outputdt_not_multiple_dt.zarr")
271+
272+
dt = 81.2584344538292 # number for which output writing fails
273+
274+
pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[0], lat=[0])
275+
ofile = pset.ParticleFile(name=filepath, outputdt=delta(days=1))
276+
277+
def DoNothing(particle, fieldset, time):
278+
pass
279+
280+
with pytest.raises(ValueError):
281+
pset.execute(DoNothing, runtime=delta(days=10), dt=dt, output_file=ofile)

parcels/particleset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,10 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
878878
runtime = runtime.total_seconds()
879879
if isinstance(dt, delta):
880880
dt = dt.total_seconds()
881-
if dt > 0 and dt <= 1e-6:
881+
if abs(dt) <= 1e-6:
882882
raise ValueError('Time step dt is too small')
883+
if dt*1e6 % 1 != 0:
884+
raise ValueError('Output interval should not have finer precision than 1e-6 s')
883885
outputdt = output_file.outputdt if output_file else np.infty
884886
if isinstance(outputdt, delta):
885887
outputdt = outputdt.total_seconds()

0 commit comments

Comments
 (0)