|
[Sponsors] |
[swak4Foam] Calculate statistics for a cellSet with swak4Foam |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 3, 2013, 16:38 |
Calculate statistics for a cellSet with swak4Foam
|
#1 |
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
I have a cellSet that I wan't to perform some simple statistics on (as post not while the calculation is running), e.g. compute the mean and standard deviation of temperature on a set of cells. I'd rather do this with an OF'ish tool as my experiences haven't been too positive with Paraview in this regard. Also this something I'd like to automated so OF lends itself to this well.
It seems swak4Foam - with funkyDoCalc or possible the new funkyPythonPostProc - should do the trick but not quite sure how to do this. I suppose this is question is for you Bernhard - just a gentle nudging in the right direction would be helpful. Thanks, Chris |
|
September 3, 2013, 19:11 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
The absolutely easiest thing would be a new utility Code:
fieldReport T -doSets -time 0: -nrOfQuantiles 4 -distributionDirectory TDistributions -csvName Tdata.csv What it doesn't do is calculate the standard-deviation. Instead with the nrOfQuantiles 4 it calculates the values for which 25%, 50% (==Median) and 75% of the values are smaller (further discussion of the feature see below). That utility is fine if you only need single numbers and want to post-process them yourself. And it might give you more numbers than you wanted (BTW: most numbers come in two variations. Unweighted or weighted - in this case with the cell size) With funkyDoCalc you only get the numbers you asked for and you are more flexible. In the simplest case you write something like this in a dictionary (I'm doing this from memory so some keywords might be wrong - I only write this stuff. This doesn't mean that I know how to use it) Code:
THeater { valueType cellSet; setName theHeater; expression "T"; accumulations ( min max average weightedAverage weightedQuantile0.25 weightedQuantile0.75 ); } Code:
THeaterDev { valueType cellSet; setName theHeater; expression "sqrt(TSqAvg-TAvg*TAvg)"; variables ( "totalVolume=sum(vol());" "TAvg=sum(T*vol())/totalVolume;" "TSqAvg=sum(T*T*vol())/totalVolume;" ); accumulations ( min // doesn't matter. The expression should be uniform ); }
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
September 4, 2013, 11:42 |
|
#3 |
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
Bernard,
Good thing all I asked for was a "nudging" ... wow! Thanks for the super detailed reply. fieldReports will get me what I want right now and I'll migrate to using funkyDoCalc for future calculations. funkyPythonPostProc looks beautiful. Had I known about it before I could have used it on a project I just finished up where I was doing some non-linear LSQ regressions using lmfit (which uses scipy.optimize.leastsq under the hood). I think it might have saved me the pain of using Paraview to strip away the regions of interest. -Chris |
|
September 4, 2013, 13:32 |
|
#4 | ||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Quote:
But feel free to experiment. I'd appreciate any feedback before roling it into a release
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|||
September 5, 2013, 10:44 |
|
#5 | |
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
Quote:
Code:
--> FOAM Warning : ^[[?1034h--> FOAM Warning : From function pythonInterpreterWrapper::importLib(const word &name) in file pythonInterpreterWrapper.C at line 830 Could not import IPython in "::adaptRelaxation" --> FOAM Warning : From function pythonInterpreterWrapper::pythonInterpreterWrapper in file pythonInterpreterWrapper.C at line 76 Importing of IPython failed. Falling back to regular shell for "::adaptRelaxation" --> FOAM Warning : From function pythonInterpreterWrapper::importLib(const word &name) in file pythonInterpreterWrapper.C at line 830 Could not import rlcompleter in "::adaptRelaxation" --> FOAM Warning : From function pythonInterpreterWrapper::pythonInterpreterWrapper in file pythonInterpreterWrapper.C at line 334 No dictionary 'importLibs' found in "::adaptRelaxation" -Chris |
||
September 5, 2013, 12:02 |
|
#6 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
But if you set Code:
interactiveAfterExecute true; Code:
import sys print sys.version print sys.path import rlcompleter import IPython print IPython.__version__ Also make sure that the libraries you set with the SWAK_PYTHON_LINK-variable in swakConfiguaration point to the "right" libs (I don't know a sure-fire recipe to find that out). My suspicion is that the linked python is not the same Python that the libs are installed for (if you can't import sys then we're in deep trouble. But I'm confident. After rlcompleter the code imports readline and THAT seems to work - or you didn't bother me with that warning)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
September 5, 2013, 12:31 |
|
#7 | |||
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
Quote:
Quote:
Code:
>>> import sys >>> print sys.version 2.6.6 (r266:84292, May 27 2013, 05:35:12) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] >>> print sys.path ['/usr/lib/python2.6/site-packages/pip-1.3.1-py2.6.egg', '/usr/lib/python2.6/site-packages/lmfit-0.7.2-py2.6.egg', '/usr/lib64/python2.6/site-packages/openmpi', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib64/python2.6/site-packages/wx-2.8-gtk2-unicode', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info', '/usr/lib/python2.6/site-packages/IPython/Extensions'] >>> import rlcompleter >>> import IPython Traceback (most recent call last): File "test", line 1, in <module> File "/usr/lib/python2.6/site-packages/IPython/__init__.py", line 58, in <module> __import__(name,glob,loc,[]) File "/usr/lib/python2.6/site-packages/IPython/Shell.py", line 37, in <module> from IPython import ultraTB, ipapi File "/usr/lib/python2.6/site-packages/IPython/ultraTB.py", line 93, in <module> from IPython import Debugger, PyColorize, ipapi File "/usr/lib/python2.6/site-packages/IPython/Debugger.py", line 34, in <module> from IPython import PyColorize, ColorANSI, ipapi ImportError: cannot import name PyColorize >>> print IPython.__version__ Traceback (most recent call last): File "test", line 1, in <module> NameError: name 'IPython' is not defined Code:
>>> import sys >>> print sys.version 2.6.6 (r266:84292, May 27 2013, 05:35:12) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] >>> print sys.path ['', '/usr/lib/python2.6/site-packages/pip-1.3.1-py2.6.egg', '/usr/lib/python2.6/site-packages/lmfit-0.7.2-py2.6.egg', '/usr/lib64/python2.6/site-packages/openmpi', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib64/python2.6/site-packages/wx-2.8-gtk2-unicode', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info'] >>> import rlcompleter >>> import IPython >>> print IPython.__version__ 0.10 >>> Quote:
|
||||
September 5, 2013, 13:22 |
|
#8 | |||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Good news (or probably bad): you're not alone
Quote:
Quote:
Quote:
Yep. The rlcompleter lead me to this. Sorry for doubting you. The thing is: exactly the same thing happens to me on my CentOS-machine. The story is the following: usually I develop new stuff on my MacBook (where Python and all are shiny and new). Additionally I test it on a virtual Ubüntü-machine. And when all is stable I test it on the Workstation in the office (with the conservative but stable CentOSG). I DID test a previous version on the CentOS machines. I somehow fixed that problem but it seems the intermediate updates have broken it again. The problem is that the old IPython on RHEL-machines behaves a bit differently from the current one (I'm not sure. But the thing is that IPython is rather terminal-oriented and the old version doesn'T seem to like it if initialized with no terminal in sight. Fun fact: if you set 'useIPython false;' then rlcompleter seems to import without problems. If you then do 'import IPython' on the embedded Python-shell you get a different error message) I'll look into this. But don't expect a solution this week. Sorry
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||||
September 5, 2013, 14:49 |
|
#9 | ||
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
Quote:
As you know, RHEL tends to quite conservative. In general, Python and the majority of it's modules are new enough but iPython and matplotlib tend to lack some of the new things and can cause issues. I run Fedora 19 in a virtual machine which has newer everything for cases that I need it. Quote:
fieldReports and funkyDoCalc is more than meeting my needs for now. Looking into parameterizing their usage in a python script with PyFoam. Quick question in that regard, using the funky* expressions (or any other method), is there a way to query the number of cells in the internalField, boundaryField, or cell set? Thanks again, Chris |
|||
September 5, 2013, 15:40 |
|
#10 | |||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Quote:
Quote:
Just discovered during writing: I recently implemented it in the accumulators (size) but it is not available in expressions. fieldReport prints it automatically
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||||
September 9, 2013, 15:01 |
|
#11 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Anyway: what doesn't work in old IPython is tab-completion (in new one it does). This seems to be a common problem: Although tab-completion is configured in the embeded standard-shell it doesn't work there either (although it does the same things that make it work in a non-embedded python-shell). So: tab-completion only in new IPython
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
September 10, 2013, 16:44 |
|
#12 |
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
I updated and rebuilt. Running the tutorial drops me into an iPython shell successfully.
However when I list the variables with "whos" it reports "Interactive namespace is empty". A quick search on stackoverflow suggests iPython needs to be invoked with -i parameter. |
|
September 10, 2013, 19:52 |
|
#13 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
I'm quite surprised that %whos lists the variables with a new IPython (As I understand it %whos only shows the variables that were interactively defined on the shell and all these variables were injected not from the shell). And with the old IPython this is not the case? (currently got no possibility to test it with an old one)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
calculate friction factor & nusselt number | soheil1991 | FLUENT | 3 | March 11, 2017 10:30 |
[swak4Foam] problem with slave cells using toposet while calculating volume flux with swak4foam | Andy_Wang | OpenFOAM Community Contributions | 0 | October 14, 2016 14:20 |
calculate velocity difference | helly | OpenFOAM Post-Processing | 0 | June 21, 2016 09:49 |
Calculate statistics of Turbulent channel flow with LES | sjwon1991 | Main CFD Forum | 2 | May 11, 2016 00:31 |
source term in near wall cell | rajcfd | OpenFOAM Pre-Processing | 5 | February 1, 2016 11:31 |