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 Members List Search Today's Posts Mark Forums Read

Like Tree6Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 3, 2009, 10:32
Default
  #141
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 prjohnston View Post
Dear All,

Yesterday I installed PyFoam from the svn site. I did the installation under sudo and all seemed to go well. I carried out the testing as described under section 3.5 in the wiki.

I am interested in the example doInletVariation.py. Unfortunately, I cannot make it work. The file itself uses the tutorial example pitzDaily. I copied the pitzDaily directiory from /home/peter/OpenFOAM/peter-1.6/run/tutorials/incompressibl
e/simpleFoam/pitzDaily into the PyFoam/examples directory. Is this the correct
thing to do? Then, from the PyFoam/examples directory I type "python doInletVarpation.py" and get the error message:

PyFoam FATAL ERROR on line 89 of file /usr/local/lib/python2.6/dist-packages/PyFoam/Execution/BasicRunner.py : Solution directory . does not exist. No use running. Problem: [Errno 2] No such file or directory

The error seems to occur at the ConvergenceRunner line of the script. The script has already created the pitzDaily/InletVariation directory and modified the inlet velocity in the pitzDaily/0/U file.

If someone could help me, that would be much appreciated.

I am running OpenFOAM 1.6 under ubuntu 9.04. Unitl now everything has been going really well.

Thank you,

Peter.
OK. My bad. The problem is that the example is in the pre-1.5 calling-convention for utilities. As a quick fix replace the three instances of "." with "-case". Of course you'll need the calcMassFlow and calcPressureDifference-Utilities as well.

A better example that does not depend on third-party-stuff is on slide 48 of this presentation:
http://www.openfoamworkshop.org/2009...der_PyFoam.pdf
The problem is, this is from pre-1.6 times and the current PVSnapshot-Utility doesn not work with paraview 3.6

I'm currently in the process of fixing this and once I've got it sorted out I will release a new version of pyFoam which will also have this example fixed

Bernhard
gschaider is offline   Reply With Quote

Old   September 4, 2009, 01:41
Default
  #142
New Member
 
Peter Johnston
Join Date: Mar 2009
Location: Brisbane, Queensland, Australia
Posts: 25
Rep Power: 17
prjohnston is on a distinguished road
Dear Bernhard,

Thanks for your solution. It all works nicely now (I didn't worry about the mass and pressure utilities).

I have couple of questions/comments:

1) I am intrigued that paraFoam can find all the cases in the archive without the "time" directories appearing explicitly. Could you explain how this works?

2) I would like to use the parameter variation with groovyBC (which is great) where I set the maximum velocity in a paraboloidal flow field (instead of the uniform one as used in your doInletVariations.py script). Is such a thing possible?

Thanks again,

Peter.
prjohnston is offline   Reply With Quote

Old   September 4, 2009, 08:04
Default
  #143
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 prjohnston View Post
Thanks for your solution. It all works nicely now (I didn't worry about the mass and pressure utilities).

I have couple of questions/comments:

1) I am intrigued that paraFoam can find all the cases in the archive without the "time" directories appearing explicitly. Could you explain how this works?
You mean paraFoam or pyFoam?
For PyFoam the general answer is that the SolutionDirectory-class has some special methods that make it look like "a list of TimeDirectories" (making it possible to write a natural iteration "for t in sol:" over all the time-steps in Python). TimeDirectory in turn is a "list of SolutionFiles"

Quote:
Originally Posted by prjohnston View Post
2) I would like to use the parameter variation with groovyBC (which is great) where I set the maximum velocity in a paraboloidal flow field (instead of the uniform one as used in your doInletVariations.py script). Is such a thing possible?

Thanks again,

Peter.
Of course. The easiest way to do this (at least in my sick mind) is to read the U-field in the initial timestep into a ParsedParameterFile (lets call it Uinit), manipulate UInit["boundaryField"]["theInletPatch"]["valueExpression"] accordingly and write it back to disk

Bernhard
gschaider is offline   Reply With Quote

Old   September 6, 2009, 20:45
Default PyFoamPlotWatcher is not working
  #144
New Member
 
Arvind
Join Date: Mar 2009
Posts: 13
Rep Power: 17
arvind_arya is on a distinguished road
I want to watch residuals.....so i have installed PyFoam- 0.5.2.... but...... while executing pyFoamPlotWatcher ......it says

File "/usr/local/bin/pyFoamPlotWatcher.py", line 3, in <module>
from PyFoam.Applications.PlotWatcher import PlotWatcher
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/PlotWatcher.py", line 6, in <module>
from PyFoam.Execution.GnuplotRunner import GnuplotWatcher
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Execution/GnuplotRunner.py", line 86
with="steps",
^
SyntaxError: invalid syntax

