PHASTA / vtkpytools

Internal tools for using VTK
https://fluid.colorado.edu/wiki/index.php/VTKpytools
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Find itersections of discrete data on wall #60

Closed jrwrigh closed 3 years ago

jrwrigh commented 3 years ago

For creating profiles at specific non-spatially-defined locations (such as Re_theta), we need to find intersections of discrete data (wall-localized data normally) with the desired location.

Example: Given data:

x D
0 0.1
1 0.3
2 -0.1

, at what x locations does D = 0.2?

Possible solution: (from StackExchange)

def find_roots(x,y):
    s = np.abs(np.diff(np.sign(y))).astype(bool)
    return x[:-1][s] + np.diff(x)[s]/(np.abs(y[1:][s]/y[:-1][s])+1)

where s gives the indices where y changes sign. Then it performs linear interpolation at those locations. For the example problem (given x and D arrays), the solution would be find_roots(x, D-0.2).