# Interpolations over Shape Fitted Grids

**URL:** <https://discourse.julialang.org/t/interpolations-over-shape-fitted-grids/79033>\
**Category:** Data\
**Tags:** interpolations\
**Created:** [April 5, 2022, 5:56am UTC](https://discourse.julialang.org/t/interpolations-over-shape-fitted-grids/79033 "2022-04-05T05:56:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Whyborn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/whyborn/32/34755_2.png) [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Post date:** [April 5, 2022, 5:56am UTC](https://discourse.julialang.org/t/interpolations-over-shape-fitted-grids/79033/1 "2022-04-05T05:56:57Z")

</div>

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:

```julia
# 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.

---

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [April 5, 2022, 8:21pm UTC](https://discourse.julialang.org/t/interpolations-over-shape-fitted-grids/79033/2 "2022-04-05T20:21:46Z")

</div>

Does Dierckx.jl do what you need?  
[https://github.com/kbarbary/Dierckx.jl](https://github.com/kbarbary/Dierckx.jl)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 5, 2022, 8:32pm UTC](https://discourse.julialang.org/t/interpolations-over-shape-fitted-grids/79033/3 "2022-04-05T20:32:36Z")

</div>

> [@Whyborn](#):
>
> I am trying to **interpolate** on a grid that is body fitted (in a Computational Fluid Dynamics context).

If it is a finite-element mesh (e.g. a tetrahedral or quadrilateral mesh), then you could in principle use [Gridap to interpolate](https://gridap.github.io/Gridap.jl/stable/Fields/#Gridap.Fields.Field) using finite-element basis functions (e.g. first-order Lagrange elements to interpolate linearly from nodal values).

See also [Interpolate 3d grid of datapoints](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485)

---

<div class="post-metadata">

**Author:** ![Whyborn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/whyborn/32/34755_2.png) [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Post date:** [April 6, 2022, 12:04am UTC](https://discourse.julialang.org/t/interpolations-over-shape-fitted-grids/79033/4 "2022-04-06T00:04:23Z")

</div>

> [@tobydriscoll](#):
>
> Does Dierckx.jl do what you need?

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.

> [@stevengj](#):
>
> If it is a finite-element mesh (e.g. a tetrahedral or quadrilateral mesh), then you could in principle use [Gridap to interpolate](https://gridap.github.io/Gridap.jl/stable/Fields/#Gridap.Fields.Field) using finite-element basis functions (e.g. first-order Lagrange elements to interpolate linearly from nodal values).

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.