I am using UBUNTU-9.0.4 AND OF-1.6
please spare some time to give ur suggestions
Thanks in Advance
arvind_arya is offline   Reply With Quote

Old   September 7, 2009, 14:32
Default
  #145
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 arvind_arya View Post
I want to watch residuals.....so i have installed PyFoam- 0.5.2.... but...... while executing pyFoamPlotWatcher ......it says

File "/usr/local/bin/pyFoamPlotWatcher.py", line 3, in <module>
from PyFoam.Applications.PlotWatcher import PlotWatcher
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/PlotWatcher.py", line 6, in <module>
from PyFoam.Execution.GnuplotRunner import GnuplotWatcher
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Execution/GnuplotRunner.py", line 86
with="steps",
^
SyntaxError: invalid syntax

I am using UBUNTU-9.0.4 AND OF-1.6
please spare some time to give ur suggestions
Thanks in Advance
The problem is that "with" became a keyword in Python 2.6. Strange thing is that it has already been changed to "with_" starting with pyFoam 0.5.2 (I just checked and it is with_ in the last tar). Could you verify with the "pyFoamVersion.py"-command that you're really using the Version you think you're using? Have you had a previous installation of pyFoam? (Maybe something went wrong when upgrading)

Bernhard
gschaider is offline   Reply With Quote

Old   September 16, 2009, 23:29
Default
  #146
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
Hi, just a thought, is there a way to merge the two log files to one. I happened to get my computer restarted during my parallel computation.
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat is offline   Reply With Quote

Old   September 17, 2009, 06:47
Default
  #147
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 lakeat View Post
Hi, just a thought, is there a way to merge the two log files to one. I happened to get my computer restarted during my parallel computation.
PyFoam has nothing to do that (although the problem happens from time to time). I'll have a look how complicated it would be to add a --append-log option to the runner-classes, but I can't promise anything

For the time being I'd recommend clipping all the "unused" timesteps from the old log, clipping the header from the new log and appendign them with cat to a new file. The resulting log can then be treated with the PlotWatcher. You might see some funny restart-effects in the residuals though

Bernhard
gschaider is offline   Reply With Quote

Old   September 17, 2009, 08:30
Default
  #148
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
It's so kind of you,Bernhard.
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat is offline   Reply With Quote

Old   October 22, 2009, 20:44
Default pyFoam and transient simulations
  #149
New Member
 
Peter Johnston
Join Date: Mar 2009
Location: Brisbane, Queensland, Australia
Posts: 25
Rep Power: 17
prjohnston is on a distinguished road
I have successfully managed to run some parameter variation studies using pyFoam for steady state simulations. Using lastToArchive moves the final converged result to an archive directory.

My question is: can I do something similar with transient simulations?

I wish to run a parameter variation study for transient problems. For each parameter I need to run the simulation over several cycles to remove any initial transients. So after these cycles have completed, is there a way within pyFoam to move all the saved time steps to an archive directory? I can probably do this in raw python, but was wondering if there was some simple way in pyFoam.

Thanks very much,

Peter Johnston.
prjohnston is offline   Reply With Quote

Old   October 23, 2009, 05:41
Default
  #150
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 prjohnston View Post
I have successfully managed to run some parameter variation studies using pyFoam for steady state simulations. Using lastToArchive moves the final converged result to an archive directory.

My question is: can I do something similar with transient simulations?

I wish to run a parameter variation study for transient problems. For each parameter I need to run the simulation over several cycles to remove any initial transients. So after these cycles have completed, is there a way within pyFoam to move all the saved time steps to an archive directory? I can probably do this in raw python, but was wondering if there was some simple way in pyFoam.
Havn't used the archive-facility myself in a long time. So I had to look it up. If you look into the source of the SolutionDirectory-class you see the method
Code:
 
   def addBackup(self,pth):
        """add file to list of files that are to be copied to the
        archive"""
that should do what you want to

BTW: if sol is a SolutionDirectory then
Code:
for t in sol:
    print "t=",t.baseName()
should give you all timestep-names in the right order. Maybe that helps

Bernhard
gschaider is offline   Reply With Quote

Old   October 29, 2009, 03:01
Default
  #151
New Member
 
Peter Johnston
Join Date: Mar 2009
Location: Brisbane, Queensland, Australia
Posts: 25
Rep Power: 17
prjohnston is on a distinguished road
Dear Bernhard,

Thanks for that. Much better than the klutzy piece of python that I wrote .

Regards,

Peter.
prjohnston is offline   Reply With Quote

Old   October 29, 2009, 04:44
Default
  #152
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 prjohnston View Post
Thanks for that. Much better than the klutzy piece of python that I wrote .
Actually there is a klutzy piece of python underneath it
gschaider is offline   Reply With Quote

