parcels
parcels copied to clipboard
Remove FieldSet.add_constant() method?
Now that we don't support JIT in v4, there is also no need anymore for fieldset.add_constant; because a Kernel will inherit variables from the function in which it was called.
For example, the following test from v3
def test_fieldset_constant():
data, dimensions = generate_fieldset_data(100, 100)
fieldset = FieldSet.from_data(data, dimensions)
westval = -0.2
eastval = 0.3
fieldset.add_constant("movewest", westval)
fieldset.add_constant("moveeast", eastval)
assert fieldset.movewest == westval
pset = ParticleSet.from_line(fieldset, size=1, pclass=Particle, start=(0.5, 0.5), finish=(0.5, 0.5))
pset.execute(pset.Kernel(addConst), dt=1, runtime=1)
Can in v4 work as
def test_fieldset_inherit_constant(fieldset):
movewest, moveeast = -0.2, 0.3
def addConst(particles, fieldset): # pragma: no cover
particles.lon += movewest + moveeast
pset = ParticleSet(fieldset, lon=(0.5, 0.5), lat=(0.5, 0.5))
pset.execute(addConst, dt=np.timedelta64(1, "s"), runtime=np.timedelta64(1, "s"))
So the question is whether we still need an explicit FieldSet.add_constant() method
Didn't know the context surrounding this function - agreed that I think it can be removed!