CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

working with Field

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 22, 2012, 12:18
Default working with Field
  #1
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18
anishtain4 is on a distinguished road
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?
anishtain4 is offline   Reply With Quote

Old   June 22, 2012, 17:02
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anishtain4 View Post
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
gschaider is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting an external B0_x field in MHD module fferroni FLUENT 11 August 1, 2022 08:20
funkySetBoundaryFields - Manipulation of existing field jhertel OpenFOAM Pre-Processing 16 May 18, 2020 06:32
chtMultiRegionFoam - exchange data between flow field and temperature phsieh2005 OpenFOAM Running, Solving & CFD 0 February 7, 2012 09:16
How to get the velocity field from the pressure field Hermano Main CFD Forum 2 November 29, 2011 08:32
Differences between serial and parallel runs carsten OpenFOAM Bugs 11 September 12, 2008 11:16


All times are GMT -4. The time now is 08:29.