On Sun, Aug 12, 2018 at 2:52 PM Drew Davidson <davidson...@gmail.com> wrote:
>
> I am posting because before I tried this, I was unable to find on this 
> mailing list a clear statement/warning that such an interpolation can run 
> slow (eat up computer time).  Is there a faster way to interpolate?

The call method to cell variable takes a nearestCellIDs argument which
can greatly speed up the interpolation if you're interpolating between
the same meshes multiple times. For adaptive meshing the meshes need
to retain knowledge of the adaptation to make the interpolation faster
otherwise a brute force technique is required. Scipy or Sklearn
probably has better algorithms for finding nearest neighbors so that
could be used to find the nearest neighbors instead of FiPy's method.
To use the nearestCellIDs argument, try this,

    import fipy

    m0 = fipy.Grid2D(nx=10, ny=10)
    m1 = fipy.Grid2D(nx=20, ny=10)

    v0 = fipy.CellVariable(mesh=m0, value= m0.x * m0.y)
    v1 = fipy.CellVariable(mesh=m1)

    # very slow and can be replaced
    ids = m0._getNearestCellID(m1.cellCenters)

    # should be fast at nearest neighbors are already calculated
    v1[:] = v0(points=m1.cellCenters, order=1, nearestCellIDs=ids)

    print v1

You could replace "_getNearestCellID" sklearn's,
http://scikit-learn.org/stable/modules/neighbors.html, without doing
anything to fipy. "ids" is just a numpy array.

> Google seemed to lead me to various interpolation tools, but I do not see a 
> way to take the data outside of FiPy to do the interpolation and then bring 
> the data back into FiPy.  I looked at the FiPy CellVariable source code but 
> it is beyond me to mess around with it.  It looked like it might run fast 
> since it seems to operate on only the nearest neighbors, but maybe it is 
> slowed down by having to do one cell at a time?

To get data out of fipy, you don't need to do much more than,

    import pandas
    pandas.DataFrame(dict(x=m1.x, y=m1.y, v=v1)).to_csv('test.csv')

for example. This will write the position and values of a cell
variable to a CSV file.

-- 
Daniel Wheeler

_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to