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

[PyFoam] First discussion thread about PyFoam

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 19, 2013, 13:45
Default
  #281
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 13:57
Default
  #282
Senior Member
 
izna O'connor
Join Date: Jun 2013
Posts: 143
Rep Power: 13
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, 11:48
Default
  #283
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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, 11:52
Default
  #284
Senior Member
 
zaynah K.
Join Date: Jun 2012
Location: Mauritius
Posts: 138
Rep Power: 14
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, 12:27
Default
  #285
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
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, 10:02
Default
  #286
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 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, 10:10
Default
  #287
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
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, 06:09
Default Extracting the values from the patchAverage utility through python script
  #288
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 12
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, 06:28
Default
  #289
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 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, 06:31
Default
  #290
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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 offline   Reply With Quote

Old   June 5, 2014, 06:48
Default
  #291
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 12
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, 06:55
Default
  #292
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 12
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, 04:30
Default
  #293
New Member
 
DAPHNE
Join Date: Apr 2014
Posts: 6
Rep Power: 12
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, 21:53
Default
  #294
New Member
 
Kojirion's Avatar
 
Albert Yiamakis
Join Date: Jun 2015
Posts: 6
Rep Power: 11
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

Old   January 27, 2016, 08:33
Default
  #295
New Member
 
Jens
Join Date: Apr 2014
Posts: 28
Rep Power: 12
jensi_t is on a distinguished road
Hello,

I use fluent3DMeshToFoam and fluentDataToFoam to start my calculation from an initial solution (with nonuniform profiles on inlets). Then I apply a changeDictionaryDict to the case to set the right boundary conditions (probably also possible with pyFoam).

One inlet condition for U is for example:
Code:
        farfield_inlet
        {
        type            temperatureDirectedInletOutletVelocity;
        phi             phi;
        T               T;
        T0              uniform 255;
        inletDirection  uniform (1 0 0);
        cylindricalCCS  no;
        omega           ( 0 0 0 );
        value           uniform (245 0 0);
        }
My question is how I can copy the nonuniform Ttot Field of farfield_inlet into the U boundary condition. Is pyFoam my friend in such a case?

Thanks in advance.

Jens
jensi_t is offline   Reply With Quote

Old   October 8, 2017, 03:58
Default pyfoam ( small ) bug
  #296
Member
 
Jeff
Join Date: May 2016
Posts: 44
Rep Power: 10
jf_vt is on a distinguished road
Hello
I am not sure where to report pyfoam bug so I do it here:
pyfoam version 0.6.4 on top of python 2.7.12 and foam extend 4.0

The bug is:
PyFoam change keyword value from "none" to "no" creating a subsequent solver error in the following situation:

Initial pressure file p in 0 directory has an outlet value as :
Quote:
outlet
{
type totalPressure;
rho none;
psi psi;
gamma 1.3;
p0 $internalField;
value $internalField;
}
I change $internal field value in this file with the commands:
Quote:
pFile = ParsedParameterFile(os.path.join(dirCase,caseName, '0','p'))
pFile['internalField'].setUniform(press)
pFile.writeFile()
press being previously defined in my script.
This is the ONLY change made on this file

but after writeFile(), the boundary condition has been overwritten with:
Quote:
outlet
{
type totalPressure;
rho no;
psi psi;
gamma 1.3;
p0 $internalField;
value $internalField;
}
as stated above.

If I did not miss something obvious, It looks like a parser bug as "no" are the first 2 letter of "none" obviously...
easy to change afterward so a small bug in any case.

( with congratulation and thanks to the developper(s) for this amazing piece of software)

JF
jf_vt is offline   Reply With Quote

Old   October 8, 2017, 18:07
Default
  #297
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 jf_vt View Post
Hello
I am not sure where to report pyfoam bug so I do it here:
pyfoam version 0.6.4 on top of python 2.7.12 and foam extend 4.0

The bug is:
PyFoam change keyword value from "none" to "no" creating a subsequent solver error in the following situation:

Initial pressure file p in 0 directory has an outlet value as :


I change $internal field value in this file with the commands:


press being previously defined in my script.
This is the ONLY change made on this file

but after writeFile(), the boundary condition has been overwritten with:


as stated above.

If I did not miss something obvious, It looks like a parser bug as "no" are the first 2 letter of "none" obviously...
easy to change afterward so a small bug in any case.

( with congratulation and thanks to the developper(s) for this amazing piece of software)

JF
The Problem seems to be PyFoam. "none" is assumed to be an equivalent for boolean "false" because OpenFOAM defines it this way in Switch.H and Switch.C. "false" is then later written as "no". One of the instances where PyFoam has to chose because the OF-fileformat is not unambigous ... and it choses wrongly.

The best way for you to fix this quickly is to go to PyFoam/Basics/DataStructures.py look for the FalseStrings-list and comment out "none" as well. That way "none" should be parsed as the word "none".

I'll think of a permanent solution (that will probably be the same thing + praying that it doesn't break too many other cases)
__________________
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   October 9, 2017, 00:20
Default
  #298
Member
 
Jeff
Join Date: May 2016
Posts: 44
Rep Power: 10
jf_vt is on a distinguished road
Quote:
Originally Posted by gschaider View Post

The best way for you to fix this quickly is to go to PyFoam/Basics/DataStructures.py look for the FalseStrings-list and comment out "none" as well. That way "none" should be parsed as the word "none".
Thanks
I will keep that in mind if this has a broader impact on my scripts down the road and a real fix appear impractical or difficult.

For the time being, I just added
Quote:
pFile['boundaryField']['outlet']['rho']='none'
to the script and it worked as well

JF
jf_vt is offline   Reply With Quote

Old   October 9, 2017, 08:37
Default
  #299
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 jf_vt View Post
Thanks
I will keep that in mind if this has a broader impact on my scripts down the road and a real fix appear impractical or difficult.

For the time being, I just added


to the script and it worked as well

JF
I'll remove "none" from the list of possible "false"-representations. I don't think that anyone is even aware that this is possible (OF specifies 6 different ways to write false ) and it breaks valid cases
__________________
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   January 16, 2018, 10:58
Default
  #300
New Member
 
Khomenko Maxim
Join Date: Aug 2015
Posts: 18
Rep Power: 11
mbookin is on a distinguished road
Dear Bernard!

I'm trying to make GUI for my OpenFoam solver with PyFoam supposed to be used for parsing dictionaries.
I thought to use the ParsedParameterFile function for taking data from GUI edit-boxes and writing it to the dictionary. The thing that stopped me was that ParsedParameterFile function cant understand dimensioned scalars in the dictionary. I have written here about this problem, but haven't got any answers. Could you please give me a hint of where to look for. How do you think maybe OpenFOAM classes like IOdictionary is more suitable for that?
mbookin 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
Divergence detected in AMG solver: k when udf loaded google9002 Fluent UDF and Scheme Programming 3 November 8, 2019 00:34
udf problem jane Fluent UDF and Scheme Programming 37 February 20, 2018 05:17
Guide: Getting Started with the CFD Online Discussion Forums pete Site Help, Feedback & Discussions 8 July 29, 2016 06:00
Error messages atg enGrid 7 August 30, 2013 12:16
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 15:37


All times are GMT -4. The time now is 07:45.