Parcels version
v4
Description
Changing the particles.dt inside a kernel does not carry over to the next iteration in the Kernel loop. This can be unexpected for users.
Note that this is also why AdvectionRK45() requires the particles.next_dt parameter.
I don't see an easy solution for this Issue - as we don't inspect Kernel functions anymore in v4 we can't use that point to throw a warning if a user changes particles.dt. Perhaps it can be added in the ParticleSetView getattr?
Code sample
# Paste your code within this block
def test_dt_modify_in_kernel(fieldset):
TestParticle = Particle.add_variable(Variable("age", dtype=np.float32, initial=0))
pset = ParticleSet(fieldset, pclass=TestParticle, x=[0.5], y=[0])
def ModifyDt(particles, fieldset): # pragma: no cover
particles.age += particles.dt
particles.dt = 2
runtime = 10
expected_age = 1 + 2 * (runtime - 2) # 1 for the first step; 2 for the remaining steps (except last)
pset.execute(ModifyDt, runtime=runtime, dt=1.0)
np.testing.assert_allclose(pset.t[0], runtime)
np.testing.assert_allclose(pset.age[0], expected_age)
# Paste your error message within this block
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E Mismatched elements: 1 / 1 (100%)
E Max absolute difference among violations: 12.
E Max relative difference among violations: 0.70588235
E ACTUAL: array(5., dtype=float32)
E DESIRED: array(17)
Parcels version
v4
Description
Changing the
particles.dtinside a kernel does not carry over to the next iteration in the Kernel loop. This can be unexpected for users.Note that this is also why
AdvectionRK45()requires theparticles.next_dtparameter.I don't see an easy solution for this Issue - as we don't inspect Kernel functions anymore in v4 we can't use that point to throw a warning if a user changes
particles.dt. Perhaps it can be added in the ParticleSetView getattr?Code sample