CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   working with Field (http://www.cfd-online.com/Forums/openfoam-programming-development/103662-working-field.html)

anishtain4 June 22, 2012 12:18

working with Field
 
Assume you have a scalarField or vectorField named fi(K), and you want to compute its average value in a spherical shell with thickness of one, say:

sigma( magSqr(fi(K)) )
i-0.5<k<i+0.5
k=sqrt(sqr(kx)+sqr(ky)+sqr(kz))

I know you can make a loop or use forAll but this way's gonna check every label once for every shell and that is pretty time consuming. Is there any better way?

gschaider June 22, 2012 17:02

Quote:

Originally Posted by anishtain4 (Post 367879)
Assume you have a scalarField or vectorField named fi(K), and you want to compute its average value in a spherical shell with thickness of one, say:

sigma( magSqr(fi(K)) )
i-0.5<k<i+0.5
k=sqrt(sqr(kx)+sqr(ky)+sqr(kz))

I know you can make a loop or use forAll but this way's gonna check every label once for every shell and that is pretty time consuming. Is there any better way?

That is a basic programming: "memory usage buys performance" Create an array for the sums, one for every shell. Loop once over the cells. Find out to which shell the cell belongs. Increase that array. Of course you'll need a second array .... but that is left to the reader as an exercise


All times are GMT -4. The time now is 17:44.