Interpolations over Shape Fitted Grids

I am trying to interpolate on a grid that is body fitted (in a Computational Fluid Dynamics context). The grid cannot be simply described by vectors describing the grid spacing in each dimensions, instead the points are simply represented by vectors x, y which are the same length as the number of data points in the grid. The output vector is then the same length as x, y.

To create a simple example, interpolating in a 1x1 box with arbitrarily located sample points:

# Some 2D function
f(x, y) = cos(8. * pi * x) + sin(4. * pi * y)

# 1000 (x, y) points
x_pts = rand(Float64, 1000)
y_pts = rand(Float64, 1000)

# Sample f at the generated points
output = f.(x_pts, y_pts)

# Now to generate an interpolator for this data

Ideally, I would just use the Interpolations.jl interpolate function, but AFAIK it wants rectilinear grids where the output matrix is of dimensions Nx, Ny. I can call the scipy.interpolate library and use something like the CloughTocher2DInterpolator, but I feel like this functionality, even just first-order interpolation, must exist in Julia but I just haven’t been able to find it.

Does Dierckx.jl do what you need?

If it is a finite-element mesh (e.g. a tetrahedral or quadrilateral mesh), then you could in principle use Gridap to interpolate using finite-element basis functions (e.g. first-order Lagrange elements to interpolate linearly from nodal values).

See also Interpolate 3d grid of datapoints

Ah yes, Dierckx.jl does actually do what I need. I had a go with that originally, but was misusing the smoothing parameter s so it give the behaviour I was expecting.

That looks like quite a neat library, I will give it a look. I want to extend it to 3 dimensions in the near future, which Dierckx doesn’t handle, so this might be the right tool for the job. Cheers.