1

I'm using the griddata() command in MATLAB to go from a spherical grid of sizes on the order (128x256x1500) to a Cartesian cubic grid, centered on the sphere and 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.

I think I could probably cache a table of vertex indices and associated interpolation weights for every point on the cubic grid, but I'm not sure how/where to do this....

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?

jvriesem
  • 1,859
  • 3
  • 18
  • 40
  • have you looked into [`scatteredInterpolant`](http://www.mathworks.com/help/matlab/ref/scatteredinterpolant-class.html): first you build the interpolant which fits the surface of the sample points (performed once), then you can evaluate it multiple times on different query points – Amro Jul 04 '14 at 23:40
  • Thanks for your response! It's 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. – jvriesem Jul 05 '14 at 00:05
  • 1
    I see, I'm afraid I don't know of a function that does that.. It sounds to me like you want to implement a sort of [memoization](https://en.wikipedia.org/wiki/Memoization) – Amro Jul 05 '14 at 15:15
  • Yeah, that would work. Compute it once, use it many times. – jvriesem Jul 05 '14 at 15:43
  • 1
    Here is a [blog post](http://blogs.mathworks.com/loren/2006/02/08/use-nested-functions-to-memoize-costly-functions/) that might help you get started with this idea, there are many [other](http://www.mathworks.com/matlabcentral/fileexchange/33068-a-multidimensional-map-class) [resources](http://stackoverflow.com/q/11178367/97160) out [there](http://stackoverflow.com/q/5023998/97160).. – Amro Jul 05 '14 at 15:53
  • Epilogue: What I ended up doing was writing a routine to do everything in Fortran-90 using manual trilinear interpolation rather than using tetrahedra or QHULL. It read in the spherical data and then looked for a particular data file (a cache of the interpolating coefficients and indices for all points). If the file was found, it loaded it into memory. If it wasn't found, it called a routine to calculate this information, then saved the resulting arrays in a cache file for a subsequent program execution and kept the arrays in RAM for the next iteration/checkpoint. – jvriesem Jul 13 '16 at 17:40

0 Answers0