CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [PyFoam] First discussion thread about PyFoam (https://www.cfd-online.com/Forums/openfoam-community-contributions/60683-first-discussion-thread-about-pyfoam.html)

braennstroem July 28, 2007 03:33

First discussion thread about PyFoam
 
Hi,

I tried to run the simulations using PyFoam with OpenFoam 1.4. The installation was no problem and the test of the installation (like the wiki suggested) was ok too,but as soon as I start the calculations with

localhost~/OpenFOAM/fab-1.4/run/tutorials/simpleFoam$ pyFoamSteadyRunner.py simpleFoam . pitzDaily

I get:
[28 Jul 9:30am]
Traceback (most recent call last):
File "/usr/bin/pyFoamSteadyRunner.py", line 3, in ?
from PyFoam.Applications.SteadyRunner import SteadyRunner
ImportError: No module named SteadyRunner

So it looks actually like a python problem!? I installed it with python 2.5 and 2.3.
Would be nice, if anybody has an idea, how to get pyfoam running... it seems pretty powerfull!

Regards!

braennstroem July 30, 2007 13:15

Hi, it works at work ;-) ...
 
Hi,
it works at work ;-) ... it seems that the wiki-test of the installation is not enough; I would say, that I forgort to load the libaries, stupid.

Regards!
Fabian

gschaider July 31, 2007 13:14

Is it something I forgot to me
 
Is it something I forgot to mention on the Wiki-page? Or did you just forget to set the PYTHONPATH-variable?

braennstroem August 1, 2007 05:30

Hi Bernhard, I just forgot
 
Hi Bernhard,

I just forgot the Pythonpath... your WIKI is ok, but I am missing some more information ;-)

How can I convert the openfoam data files to ensight for every variation when using your 'Parameter Variation' script?

Regards!
Fabian

gschaider August 1, 2007 09:23

The one that is one the Wiki-P
 
The one that is one the Wiki-Page? Must revise that one of these days (It's still from the 0.1.x-version)

Add something like (don't know the exact call for the Ensight-Converter) near the call for the mass-flow calculation:

eUtil=UtilityRunner(argv=["foamToEnsight",".",case,"-latestTime"],silent=True,lo gname="EnsightConversion")
eUtil.start()

braennstroem August 1, 2007 15:29

Hi Bernhard, thanks, I will
 
Hi Bernhard,

thanks, I will try it out!

Fabian

braennstroem August 2, 2007 02:17

Hi Bernhard, I have one mor
 
Hi Bernhard,

I have one more question ... what do you think is the best way to run different solvers, e.g. potentialFoam / simpleFoam / turbFoam / oodles, one after another. Do you think one of your 'utilities' can do that?

Greetings!
Fabian

gschaider August 2, 2007 08:26

Hi Fabian! Of course it can
 
Hi Fabian!

Of course it can. The only problem is that "different folks need different strokes": the solvers you are refering to need very different fvS.+-files (amongst other things). But if you have a template case that satisfys them all you could do the following (just a sketch):

caseName="baseCase"

for solver in ["potentialFoam","simpleFoam","turbFoam","oodle s"]:
. case=SolutionDirectory(caseName).cloneCase(caseNam e+"."+solver)
. run=ConvergenceRunner(BoundingLogAnalyzer(),argv=[solver,".",case.name],silent=T rue)
. run.start()

(Sorry about the points, but they're the only way I can get the MessageBoard to indent the lines)

The problem with this example is of course that we're mixing steady with unsteady solvers.

About the discussion in the "Foam::error::printStack"-thread (I'm moving it here because it doesn't belong there http://www.cfd-online.com/cgi-bin/Op...how.cgi?1/4603 ): I hope my answer didn't come across in such a way that I am not open to other peoples ideas/input on the scope of PyFoam.

About the manipulation of boundary conditions: you are aware of the ParsedParameterFile-class? That one might be helpful. It reads a Foam-Dictionary and stores it as a Python-data-structure in memory (Foam-dictionaries become Python-dictionaries, Foam-Lists become ..... Python-lists) which you can manipulate and write back to disk (the output is ugly as f###, but valid). Ah. And don't try to use it on a 10k-nonuniform-field (I'm afraid the parser will run out of memory).

Bernhard

philippose August 26, 2007 04:31

Hello there, A Good Sunday
 
Hello there,

A Good Sunday morning to everyone :-)!

First of all, I must commend Bernhard Gschaider for the effort put into PyFoam. I was looking into the facilities available, and its quite mindblowing how much stuff has been packed into it :-)! Really cool !!

I am considering using PyFoam for a set of batch simulations with parameter variations. Before I go deeper into making an application, I have one question....

The ConvergenceRunner, is used to run a steady state simulation, until the solution converges, which in this case would be the residuals dropping below a certain limit.

I was looking through some of the examples, but could not find any example, where these "convergence limits" are specified. How can I specify what the limits of the residuals are, below which PyFoam considers the solution to be "converged" ?

Have a nice day!

Philippose

braennstroem August 26, 2007 08:43

Hi, @Bernhard: Thanks, it se
 
Hi,
@Bernhard:
Thanks, it seems pyfoam is usefull for everything :-) I'll try it out...

@Philippose:
I'll think it depends on the number of iterations, but I am not sure.

I would be nice, if the convergence could be checked by monitoring some kind of physical value in the flow and define a certain range for a certain number of iterations.

Fabian

gschaider August 27, 2007 10:51

Hi! Fabian is right: The Co
 
Hi!

Fabian is right: The ConvergenceRunner doesn't judge the convergence himself, but lets the linear solvers do it: if all of them do 0 iterations it assumes that the solution is converged

@other measures for convergence: The only means that PyFoam has to get information about a run is by checking the output of the solver. If "some kind of physical value in the flow" is output, then it can be checked for and the run can be terminated the same way the ConvergenceRunner does it.

Bernhard

philippose August 28, 2007 14:41

Hello Bernhard and Fabian,
 
Hello Bernhard and Fabian,

Thanks a lot for the information... I have been looking through the code, and I think I am slowly getting a hang of it, though, its really extensive :-)! And I am more or less, a beginner in Python when it comes to such large projects with tonnes of classes, etc...

As far as I can see, creating a "Runner" which actually works on a convergence criteria like stopping when some or all of the variables go below a residual threshold, or even looking for convergence in a physical variable like flow, shouldnt be too difficult.

Anyway, shall post questions as I progress over the next week or so :-)!

