CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

PyFoam

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   August 19, 2013, 12:45
Default
  #281
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,251
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Izna,

You apparently have not yet installed swak4Foam: http://openfoamwiki.net/index.php/Contrib/swak4Foam

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   August 19, 2013, 12:57
Default
  #282
Senior Member
 
izna O'connor
Join Date: Jun 2013
Posts: 139
Rep Power: 4
izna is on a distinguished road
Oh Brunos..
Again errors..

Quote:

Plotting the following cases:
['../Bump2D_run_1.06_10.0_1500.0_200.0_200.0_0.5_2000']
Traceback (most recent call last):
File "./runBump2D.py", line 211, in <module>
plot2DBump.main(target,hSample)
File "/home/izna/Desktop/benmartinez/2DBumpTemplate/plot2DBump.py", line 38, in main
m = max(lastRun)
ValueError: max() arg is an empty sequence

izna is offline   Reply With Quote

Old   August 21, 2013, 10:48
Default
  #283
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,251
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Hi Izna,

That error does not seem to be PyFoam's nor swak4Foam's fault.
Please start a new thread about this particular topic and please describe where you got those cases/scripts and how you ran the case and/or scripts.

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   August 21, 2013, 10:52
Default
  #284
Senior Member
 
zaynah K.
Join Date: Jun 2012
Location: Mauritius
Posts: 138
Rep Power: 5
zaynah04 is on a distinguished road
I will post one thing for this..

I have checked Hanan case, and i think there is soem errors.. i will post mne.. and we can aall compare
zaynah04 is offline   Reply With Quote

Old   April 8, 2014, 11:27
Default
  #285
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 133
Rep Power: 8
francois is on a distinguished road
Hi all,

I've an easy one: "How to tell pyFoam to use matplotlib instead of gnuplot by default ?"

I've an already converged case and want to plot for example the residuals with matplotlib. What's the best procedure to achieve this ?

Same kind of question for example for pyFoamSamplePlot.py.

I'm sorry if it looks too trivial but I've tried to find some help in the forum and the doc without success.

Thanks for your help.
Regards
François
francois is offline   Reply With Quote

Old   April 11, 2014, 09:02
Default
  #286
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by francois View Post
Hi all,

I've an easy one: "How to tell pyFoam to use matplotlib instead of gnuplot by default ?"

I've an already converged case and want to plot for example the residuals with matplotlib. What's the best procedure to achieve this ?

Same kind of question for example for pyFoamSamplePlot.py.

I'm sorry if it looks too trivial but I've tried to find some help in the forum and the doc without success.

Thanks for your help.
Regards
François
If you have the suspicion that something SHOULD work in pyFoam try something like "pyFoamPlotWatcher.py --help" and have a look. In this special case the section "Plot Behaviour" and especially the --implementation-option might be of interest. Also have a look at pyFoamRedoPlot.py (this uses Matplotlib by default)

pyFoamSamplePlot.py only supports Gnuplot but you can write out the data to a CSV-file and then visualize it with whatever you like

Also some utilities (but not SamplePlot) support reading the data and then dropping you to an interactive python-shell. See for instance http://openfoamwiki.net/staticPages/...tml#/sec-3-2-2

My current policy is "Support GNUplot by default because it is an order of magnitude faster than Matplotlib. Also is the API of matplotlib changing and what works on one version might stop working on another. Start offering the possibility to easily export data into the Numpy/Pandas/Matplotlib-stack and then everyone can visualize the way he likes"
__________________
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
gschaider is offline   Reply With Quote

Old   April 11, 2014, 09:10
Default
  #287
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 133
Rep Power: 8
francois is on a distinguished road
Thanks Bernhard for your exhaustive and helpful answer
It's clearer for me now

Regards,
François
francois is offline   Reply With Quote

Old   June 5, 2014, 05:09
Default Extracting the values from the patchAverage utility through python script
  #288
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 3
DAPHNE is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Hi Fabian!

The lines you want to change are:

pUtil.add("deltaP","Average of p over patch (.+) = (%f%)",idNr=1)

In order to get added as data the pattern has to be enclosed in (). The first one is used as the ID (as specified by the option). The %f% is replaced with the regular expression that matches a floating point number (just a shorthand in the PyFoam-classes that use regular expressions)

