Caching a large 3D interpolation using griddata()

3 views (last 30 days)
Jess
Jess on 4 Jul 2014
Edited: Matt J on 5 Jul 2014
I'm using griddata() to go from a spherical grid of sizes on the order (128x256x1500) to a Cartesian cube centered on the sphere, containing N^3 regularly-spaced points (where N is between 128 and 512). I need to do this for dozens or hundreds of checkpoints in my simulation, and several variables per checkpoint. I'm going to need to interpolate from the same spherical grid to the same cubic grid several hundred or several thousand times over, using new data on the spherical grid each time!
Since the most computationally expensive part of this routine is the triangulation and interpolation, I would like to cache some information the first time the routine is run and use that information for subsequent runs.
As far as I can tell, this is not possible using the current implementation of griddata(). Is there any way I could do something like this -- perhaps re-writing the griddata() routine?

Answers (1)

Matt J
Matt J on 5 Jul 2014
Edited: Matt J on 5 Jul 2014
In recent versions of MATLAB, you have scatteredInterpolant which pre-composes an interpolation object, so probably does some of the caching you're talking about. Beyond that, there is parfor in the Parallel Computing Toolbox, if you have it. You would probably have to be strategic about how you slice the input and output data, if you go that route.
  2 Comments
Jess
Jess on 5 Jul 2014
Thanks for your quick response!
The scatteredInterpolant class is not quite what I'm looking for, unfortunately. Suppose I have values (Y) defined on a set of points (X), and after interpolation I have (Y1) defined on (X1). The scatteredInterpolant class allows me to save X and Y, such that if I give it a new set of points (X1), it gives me a new set of interpolated values (Y1). It's saving information about the 3D function so that I can interpolate at several new points.
What I want do is to save information about the geometry. I want to re-use X and X1, such that I can give it a new Y and it will give me a new Y1.
Does this make sense?
Thanks again!
Matt J
Matt J on 5 Jul 2014
Edited: Matt J on 5 Jul 2014
It might be worthwhile having a look at FUNC2MAT. It will let you express the interpolation as a multiplication of Y(:) with a reusable sparse matrix that is (X,X1)-dependent. The computation of this matrix will be time-consuming, but if you'll be reusing it enough, it might be worth it. FUNC2MAT also lets you mitigate the matrix computation using the Parallel Computing Toolbox, if you have it.

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!