Hi All,

I'd like overlay the trace of a non-interfering particle on top of a vector 
field plot. Specifically, I'd like to add the particle trace to the quiver plot 
of the cavity driven flow example. To do so, I need to interpolate the 
particle's position to the velocity vector's positions at: 
mesh.faceCenters.value. 
Then use the velocity at that position to update the particle's velocity.

Initially, I was going to define my own function to find the index of the 
closest face center:
>>> def findNearestIndex(array, point):    
…               return (numpy.abs(array-point)).argmin()

Which works for 1D arrays:
array = mesh.faceCenters.value[0]
point = 0.5

However, there can be multiple face centers with the same x coordinate. And 
when I try 2D with this function, I believe the argmin() flattens the data 
rendering the output of the function useless for this application.

x = array([11,12,13])
y = array([21,22,23])
array = zip(x,y)
point = array([12,22])

>>> numpy.abs(array-point)
array([[ 1.,  1.],
       [ 0.,  0.],
       [ 1.,  1.]])

>>> findNearestIndex(array,point)
array([2])

where index of 2 corresponds to the first 0 when flattened. So, this method 
didn't work as it sits, but it's possible to fix.


Then I considered looking through fipy>fipy>tools>numerix for any numerix 
functions that may already do this. The functions I found that interested me 
were:
numerix.nearest()
numerix.take()

However, when I use numerix.nearest I don't get the expected result:
>>> numerix.nearest(x, [12.])
array([0])

which I'd expect to see array([1]).

Also, if I try numerix with the 2D set of information given by the cell 
centers, I get a result I don't understand. (I made a really large cell volume 
mesh in a 1x1unit square box. The cell center values are:
>>> mesh.cellCenters.value
array([[ 0.25      ,  0.08333333,  0.91666667,  0.75      ,  0.41666667,
         0.25      ,  0.58333333,  0.25      ,  0.75      ,  0.75      ,
         0.41666667,  0.58333333,  0.25      ,  0.91666667,  0.08333333,
         0.75      ],
       [ 0.91666667,  0.25      ,  0.75      ,  0.08333333,  0.75      ,
         0.58333333,  0.75      ,  0.41666667,  0.58333333,  0.41666667,
         0.25      ,  0.25      ,  0.08333333,  0.25      ,  0.75      ,
         0.91666667]])

When I call:
>>> numerix.nearest(mesh.cellCenters.value, [.3])
array([18])

I don't understand the result of 18 being the index if the length of each 
component of mesh.cellCenters.value is 16. So, it seems the biggest problem 
here is that I don't fully understand the use of numerix.nearest(). But, if 
numerix.nearest did work, then I would have used numerix.take() to get the 
value of the velocity vector given the indices from numerix.nearest().

In sum, I'll continue to try and develop my own bit of code to do this and try 
to understand numerix.nearest better. And, please let me know if anyone has 
some tips of advice towards the success of this.

Thank you,
Ryan Smith
_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to