Hi,
I'm writing a little post-processing procedure and need help avoiding a hefty for loop, which will typically require 1000^3 iterations.
Its purpose is to take data from a simulation, which expresses three components of a vector field at a different position s.t.
x - component is defined on cell boundary in x-direction, cell center in other directions (xb,yc,zc(
y - component is defined on cell boundary in y-direction, cell center in other directions (xc,yb,zc)
z - component is defined on cell boundary inz-direction, cell center in other directions (xc,yc,zb)
and express the field as defined in the cell center for all components (xc,yc,zc).
Rather than using interpolation, I think the best way will be to simply average the values across the cell face to head off errors down the line.
The problem is im not sure how to avoid a hefty for loop which goes through all elements taking the desired average as follows....
FUNCTION reformat_bcomponents_1,t
data = getdata(t,/BX,/BY,/BZ,/GRID)
bx = DBLARR(SIZE(data.x,/N_ELEMENTS),SIZE(data.y,/N_ELEMENTS),SIZ E(data.z,/N_ELEMENTS))
by = DBLARR(SIZE(data.x,/N_ELEMENTS),SIZE(data.y,/N_ELEMENTS),SIZ E(data.z,/N_ELEMENTS))
bz = DBLARR(SIZE(data.x,/N_ELEMENTS),SIZE(data.y,/N_ELEMENTS),SIZ E(data.z,/N_ELEMENTS))
FOR iz = 0,SIZE(data.z,/N_ELEMENTS) -1 DO BEGIN
FOR iy = 0,SIZE(data.y,/N_ELEMENTS) -1 DO BEGIN
FOR ix = 0,SIZE(data.x,/N_ELEMENTS) -1 DO BEGIN
bx[ix,iy,iz] = MEAN( [ data.bx[ix,iy,iz], data.bx[ix+1,iy,iz] ] ,/DOUBLE)
by[ix,iy,iz] = MEAN( [ data.by[ix,iy,iz], data.by[ix,iy+1,iz] ] ,/DOUBLE)
bz[ix,iy,iz] = MEAN( [ data.bz[ix,iy,iz], data.bz[ix,iy,iz+1] ] ,/DOUBLE)
ENDFOR
ENDFOR
ENDFOR
mag_str = CREATE_STRUCT('bxp',bx,'byp',by,'bzp',bz)
RETURN,mag_str
END
If anyone can point me in the direction of how to do this exploiting array operations I'd be grateful.
Thanks in advance,
Jonathan
|