python - How to extract a plane from a 3D variable in FiPy (3D to 2D) -


i have variable on 3d mesh , trying cut plan. surprised question hasn't been asked before, looks easy , common problem haven't found way. appreciate advice.


let's have parallelepiped 3x3x5 , trying extract z-plane.

from fipy import * numpy import * #describes 3x3x5 mesh nx = 3 ny = 3 nz = 5  dx = 1 dy = 1 dz = 1  #creates 3d mesh , 2d mesh store plane mesh3d = grid3d(dx, dy, dz, nx, ny, nz) mesh2d = grid2d(dx, dy, nx, ny) #defines same variable, in 3d , in 2d var2d = cellvariable(mesh = mesh2d) var3d = cellvariable(mesh = mesh3d)  #fills 3d matrix in xrange(nx*ny*nz*dx*dy*dz):     var3d[i] =  print var3d 

output:

[  0.   1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.  12.  13.  14.  15.  16.  17.  18.  19.  20.  21.  22.  23.  24.  25.  26.  27.  28.  29.  30.  31.  32.  33.  34.  35.  36.  37.  38.  39.  40.  41.  42.  43.  44.] 

the 3d variable looks correctly filled.

first, tried use way described @ link http://permalink.gmane.org/gmane.comp.python.fipy/1576

the call method of cellvariable enables interpolation set of coordinates passed in via call method (the call method accessed using parentheses in function call). returns set of values corresponding each of coordinates passed in. order argument determines order of interpolation.

i not sure of how actual works, understand should interpolate single plane 0 order, should extract exact value on specific plane. please correct me if wrong.

x3d, y3d, z3d = mesh3d.getcellcenters() x2d, y2d =  mesh2d.getcellcenters()  zcut in xrange(nz*dz):     var2d.setvalue(var3d((x2d, y2d, zcut * ones(var2d.getmesh().getnumberofcells())), order=0))     print "z-plane = %d" % zcut     print var2d  raw_input("press key close") 

strangely doesn't work. indexes ok odd ones copy of contiguous planes.

z-plane = 0 [ 0.  1.  2.  3.  4.  5.  6.  7.  8.] z-plane = 1 [ 0.  1.  2.  3.  4.  5.  6.  7.  8.] z-plane = 2 [ 18.  19.  20.  21.  22.  23.  24.  25.  26.] z-plane = 3 [ 18.  19.  20.  21.  22.  23.  24.  25.  26.] z-plane = 4 [ 36.  37.  38.  39.  40.  41.  42.  43.  44.] 

i think there must stupid mistake somewhere, have no clue. idea?

the cell centers located @ z=0.5, 1.5, 2.5, ... fipy doing it's best find nearest cells z=0, 1, 2, ...

try

var2d.setvalue(var3d((x2d, y2d,                        zcut * ones(var2d.mesh.numberofcells) + dx/2.), order=0)) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -