Hello Zebo,

I believe the problem here is that the setValue method requires a boolean mask 
indicating where to set the values. For example, the typical usage in 1D might 
set the value in every point of half the grid equal to one:

val.setValue(1, where=x>Npoints/2).


So, to fix your bug, please add a second argument specifying in which mesh 
points to apply the interpolated data.

I've created a more complete example here: 
https://gist.github.com/tkphd/2f8ac66fe2f883fee352


In your case, since the interpolation is in 2D, you might need to "shape" the 
boolean mask to match up to your mesh.


Hope that helps,

Trevor



Trevor Keller, Ph.D.
Materials Science and Engineering Division
National Institute of Standards and Technology
100 Bureau Dr. MS 8550; Gaithersburg, MD 20899
Office: 223/A131 or (301) 975-2889



________________________________
From: [email protected] <[email protected]> on behalf of Zebo LI 
<[email protected]>
Sent: Tuesday, September 8, 2015 9:50 PM
To: FIPY
Subject: How to combine scipy.interpolate.interp2d with fipy variables

Hi,

I am now working on a 2D problem, in which I need to couple a discretized 
region with a continuum region. The solution of the discretized region are 
values at individual points (Irregularly distributed). Now we need to define a 
fipy variable 'val'(continuous function), which matches the discretized 
solution. For this, I use the interpolation function scipy.interpolate.interp2d 
to generate a function 'f', which is based on the linear interpolation of those 
points. But when I try to use 'val.setValue' to set values for val, I got an 
error of "Invalid input data". The following is this piece of code:
for i in range(Npoints):
        xold[i] = Cl.item((i,0))
        yold[i] = Cl.item((i,1))
        zold[i] = np.log10(abs(CV.item(i)))                 ##Cl are the 
coordinates, CV are the values, they are initially defined as matrices
f = scipy.interpolate.interp2d(xold, yold, zold, kind='linear')         ##If I 
print f(1.5,2,3)[0], it gives me a double data due to interpolation
val.setValue(function(X,Y)[0])               ##This one does not work. val is 
the variable defined on certain mesh, X,Y =mesh.cellCenters

I wonder that is there anyone meet the same type of problems, and know how to 
solve it?

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

Reply via email to