comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Can my big for loop exploit array operations?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Can my big for loop exploit array operations? [message #92147] Tue, 20 October 2015 05:35 Go to previous message
JTMHD is currently offline  JTMHD
Messages: 9
Registered: October 2014
Junior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Manipulation of array
Next Topic: IDL equivalent to MATLAB's linkaxes

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:32:40 PDT 2025

Total time taken to generate the page: 0.00453 seconds