Have a nice day!

Philippose

gschaider August 29, 2007 14:30

Hi Philippose! The problem
 
Hi Philippose!

The problem is that it happens on three levels: the Runner-class runs the solver it gets the output and sends each line to a FoamLogAnalyzer-subclass. That sends that line to all its LogLineAnalyzers (it can have as many as it wants). These are the real work-horses. They look at the lines, gather information and sometimes decide whether they think that the simulation is converged (the goOn()-method). The FoamLogAnalyzer asks all his LineAnalyzers. If one of them says "Converged" it tells the runner to stop the simulation (not without writting the current-timestep).

So what you want to do is this: implement a LogLineAnalyzer-subclass that fits your idea of convergence. Add it to the ConvergenceRunner and it should terminate the run once it is converged

Hope this helps

Bernhard

gschaider August 29, 2007 14:32

Forgot: a new version of PyFoa
 
Forgot: a new version of PyFoam (0.4.1) found its way to the Wiki.

braennstroem October 2, 2007 01:04

Hi Bernhard, I would like t
 
Hi Bernhard,

I would like to use the utitlityrunner to extract the result of 'patchAverage', which looks in my case like:

*---------------------------------------------------------------------------
ceplx049~/SCR1/OpenFOAM_Berechnung/Nottage> patchAverage . Nottage_Tetra_Fein p einlass:4 -latestTime
/*---------------------------------------------------------------------------*\
| ========= | |
| \ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \ / O peration | Version: 1.4.1 |
| \ / A nd | Web: http://www.openfoam.org |
| \/ M anipulation | |
\*---------------------------------------------------------------------------*/

Exec : patchAverage . Nottage_Tetra_Fein p einlass:4 -latestTime
Date : Oct 02 2007
Time : 06:33:06
Host : ceplx049
PID : 22200
Root : /v/ceplx049/fs2/scr/scr1/gcae504/OpenFOAM_Berechnung/Nottage
Case : Nottage_Tetra_Fein
Nprocs : 1
Create time

Create mesh for time = 1850

Time = 1850
Reading field p
Average of p over patch einlass:4[2] = 0.557439

End
*---------------------------------------------------------------------------

Do you know what kind of regex to use, to extract the pressure average? I am kind of confused about your regex in the example...

I tried this approach:

*---------------------------------------------------------------------------
pUtil=UtilityRunner(argv=["patchAverage",".",case, patch, variable, " -latestTime"],silent=True,logname="patchAverage")
pUtil.add("deltaP"," Average of p over patch (.+) = .*\]",idNr=1)
pUtil.start()
deltaP=pUtil.get("deltaP")[0]
deltaPressure=pUtil.get("p",ID="einlass:4")[0]
*---------------------------------------------------------------------------

but, as expected, it did not work:

*---------------------------------------------------------------------------
ceplx049~/SCR1/OpenFOAM_Berechnung/Nottage> python2.5 patchAverage_pyFoam.py
simpleFoam
<pyfoam.execution.utilityrunner.utilityrunner>
Traceback (most recent call last):
File "patchAverage_pyFoam.py", line 47, in <module>
deltaP=pUtil.get("deltaP")[0]
TypeError: 'NoneType' object is unsubscriptable
*---------------------------------------------------------------------------


