parcels
parcels copied to clipboard
Rewrite Particle loops to be over objects, instead of integers
Make the loops in Field
and FieldSet
that access Particles
(in particular those two classes; possibly others too) independent of of the order - hence: migrate loops like
for i in range(numerical):
new_value = array[i]
to either:
for obj in array:
new_value = obj
or:
for i, obj in enumerate(array):
new_array[i] = obj
This would simplify the integration of the linked list of nodes and the lists-of-arrays of particles (#862) later. This is because their indices are dynamic and could rearrange - a classic reason why to use iterators.
Thanks to @CKehl for bringing this up
@CKehl, I've been looking into this Issue, but I don't see where these problematic loops are. Can you point them out to me?
it's most likely in the 'Kernel', but those kind of loops exist in other classes too. Let me see where they are and collect them.
Following lines are relevant:
'for p in range(pset.size)' (kernel.py; l. 291 and 372)
list comprehension 'for i in range(pset.size)': (example_peninsula.py; ;. 150 and l. 187)
other examples that have list comprehensions in the style 'for i in range(pset.size)', where either i
or pset
is named differently
'for i in range(self.size)' and 'for i in range(pset[_new].size)' (particleset.py; l. 265 and l. 687 and l. 776)
generally problem: if particle.id is not the same as it's position in the list (e.g. due to deletion), this is prone to failure.
see #913 and follow-ups - issue resolved, progressively.