def picker(self, pos, time, gvel_out=None, nearest=False): """ Extract fluid velocity and pressure from .vtu files at correct time level""" data, alpha, names = self.system.temporal_cache(time) TemporalCache.PICKERS[0].name = names[0][0] TemporalCache.PICKERS[0].grid = IO.get_block(data[0][2], names[0][0]) TemporalCache.PICKERS[0].locator = data[0][3] TemporalCache.PICKERS[0].pos = numpy.asarray(pos, float) TemporalCache.PICKERS[1].name = names[1][0] TemporalCache.PICKERS[1].grid = IO.get_block(data[1][2], names[1][0]) TemporalCache.PICKERS[1].locator = data[1][3] TemporalCache.PICKERS[1].pos = numpy.asarray(pos, float) if len(names[0]) == 3: vel0, grad_p0, gvel_0 = self._fpick(pos, data[0][2], TemporalCache.PICKERS[0], names[0], nearest) vel1, grad_p1, gvel_1 = self._fpick(pos, data[1][2], TemporalCache.PICKERS[1], names[1], nearest) else: vel0, grad_p0 = self._fpick(pos, data[0][2], TemporalCache.PICKERS[0], names[0], nearest) vel1, grad_p1 = self._fpick(pos, data[1][2], TemporalCache.PICKERS[1], names[1], nearest) if vel0 is None or vel1 is None: return None, None if gvel_out: gvel_out = (1.0 - alpha) * gvel_0 + alpha * gvel_1 return ((1.0 - alpha) * vel0 + alpha * vel1, (1.0 - alpha) * grad_p0 + alpha * grad_p1)
def get_velocity(self, pos, time): """ Get the velocity value from the cache at a given position and time.""" data, alpha, names = self(time) data[0][3].BuildLocatorIfNeeded() data[1][3].BuildLocatorIfNeeded() PICKERS[0].name = names[0][0] PICKERS[0].grid = IO.get_block(data[0][2], names[0][0]) PICKERS[0].locator = data[0][3] PICKERS[0].pos = pos PICKERS[1].name = names[1][0] PICKERS[1].grid = IO.get_block(data[1][2], names[1][0]) PICKERS[1].locator = data[1][3] PICKERS[1].pos = pos vel0 = PICKERS[0].nearest(pos) vel1 = PICKERS[1].nearest(pos) if vel0 is None or vel1 is None: raise ValueError # otherwise return alpha * vel1 + (1.0 - alpha) * vel0