@@ -212,13 +212,14 @@ def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
212212 conversion to the result. Note that we defer to
213213 scipy.interpolate to perform spatial interpolation.
214214 """
215- # if particle is None:
216- _ei = None
217- # else:
218- # _ei = particle.ei[self.igrid]
215+ if particle is None :
216+ _ei = None
217+ else :
218+ _ei = particle .ei [:, self .igrid ]
219219
220220 tau , ti = _search_time_index (self , time )
221221 position = self .grid .search (z , y , x , ei = _ei )
222+ _update_particles_ei (particle , position , self )
222223 _update_particle_states_position (particle , position )
223224
224225 value = self ._interp_method (self , ti , position , tau , time , z , y , x )
@@ -251,6 +252,7 @@ def __init__(
251252 self .V = V
252253 self .W = W
253254 self .grid = U .grid
255+ self .igrid = U .igrid
254256
255257 if W is None :
256258 _assert_same_time_interval ((U , V ))
@@ -294,13 +296,14 @@ def eval(self, time: datetime, z, y, x, particle=None, applyConversion=True):
294296 conversion to the result. Note that we defer to
295297 scipy.interpolate to perform spatial interpolation.
296298 """
297- # if particle is None:
298- _ei = None
299- # else:
300- # _ei = particle.ei[self.igrid]
299+ if particle is None :
300+ _ei = None
301+ else :
302+ _ei = particle .ei [:, self .igrid ]
301303
302304 tau , ti = _search_time_index (self .U , time )
303305 position = self .grid .search (z , y , x , ei = _ei )
306+ _update_particles_ei (particle , position , self )
304307 _update_particle_states_position (particle , position )
305308
306309 if self ._vector_interp_method is None :
@@ -339,6 +342,18 @@ def __getitem__(self, key):
339342 return _deal_with_errors (error , key , vector_type = self .vector_type )
340343
341344
345+ def _update_particles_ei (particles , position , field ):
346+ """Update the element index (ei) of the particles"""
347+ if particles is not None :
348+ particles .ei [:, field .igrid ] = field .grid .ravel_index (
349+ {
350+ "X" : position ["X" ][0 ],
351+ "Y" : position ["Y" ][0 ],
352+ "Z" : position ["Z" ][0 ],
353+ }
354+ )
355+
356+
342357def _update_particle_states_position (particle , position ):
343358 """Update the particle states based on the position dictionary."""
344359 if particle : # TODO also support uxgrid search
0 commit comments