Old   November 10, 2009, 13:34
Default New Release 0.5.3 of PyFoam
  #153
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
I just uploaded a new release of PyFoam. A list of most changes can be found at http://openfoamwiki.net/index.php/Co...PyFoam#History but the most important differences are
  • Support for the regular-expressions that come with 1.6 and other new improvements of the file-format in 1.6 (nevertheless: there are subtle differences between Python-regexp and the way OF-regexp-engine behaves, but for most applications they behave the same)
  • Matplotlib can be used as an additional backend for plotting (this is beta-quality and modelled after the Gnuplot-support). Is quite sensitive to the installed verion of Matplot-lib so use with care. Comments and patches are welcome
  • improved format for the customRegexp that looks more 'FOAMlike'. Old files can be dumped in the new format using the --dump-option of the PlotWatcher
  • two new plot types in the customRegexp ('dynamic' for getting the data names from the regular expression and 'slave' to add data to another plot instead of plotting itself)
  • The Paraview-stuff is currently not supported for PV 3.6 (differences in the API and problems with the Python-support)
Bernhard
gschaider is offline   Reply With Quote

Old   November 11, 2009, 08:57
Default
  #154
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
Great, Thank you, Bernhard!
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat is offline   Reply With Quote

Old   November 14, 2009, 04:47
Default Parameter variation
  #155
Member
 
Thomas Wolfanger
Join Date: Mar 2009
Location: South West Germany
Posts: 62
Rep Power: 17
anger is on a distinguished road
Hello,

I have two more questions regarding pyFoam:

1) I tried to read a binary U filed into a ParsedParameterFile to do some changes in it; but reading resulted in an error. Is this due to a misuse or can this class handle only ascii and compressed ascii files?
2) I also tried to do the parameter variation as described in the OF wiki section 2.2 and was really happy that changing the condition on a filed called "inlet" worked well; but to my big big surprise, changing the value of a field called "outlet" did not work! The value was just added, but the old one was not commented out. I noticed that the type of m in the source code was of type string while for "inlet", it is of some other type resulting in using another code line in the if- expression which is responsible for writing the new value to the file.

Did anyone experience similar behaviour? I'm really stuck at this point and have no idea where to do research in the code as I'm quite new to pyFoam (which is a very useful piece of software).

Best regards,
-Thomas
anger is offline   Reply With Quote

Old   November 14, 2009, 12:47
Default
  #156
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 anger View Post
Hello,

I have two more questions regarding pyFoam:

1) I tried to read a binary U filed into a ParsedParameterFile to do some changes in it; but reading resulted in an error. Is this due to a misuse or can this class handle only ascii and compressed ascii files?
The second: it can only handle ASCII-files. The reason is simply that always use ASCII and I forgot about binary (really!). I'll have a look. The least PyFoam can do is throw a more meaningful error/exception. about really parsing it: if it can be done without making the parser more complicated I'll consider it.

Quote:
Originally Posted by anger View Post
2) I also tried to do the parameter variation as described in the OF wiki section 2.2 and was really happy that changing the condition on a filed called "inlet" worked well; but to my big big surprise, changing the value of a field called "outlet" did not work! The value was just added, but the old one was not commented out. I noticed that the type of m in the source code was of type string while for "inlet", it is of some other type resulting in using another code line in the if- expression which is responsible for writing the new value to the file.
That is really strange. Could you show me the code (it must be quite different from the example on the Wiki as there is no if-expression in that example)

Is the file you're working on ASCII or Binary? I'm afraid the SolutionFile-class that is used in that example is not aware of Binary-files either

Quote:
Originally Posted by anger View Post
Did anyone experience similar behaviour? I'm really stuck at this point and have no idea where to do research in the code as I'm quite new to pyFoam (which is a very useful piece of software).
Thanks
gschaider is offline   Reply With Quote

Old   November 14, 2009, 16:05
Default
  #157
Member
 
Thomas Wolfanger
Join Date: Mar 2009
Location: South West Germany
Posts: 62
Rep Power: 17
anger is on a distinguished road
Quote:
Originally Posted by gschaider View Post
The second: it can only handle ASCII-files. The reason is simply that always use ASCII and I forgot about binary (really!). I'll have a look. The least PyFoam can do is throw a more meaningful error/exception. about really parsing it: if it can be done without making the parser more complicated I'll consider it.


That is really strange. Could you show me the code (it must be quite different from the example on the Wiki as there is no if-expression in that example)

Is the file you're working on ASCII or Binary? I'm afraid the SolutionFile-class that is used in that example is not aware of Binary-files either



Thanks
ok, thanks for the info; compressed ascii is ok, isn't it?

