@@ -212,13 +212,14 @@ def eval(self, time: datetime, z, y, x, particles=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 particles is None :
216+ _ei = None
217+ else :
218+ _ei = particles .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 (particles , position , self )
222223 _update_particle_states_position (particles , 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, particles=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 particles is None :
300+ _ei = None
301+ else :
302+ _ei = particles .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 (particles , position , self )
304307 _update_particle_states_position (particles , position )
305308
306309 if self ._vector_interp_method is None :
@@ -339,6 +342,26 @@ 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+ if isinstance (field .grid , XGrid ):
349+ particles .ei [:, field .igrid ] = field .grid .ravel_index (
350+ {
351+ "X" : position ["X" ][0 ],
352+ "Y" : position ["Y" ][0 ],
353+ "Z" : position ["Z" ][0 ],
354+ }
355+ )
356+ elif isinstance (field .grid , UxGrid ):
357+ particles .ei [:, field .igrid ] = field .grid .ravel_index (
358+ {
359+ "Z" : position ["Z" ][0 ],
360+ "FACE" : position ["FACE" ][0 ],
361+ }
362+ )
363+
364+
342365def _update_particle_states_position (particles , position ):
343366 """Update the particle states based on the position dictionary."""
344367 if particles : # TODO also support uxgrid search
0 commit comments