The second part took me longer (I thought my classes were broken, but in fact in your example the [2] was missing):

deltaPressure=pUtil.get("deltaP",ID="einlass:4[2]")[0]

Now deltaPressure has the string 0.557439 (which is what you wanted?)

Bernhard
Hi Bernhard and All,
I tried to extract the values from the patchAverage utility through python script.
I used patchAverage utility to find the pressure field of cavity case:
################################################## ##########
tutorials/incompressible/icoFoam/cavity$ patchAverage p movingWall
Create time

Create mesh for time = 0

Time = 0
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0

Time = 0.1
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597376

Time = 0.2
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597292

Time = 0.3
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597295

Time = 0.4
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597294

Time = 0.5
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597292

End
################################################## ##################

The script I used is:
###############################################
solver="icoFoam"
case="cavity"
pCmd="patchAverage"
patch="movingWall"

pUtil=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage1")
pUtil.add("deltaPp","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)
pUtil.start()
deltaP=pUtil.get("deltaP",ID="movingWall[0]") [0]
deltaPressure=pUtil.get("deltaP")[0]
print deltaPressure
############################################
Error
/ParameterVariation/cavity$ python utilityrunner.py
Traceback (most recent call last):
File "utilityrunner.py", line 22, in <module>
deltaP=pUtil.get("deltaP")[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

################################################## ##########

So I tried the following:
################################################## #########
from PyFoam.Execution.ConvergenceRunner import ConvergenceRunner
from PyFoam.Execution.UtilityRunner import UtilityRunner
from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer
from PyFoam.LogAnalysis.UtilityAnalyzer import UtilityAnalyzer


solver="icoFoam"
case="cavity"
pCmd="patchAverage"
patch="movingWall"

pUtil=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage1")
pUtil.add("volScalarFieldp","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)
pUtil.start()
deltaP=pUtil.get("volScalarFieldp",ID="movingWall" )
print UtilityRunner.get(pUtil,"volScalarField p")
deltaPressure=pUtil.get("volScalarField")

print deltaPressure

##############################################
Output:
None
None
##############################################
Still the values are not extracted..

Thank you.

Regards,
Daphne
DAPHNE is offline   Reply With Quote

Old   June 5, 2014, 05:28
Default
  #289
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by DAPHNE View Post
Hi Bernhard and All,
I tried to extract the values from the patchAverage utility through python script.
I used patchAverage utility to find the pressure field of cavity case:
################################################## ##########
tutorials/incompressible/icoFoam/cavity$ patchAverage p movingWall
Create time

Create mesh for time = 0

Time = 0
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0

Time = 0.1
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597376

Time = 0.2
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597292

Time = 0.3
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597295

Time = 0.4
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597294

Time = 0.5
Reading volScalarField p
Average of volScalarField over patch movingWall[0] = 0.0597292

End
################################################## ##################

The script I used is:
###############################################
solver="icoFoam"
case="cavity"
pCmd="patchAverage"
patch="movingWall"

pUtil=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage1")
pUtil.add("deltaPp","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)
pUtil.start()
deltaP=pUtil.get("deltaP",ID="movingWall[0]") [0]
deltaPressure=pUtil.get("deltaP")[0]
print deltaPressure
############################################
Error
/ParameterVariation/cavity$ python utilityrunner.py
Traceback (most recent call last):
File "utilityrunner.py", line 22, in <module>
deltaP=pUtil.get("deltaP")[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

################################################## ##########

So I tried the following:
################################################## #########
from PyFoam.Execution.ConvergenceRunner import ConvergenceRunner
from PyFoam.Execution.UtilityRunner import UtilityRunner
from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer
from PyFoam.LogAnalysis.UtilityAnalyzer import UtilityAnalyzer


solver="icoFoam"
case="cavity"
pCmd="patchAverage"
patch="movingWall"

pUtil=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage1")
pUtil.add("volScalarFieldp","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)
pUtil.start()
deltaP=pUtil.get("volScalarFieldp",ID="movingWall" )
print UtilityRunner.get(pUtil,"volScalarField p")
deltaPressure=pUtil.get("volScalarField")

print deltaPressure

##############################################
Output:
None
None
##############################################
Still the values are not extracted..

Thank you.

Regards,
Daphne
There may be other problems, but I think it is the [] in the regular expression. That has a special meaning in regular expression. Replace it with "\[0\]"

For your first steps with regular expressions try something like http://regex101.com/#python (mind: it will NOT understand the %f%. That is PyFoam-specific)
__________________
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
gschaider is offline   Reply With Quote

Old   June 5, 2014, 05:31
Default
  #290
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,088
Rep Power: 19
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

Quote:
Originally Posted by DAPHNE View Post
The script I used is:
###############################################
solver="icoFoam"
case="cavity"
pCmd="patchAverage"
patch="movingWall"

pUtil=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage1")
pUtil.add("deltaPp","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)
pUtil.start()
deltaP=pUtil.get("deltaP",ID="movingWall[0]") [0]
deltaPressure=pUtil.get("deltaP")[0]
print deltaPressure
############################################
Error
/ParameterVariation/cavity$ python utilityrunner.py
Traceback (most recent call last):
File "utilityrunner.py", line 22, in <module>
deltaP=pUtil.get("deltaP")[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

################################################## ##########
It's just common sense, maybe I'm missing something, but the error usually means that pUtil.get("deltaP") returned None. You've used deltaPp in pUtil.add and you've used deltaP in pUtil.get. It looks rather strange to me.

The same thing is in the second script.
alexeym is online now   Reply With Quote

Old   June 5, 2014, 05:48
Default
  #291
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 3
DAPHNE is on a distinguished road
Dear Bernhard and Alexeym,

Firstly, thank you so much for your quick reply.

@Bernhard
The link you suggested to try Regular expressions is much useful. I tried that and made changes as you suggested. But still the same error persisits. Will keep trying and update.

@Alexeym
Sorry for the inconvenience.[made mistake while copy and paste]By mistake I posted as
pUtil.add("deltaPp","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)

But actually I used only the following:
pUtil.add("deltaP","Average of volScalarField over patch movingWall[0](.+) =(%f%)",idNr=1)
DAPHNE is offline   Reply With Quote

Old   June 5, 2014, 05:55
Default
  #292
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 3
DAPHNE is on a distinguished road
Hi Alexeym,

Here is the corrected version of the code I used:


pUtil=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage1")
pUtil.add("deltaP","Average of volScalarField over patch movingWall \[0\] (.+) =(%f%)",idNr=1)
pUtil.start()
deltaP=pUtil.get("deltaP")
print UtilityRunner.get(pUtil,"deltaP")
deltaPressure=pUtil.get("deltaP",ID="movingWall \[0\]")
print deltaPressure

Regards,
Daphne
DAPHNE is offline   Reply With Quote

Old   June 12, 2014, 03:30
Default
  #293
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 3
DAPHNE is on a distinguished road
Hi All,

I managed to correct the code to extract the values from the patch Average utility.

Code:
pUtil1=UtilityRunner(argv=[pCmd,"p",patch],silent=True,logname="patchAverage")
pUtil1.add("PressureDifference","Average of volScalarField over patch (.+)= (%f%)",idNr=1)
pUtil1.start()
a=UtilityRunner.get(pUtil1,"PressureDifference")
print a

Regards,
Daphne
DAPHNE is offline   Reply With Quote

Old   June 11, 2015, 20:53
Default
  #294
New Member
 
Albert Yiamakis
Join Date: Jun 2015
Posts: 2
Rep Power: 0
Kojirion is on a distinguished road
Hello,

I am using pyFoam version 0.6.4 with python 3.4.3, which the wiki suggests is fine. It generally works, however I have encountered an error that I 'm almost certain is due to incompatibility between python versions. Line 291 of Benchmark.py reads

Code:
args=string.split("%s %s %s %s" % (pre,workDir,caseDir,post))
I believe that would work with python 2, but does not on 3 (" AttributeError: 'module' object has no attribute 'split'")
(Line 293 suffers from the same problem)

I have also encountered a couple more issues when parsing a dictionary with
ParsedParameterFile that I haven't dug in to find the cause of:

- the value "none" is incorrectly read as "no" and has to be manually fixed
- whitespace is not parsed correctly, for example "(air in water)" when reading the phaseProperties of twoPhaseEulerFoam bubbleColumn tutorial: it results in a list rather than a dictionary.

Kojirion is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PyFoam library seb62 OpenFOAM Post-Processing 52 September 30, 2011 08:28


All times are GMT -4. The time now is 20:22.