For the second question: sorry for being unclear; the thing about m is to be found in the source code of the replaceBoundary routine (line 89) of the SolutionFile class of pyFoam. The line I use in my python script is actually the same as in the wiki apart from the name of the field and some formatting; it works on T and U for a field named "inlet" but not on p for a field named "outlet". The p file I'm experiencing this strange behaviour on is ascii. It seems to me that in replaceBoundary, the wrong place is found, but I have no clue why this could be the case, because it works well for the name "inlet".

Thank you for any input,

Best regards,
-Thomas

I tried the following: I took a p file which was output by pyFoam and used this as base file to make the changes on. On the first try this didn't work either, so I edited the file and uncommented the first line which started with "//pyFoam added"; and now, replacing worked!
More information on m which might help to track down the problem (with the non-working file):
I get this output when adding a line "print m, type(m), l, l.line" on line 88 of SolutionFile.py
outlet } <type 'str'> <PyFoam.Basics.LineReader.LineReader object at 0x297a910> }

Thanks,
-Thomas

Last edited by anger; November 16, 2009 at 03:32. Reason: Additional info/workaround
anger is offline   Reply With Quote

Old   November 16, 2009, 06:53
Default
  #158
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 anger View Post
ok, thanks for the info; compressed ascii is ok, isn't it?
Yep. That is handled transparently.

Quote:
Originally Posted by anger View Post
For the second question: sorry for being unclear; the thing about m is to be found in the source code of the replaceBoundary routine (line 89) of the SolutionFile class of pyFoam. The line I use in my python script is actually the same as in the wiki apart from the name of the field and some formatting; it works on T and U for a field named "inlet" but not on p for a field named "outlet". The p file I'm experiencing this strange behaviour on is ascii. It seems to me that in replaceBoundary, the wrong place is found, but I have no clue why this could be the case, because it works well for the name "inlet".

Thank you for any input,

Best regards,
-Thomas

I tried the following: I took a p file which was output by pyFoam and used this as base file to make the changes on. On the first try this didn't work either, so I edited the file and uncommented the first line which started with "//pyFoam added"; and now, replacing worked!
More information on m which might help to track down the problem (with the non-working file):
I get this output when adding a line "print m, type(m), l, l.line" on line 88 of SolutionFile.py
outlet } <type 'str'> <PyFoam.Basics.LineReader.LineReader object at 0x297a910> }
I'll have a look. The problem is that SolutionFile is a legacy class that existed before ParsedParameterFile. These days I do most of this stuff with PPF. SolutionFile only has a performance advantage if you're handling files with large non-uniform fields, in all other case PPF is preferred because it is much more flexible and robust

BTW: The problem occurs with a "plain" file or is there some binary data in it?

Bernhard
gschaider is offline   Reply With Quote

Old   November 16, 2009, 07:06
Default EGR Flow rate calculation
  #159
Member
 
Venkat
Join Date: Nov 2009
Posts: 35
Rep Power: 16
enr_venkat is on a distinguished road
Hi everyone,

I'm a new registered user in CFD-Online. I would like to calculate theoretically the mass flow rate of air that pass through EGR Valve at different Valve seats positioningi.e. 1mm, 2mm, 3mm, 4mm, 5mm.. As i understand, the flow rate would increase gradually as the valve lift increases. I have the experimental data i.e. at 1mm valve lift, the mass flow rate is observed to be 6 - 8 kg/hr and at 7mm, flow rate is observed to be 10 kg/hr. My client wants to compare the theoretical calculation. Moreover, the flow is assumed to be incompressible as the density is constant with time.

Known values - Pressure drop (2 kpa), valve lift position (1mm to 7mm), Exhaust temperature 20 C, EGR Dia - 30 mm

Mass flow rate to be calculated : ?

I'm looking for an incompressible flow rate equation using which we could calculate flow rate. Please do the neeful
enr_venkat is offline   Reply With Quote

Old   November 16, 2009, 08:10
Default
  #160
Member
 
Thomas Wolfanger
Join Date: Mar 2009
Location: South West Germany
Posts: 62
Rep Power: 17
anger is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Yep. That is handled transparently.



I'll have a look. The problem is that SolutionFile is a legacy class that existed before ParsedParameterFile. These days I do most of this stuff with PPF. SolutionFile only has a performance advantage if you're handling files with large non-uniform fields, in all other case PPF is preferred because it is much more flexible and robust

BTW: The problem occurs with a "plain" file or is there some binary data in it?

Bernhard
Hello Bernhard,

yes, it is a plain ascii file.
The reason for using SolutionFile is that my first trial with PPF was on a binary file which failed so I thought this class could not be used for my task.

Best regards,
-Thomas
anger is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 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:25.