Greetings!
Fabian

gschaider October 2, 2007 05:44

Hi Fabian! The lines you wa
 
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

braennstroem October 3, 2007 05:21

Hi Bernhard, thanks for you
 
Hi Bernhard,

thanks for your help; I will try on Thursday at the office.
Fabian

pvc October 4, 2007 03:35

Hi bernhard, I'm trying to
 
Hi bernhard,

I'm trying to use the DisplayBlockMesh utility:
Following the message given by the --help option. I have:

cue006@cfd-kf:~/OpenFOAM/cue006-1.4.1/run/tutorials/oodles> pyFoamDisplayBlockMesh.py CST/constant/polyMesh/blockMeshDict
Traceback (most recent call last):
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 391, in ?
DisplayPlotMesh()
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 22, in __init__
PyFoamApplication.__init__(self,description=descri ption,usage="%prog [options] <blockmeshdict>",interspersed=True,nr=1)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/Applications/PyFoamApplication. py", line 21, in __init__
self.run()
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 42, in run
self.readFile()
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 122, in readFile
self.blockMesh=ParsedBlockMeshDict(sys.argv[1])
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedBlockMeshDi ct.py", line 11, in __init__
ParsedParameterFile.__init__(self,name,backup=back up,debug=debug)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedParameterFi le.py", line 26, in __init__
self.readFile()
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/FileBasis.py", line 56, in readFile
self.content=self.parse(self.fh.read())
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedParameterFi le.py", line 30, in parse
parser=FoamFileParser(content,debug=self.debug,bou ndaryDict=self.boundaryDict)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedParameterFi le.py", line 77, in __init__
self.header,self.data=self.parse(content)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/Basics/PlyParser.py", line 50, in parse
return yacc.parse(content)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/ThirdParty/ply/yacc.py", line 334, in parse
tok = self.errorfunc(errtoken)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedParameterFi le.py", line 304, in p_error
raise "ParserError",("Syntax error at token", p) # .type, p.lineno
ParserError: ('Syntax error at token', LexToken(NAME,'version',3,124))


What's wrong?

Cheers

pvc

gschaider October 4, 2007 05:30

Hi Pierre! PyFoam thinks th
 
Hi Pierre!

PyFoam thinks tht there is a syntactical error in the blockMeshDict. The cause could either be
a) there IS an error in the blockMeshDict (have you ever tried to run blockMesh on it?)
b) there IS a bug in PyFoam
Could you give me the blockMeshDict that is causing trouble (either per mail or here)

Bernhard

pvc October 4, 2007 22:20

hi bernhard, Thanks for th
 
hi bernhard,

Thanks for the tip. I've tested my PyFoam installation against the pitzdaily case and it's working.

My geometry was derived from a cylindermesh.m4 script (see http://www.cfd-online.com/OpenFOAM_D...es/1/3249.html).
I think the answer will come by solving this simple case, since pyFoamDisplayBlockMesh was crashing when trying to open it. As you have suggested, maybe a bug?

Kind regards

Pierre
cue006@cfd-kf:~/OpenFOAM/cue006-1.4.1/run/tutorials/oodles/m4_Files> pyFoamDispl
ayBlockMesh.py cylinderMeshDict
Traceback (most recent call last):
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 391, in ?
DisplayPlotMesh()
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 22, in __init__
PyFoamApplication.__init__(self,description=descri ption,usage="%prog [option
s] <blockmeshdict>",interspersed=True,nr=1)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/Applications/PyFoamAppli
cation.py", line 21, in __init__
self.run()
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 42, in run
self.readFile()
File "/usr/local/bin/pyFoamDisplayBlockMesh.py", line 122, in readFile
self.blockMesh=ParsedBlockMeshDict(sys.argv[1])
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedBloc
kMeshDict.py", line 11, in __init__
ParsedParameterFile.__init__(self,name,backup=back up,debug=debug)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedPara
meterFile.py", line 26, in __init__
self.readFile()
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/FileBasis.
py", line 56, in readFile
self.content=self.parse(self.fh.read())
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedPara
meterFile.py", line 30, in parse
parser=FoamFileParser(content,debug=self.debug,bou ndaryDict=self.boundaryDic
t)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedPara
meterFile.py", line 77, in __init__
self.header,self.data=self.parse(content)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/Basics/PlyParser.py", li
ne 50, in parse
return yacc.parse(content)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/ThirdParty/ply/yacc.py",
line 334, in parse
tok = self.errorfunc(errtoken)
File "/usr/local/lib64/python2.4/site-packages/PyFoam/RunDictionary/ParsedPara
meterFile.py", line 304, in p_error
raise "ParserError",("Syntax error at token", p) # .type, p.lineno
ParserError: ('Syntax error at token', LexToken(NAME,'version',3,124))


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