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   June 14, 2010, 09:02
Default
  #201
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by maddalena View Post
... so I will try the 2nd solution, it seems the easiest to implement.
Or...
  • is there any already implemented function to read only the last line of a file?
  • Or maybe I can search in the forceCoeffs.dat the line starting with the latestTime and extract the coefficient values.
The point is that frm me is difficult to understand what is implemented and how to use it. I am really a newbie in pyFoam!
Thanks,

mad
Reading the last line of a file is a one-liner (no pun intended) in Python

line=open("filename").readlines()[-1]

If you know that the line consists of floats separated by whitespaces you can get an array with the number with

data=map(float,open("filename").readlines()[-1].split())

If furthermore you happen to know that the data will be "<time> <lift> <drag>" then

time,lift,drag=map(float,open("filename").readline s()[-1].split())

will give you these numbers. But of course this expression is the easiest to break

Bernhard
gschaider is offline   Reply With Quote

Old   June 14, 2010, 09:48
Thumbs up
  #202
Senior Member
 
maddalena's Avatar
 
maddalena
Join Date: Mar 2009
Posts: 436
Rep Power: 11
maddalena is on a distinguished road
Ok, I know that this may be not "elegant", but this is the easiest way to get what I want!
Quote:
Originally Posted by gschaider View Post
If furthermore you happen to know that the data will be "<time> <lift> <drag>" then

time,lift,drag=map(float,open("filename").readline s()[-1].split())

will give you these numbers. But of course this expression is the easiest to break
Thanks a lot!

mad
maddalena is offline   Reply With Quote

Old   August 30, 2010, 08:50
Default Trying to use PyFOAM
  #203
Senior Member
 
BastiL
Join Date: Mar 2009
Posts: 462
Rep Power: 10
bastil is on a distinguished road
Hi Bernhard,

I try to use PyFOAM for some time now and I have to say it is a great tool alowing me to do some changes in my files easily. However, I have one minor issue:

I have written a Python-Skript using PyFOAM to modify some boundaries. Everything works fine except the fact that I get two files in my directory afterwards:

PlyParser_FoamFileParser_parsetab.py and
PlyParser_FoamFileParser_parsetab.pyc

I guess these are temporal files generated by the ply-Parser but I don't really know why they are not deleted. As soon as I use one of the default PyFOAM scripts this does not occur. Do I have to do something like closing files?

Thanks Bastian
bastil is offline   Reply With Quote

Old   August 30, 2010, 12:34
Default
  #204
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by bastil View Post
Hi Bernhard,

I try to use PyFOAM for some time now and I have to say it is a great tool alowing me to do some changes in my files easily. However, I have one minor issue:

I have written a Python-Skript using PyFOAM to modify some boundaries. Everything works fine except the fact that I get two files in my directory afterwards:

PlyParser_FoamFileParser_parsetab.py and
PlyParser_FoamFileParser_parsetab.pyc

I guess these are temporal files generated by the ply-Parser but I don't really know why they are not deleted. As soon as I use one of the default PyFOAM scripts this does not occur. Do I have to do something like closing files?
If I remember it correctly they are saved as a sort-of caching mechanism: if the grammar is unchanged and it finds those file they are not rebuilt. But I may be wrong. Anyway: it never bothered too much so I accepted them. But if there is sufficient interest (which woud manifest itself in a bug-report on the OF-extend-Mantis) I will have a look at it

Bernhard
gschaider is offline   Reply With Quote

Old   February 3, 2011, 03:40
Default pyFoamPlotWatcher - customRegExp
  #205
Member
 
Antonio Liggieri
Join Date: Aug 2010
Posts: 64
Rep Power: 5
alfa_8C is an unknown quantity at this point
Hy all,

does anybody know, why this expression in customRegExp . file doesn't work?

This is how the string appears on the screen or log file respectively:

volAverage(heatSource) for T = 293
 
And this is my expression:

{"expr":"volAverage(heatSource) for T = (%f%)","name":"Source","title":["Temp"]}

There is neither an error message nor a plot is being shown as I would expect it.

Thank you in advance,
Toni
alfa_8C is offline   Reply With Quote

Old   February 3, 2011, 09:34
Default
  #206
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by alfa_8C View Post
Hy all,

does anybody know, why this expression in customRegExp . file doesn't work?

This is how the string appears on the screen or log file respectively:

volAverage(heatSource) for T = 293
 
And this is my expression:

{"expr":"volAverage(heatSource) for T = (%f%)","name":"Source","title":["Temp"]}

There is neither an error message nor a plot is being shown as I would expect it.

Thank you in advance,
Toni
At first: I asssume you have a customRegexp-file (case is important)

The problem here is that for regular expressions (not PyFoams fault not even Pythons. That is the way god created regular expressions) the brackets () have a special meaning. So in order to match a ( you're got to write \( in your expression. Same goes for ) but is left to the reader as an exercise

Bernhard
gschaider is offline   Reply With Quote

Old   February 4, 2011, 07:54
Default
  #207
Member
 
Antonio Liggieri
Join Date: Aug 2010
Posts: 64
Rep Power: 5
alfa_8C is an unknown quantity at this point
ok thanx - now it works properly ;-)

one further question.

how must the expression look like, if I want to plot more than one value from log file in the same plot-window?
alfa_8C is offline   Reply With Quote

Old   February 4, 2011, 10:51
Default
  #208
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by alfa_8C View Post
ok thanx - now it works properly ;-)

one further question.

how must the expression look like, if I want to plot more than one value from log file in the same plot-window?
Find a short but crisp example at http://openfoamwiki.net/index.php/Co...oam#New_format (the master/slave-thing)
gschaider is offline   Reply With Quote

Old   February 4, 2011, 11:00
Default
  #209
Member
 
Antonio Liggieri
Join Date: Aug 2010
Posts: 64
Rep Power: 5
alfa_8C is an unknown quantity at this point
I'm still using the old format. As I understand this type: slave; issue is only possible by using the new "openFoam-like" format right?
I can't make out how to apply this to my old format... sorry for the inconvenience...
alfa_8C is offline   Reply With Quote

Old   February 4, 2011, 16:27
Default
  #210
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by alfa_8C View Post
I'm still using the old format. As I understand this type: slave; issue is only possible by using the new "openFoam-like" format right?
I can't make out how to apply this to my old format... sorry for the inconvenience...
Won't work in the old format. Internally everything (old and new format) is converted to the same data structures but the young format knows more than the old format (that is where it differs from real life ). The good news (not exactly new: it is there since I moved to the new format and it was always "hidden" in the online help) is that every utility that uses customRegex has the option --dump-custom-regegex that prints out these data-structures in the new format. So run the PlotWatcher with this option on a case with the old format and replace the customRegex with the output. Story ends with "and he lived happily ever after with the new format"
gschaider is offline   Reply With Quote

Old   May 11, 2011, 10:04
Default
  #211
New Member
 
Join Date: Mar 2011
Posts: 6
Rep Power: 5
sakro is on a distinguished road
Hello, I faced really annoying problem and will be very thankful if you help me =)

I'm using pyFoamCaseBuilder.py for generating cases from Star-ccm+. Everything works well until boundaries are not named using character '-', in this case pyFoamCaseBuilder.py complains

Quote:
Building case testCase
Error in /usr/local/bin/pyFoamCaseBuilder.py : Illegal character '-'
Since main script for Star-ccm+ uses naming-convention for boundaries
like:

Quote:
Patch:000-DOMAIN_INLET
Patch:000-DOMAIN_OUTLET
it is essential for me to be able to handle these situations,
thanks in advance
sakro is offline   Reply With Quote

Old   May 11, 2011, 10:24
Default
  #212
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sakro View Post
Hello, I faced really annoying problem and will be very thankful if you help me =)

I'm using pyFoamCaseBuilder.py for generating cases from Star-ccm+. Everything works well until boundaries are not named using character '-', in this case pyFoamCaseBuilder.py complains

Since main script for Star-ccm+ uses naming-convention for boundaries
like:

it is essential for me to be able to handle these situations,
thanks in advance
Which version of PyFoam are you using? Chech with pyFoamVersion.py

Is there a longer stack-trace?

Does pyFoamEchoDictionary.py work for the file in question?

Please write a bug-report providing this information and if possible example files to reproduce it (you find a link to the Mantis at the Wiki-page of PyFoam) and I'll have a look at it
gschaider is offline   Reply With Quote

Old   May 11, 2011, 11:07
Default
  #213
New Member
 
Join Date: Mar 2011
Posts: 6
Rep Power: 5
sakro is on a distinguished road
I'm using 0.5.5;

well, I figured out, that this is generally inappropriate name for a boundary that begins with a digit (So boundary name should be an identifier, it is not the same in Star-ccm+). Didn't know that

since I have names for boundaries like "000-DOMAIN_INLET" pyFoamEchoDictionary.py complains

Quote:
Error in /usr/local/bin/pyFoamEchoDictionary.py : Illegal character '-'
So it is not a PyFoam issue, sorry for interruption
sakro is offline   Reply With Quote

Old   May 11, 2011, 18:31
Default
  #214
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by sakro View Post
I'm using 0.5.5;

well, I figured out, that this is generally inappropriate name for a boundary that begins with a digit (So boundary name should be an identifier, it is not the same in Star-ccm+). Didn't know that

since I have names for boundaries like "000-DOMAIN_INLET" pyFoamEchoDictionary.py complains



So it is not a PyFoam issue, sorry for interruption
Just to clarify: if OF accepts a patch name 00-DOMAIN_INLET (and I wouldn't be surprised if it does) and PyFoam doesn't then this is a bug in PyFoam (how strange that name may seem. Strange mainly for those who are used to programming languages)

is this name accepted by the usual OF-utilities?

Bernhard
gschaider is offline   Reply With Quote

Old   May 12, 2011, 06:40
Default
  #215
New Member
 
Join Date: Mar 2011
Posts: 6
Rep Power: 5
sakro is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Just to clarify: if OF accepts a patch name 00-DOMAIN_INLET (and I wouldn't be surprised if it does) and PyFoam doesn't then this is a bug in PyFoam (how strange that name may seem. Strange mainly for those who are used to programming languages)

is this name accepted by the usual OF-utilities?

Bernhard

That is how I checked it yesterday:
1. copied pitzDaily tutorial
2. in the directory of copied tutorial
pyFoamChangeBoundaryName.py . inlet 000-DOMAIN_INLET --time-step=0
3. simpleFoam

Quote:
Create time

Create mesh for time = 0

--> FOAM Warning :
From function entry::getKeyword(keyType&, Istream&)
in file db/dictionary/entry/entryIO.C at line 77
Reading /run/incompressible/simpleFoam/pitzDaily/constant/polyMesh/boundary
found on line 14 the doubleScalar 0
expected either } or EOF


--> FOAM FATAL ERROR:
hanging pointer, cannot dereference

From function PtrList:perator[]
in file lnInclude/PtrListI.H at line 122.

FOAM aborting

#0 Foam::error:rintStack(Foam::Ostream&) in "/opt/openfoam171/lib/linux64GccDPOpt/libOpenFOAM.so"
#1 Foam::error::abort() in "/opt/openfoam171/lib/linux64GccDPOpt/libOpenFOAM.so"
#2 Foam:olyBoundaryMesh:olyBoundaryMesh(Foam::IOo bject const&, Foam:olyMesh const&) in "/opt/openfoam171/lib/linux64GccDPOpt/libOpenFOAM.so"
#3 Foam:olyMesh:olyMesh(Foam::IOobject const&) in "/opt/openfoam171/lib/linux64GccDPOpt/libOpenFOAM.so"
#4 Foam::fvMesh::fvMesh(Foam::IOobject const&) in "/opt/openfoam171/lib/linux64GccDPOpt/libfiniteVolume.so"
#5
in "/opt/openfoam171/applications/bin/linux64GccDPOpt/simpleFoam"
#6 __libc_start_main in "/lib/libc.so.6"
#7
in "/opt/openfoam171/applications/bin/linux64GccDPOpt/simpleFoam"
Aborted
there is no proper error message in OF about that, but it definitely doesn't work =)

I'd note that although "pyFoamChangeBoundaryName.py . inlet 000-DOMAIN_INLET --time-step=0" done its work, after that I couldn't do, say:


Quote:
pitzDaily$ pyFoamEchoDictionary.py 0/U
Error in /usr/local/bin/pyFoamEchoDictionary.py : Illegal character '-'
ps: just noticed that if you change all "inlet" to "000-INLET_OUTLET" by hands than the error that simpleFoam gives you is different:


Quote:
Create mesh for time = 0

--> FOAM Warning :
From function entry::getKeyword(keyType&, Istream&)
in file db/dictionary/entry/entryIO.C at line 77
Reading /run/incompressible/simpleFoam/pitzDaily/constant/polyMesh/boundary
found on line 26 the doubleScalar 0
expected either } or EOF


--> FOAM FATAL IO ERROR:
Expected a ')' or a '}' while reading PtrList, found on line 44 the word 'frontAndBack'

file: /run/incompressible/simpleFoam/pitzDaily/constant/polyMesh/boundary at line 44.

From function Istream::readEndList(const char*)
in file db/IOstreams/IOstreams/Istream.C at line 151.

FOAM exiting
Alexander
sakro is offline   Reply With Quote

Old   June 3, 2011, 09:55
Default
  #216
Senior Member
 
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 526
Rep Power: 15
philippose will become famous soon enough
Hello Bernhard,

A Good Day to you! Its been a while, and I hope everything is going great with you!

I have been using PyFoam over the last few days to automate some post-processing of OpenFOAM Simulations, and have the following questions / observations:

1. I use a CIFS (Samba) share mounted on my Linux system as my Simulation folder. When using the "SolutionDictionary" class, the constructor quits with an error that the file-system does not support symbolic links. ..... I found out that I can prevent this by using the "paraviewLink=False" entry when calling the constructor, but maybe it would be more elegant if we detect this in the code and make a copy of controlDict to controlDict.foam instead of a symbolic link?


2. When using the "ParsedParameterFile" class, I noticed that the "macroExpansion" option assumes that the path to the "#include" files are relative to the location of the dictionary. .... There are a couple of issues in this case....:

.... 2[a]. It is not always the case that a relative path is used when specifying the location of the file.... it could also be an absolute path, in which case, the line 511 in ParsedParameterFile.py would not provide a usable path.

.... 2[b]. The path may contain environment variables.... in my case this might prove to be a little more difficult, because I used "$FOAM_CASE" which looks like is only valid when actually running the case. ..... However, in general, maybe the python function "os.path.expandvars" should be used on the specified include file before trying to open it.

.... 2[c]. I am not exactly sure what to do in the case when the environment variable is "$FOAM_CASE"..... I was wondering if it makes sense for ParsedParameterFile to consider such special cases and put in the appropriate path.... what do you think?


3. When using pyFoamReadDictionary.py or pyFoamWriteDictionary.py, if the path to the file to be opened is "<case_root>/processor<n>/0/U" .... a processor directory of a parallel case, the script quits with an error.... I have come to the level where it looks like the error is coming from the "ParsedParameterFile" class, but I have not been able to figure out exactly what is causing the issue..... could you please look into this?


Other than these points, I must say..... PyFoam really does a great job :-)! I somehow always stuck to bash scripts for post-processing, but I think thats going to change really fast now.... :-)!

Thanks a lot for all the effort you and the other contributors have put into PyFoam....

Have a great weekend!

Philippose
philippose is offline   Reply With Quote

Old   June 6, 2011, 13:51
Default
  #217
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by philippose View Post
Hello Bernhard,

A Good Day to you! Its been a while, and I hope everything is going great with you!

I have been using PyFoam over the last few days to automate some post-processing of OpenFOAM Simulations, and have the following questions / observations:

1. I use a CIFS (Samba) share mounted on my Linux system as my Simulation folder. When using the "SolutionDictionary" class, the constructor quits with an error that the file-system does not support symbolic links. ..... I found out that I can prevent this by using the "paraviewLink=False" entry when calling the constructor, but maybe it would be more elegant if we detect this in the code and make a copy of controlDict to controlDict.foam instead of a symbolic link?
I always considered a file-system that doesn't support symbolic links to be crippled. But obviously I'm wrong.

But this can be done. Please write a bug-report at https://sourceforge.net/apps/mantisb...l_bug_page.php

Quote:
Originally Posted by philippose View Post
2. When using the "ParsedParameterFile" class, I noticed that the "macroExpansion" option assumes that the path to the "#include" files are relative to the location of the dictionary. .... There are a couple of issues in this case....:

.... 2[a]. It is not always the case that a relative path is used when specifying the location of the file.... it could also be an absolute path, in which case, the line 511 in ParsedParameterFile.py would not provide a usable path.

.... 2[b]. The path may contain environment variables.... in my case this might prove to be a little more difficult, because I used "$FOAM_CASE" which looks like is only valid when actually running the case. ..... However, in general, maybe the python function "os.path.expandvars" should be used on the specified include file before trying to open it.

.... 2[c]. I am not exactly sure what to do in the case when the environment variable is "$FOAM_CASE"..... I was wondering if it makes sense for ParsedParameterFile to consider such special cases and put in the appropriate path.... what do you think?
All this seems serious. Please help me to keep track of these issues by writing a bug report at https://sourceforge.net/apps/mantisb...l_bug_page.php (just copy/paste the description)

Quote:
Originally Posted by philippose View Post
3. When using pyFoamReadDictionary.py or pyFoamWriteDictionary.py, if the path to the file to be opened is "<case_root>/processor<n>/0/U" .... a processor directory of a parallel case, the script quits with an error.... I have come to the level where it looks like the error is coming from the "ParsedParameterFile" class, but I have not been able to figure out exactly what is causing the issue..... could you please look into this?
Same as before: https://sourceforge.net/apps/mantisb...l_bug_page.php (sorry. But that way we're not relying on my poor brain to remember these bugs)


Quote:
Originally Posted by philippose View Post
Other than these points, I must say..... PyFoam really does a great job :-)! I somehow always stuck to bash scripts for post-processing, but I think thats going to change really fast now.... :-)!

Thanks a lot for all the effort you and the other contributors have put into PyFoam....

Have a great weekend!

Philippose
Thanks
gschaider is offline   Reply With Quote

Old   June 6, 2011, 18:09
Default
  #218
Senior Member
 
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 526
Rep Power: 15
philippose will become famous soon enough
Hello Bernhard,

A Good Evening to you!

Thanks a lot for your response.

I just submitted two bug reports to the Mantis bug-tracker to cover the issues [1] and [2].

Before I submit a bug report for the issue [3] which I had mentioned in the post, I would like to look a little deeper into the actual error I get. I dont thing the information I currently have will be enough for a decent bug report.

Let me know if you would like me to try any changes that you make, or if you want me to try and solve the issues in case you are too busy.


One more question..... did you have a specific reason for using system shell commands for operations such as copy (cp) and delete (rm) instead of for example, the python "shutil" module? .... I was trying to think in terms of platform independence (Windows ports of OpenFOAM).

I remember that a long time ago you had mentioned that platform independence was not part of the specifications of PyFoam.... are you considering going down the platform independence route in the future sometime?

Have a great day!

Philippose
philippose is offline   Reply With Quote

Old   June 7, 2011, 07:54
Default
  #219
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,889
Rep Power: 38
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by philippose View Post
Hello Bernhard,

A Good Evening to you!

Thanks a lot for your response.

I just submitted two bug reports to the Mantis bug-tracker to cover the issues [1] and [2].

Before I submit a bug report for the issue [3] which I had mentioned in the post, I would like to look a little deeper into the actual error I get. I dont thing the information I currently have will be enough for a decent bug report.

Let me know if you would like me to try any changes that you make, or if you want me to try and solve the issues in case you are too busy.
Seen those. Thanks. I'll have a look what I can do this week

Quote:
Originally Posted by philippose View Post
One more question..... did you have a specific reason for using system shell commands for operations such as copy (cp) and delete (rm) instead of for example, the python "shutil" module?
Reason is that when these parts were implemented I was using (because this was the system default) python2.3 and AFAIK shutil was introduced in 2.4

Quote:
Originally Posted by philippose View Post
.... I was trying to think in terms of platform independence (Windows ports of OpenFOAM).

I remember that a long time ago you had mentioned that platform independence was not part of the specifications of PyFoam.... are you considering going down the platform independence route in the future sometime?
Well I try to be as platform independent as possible (for instance consequent usage of os.path). What I meant is that I never tested it on windows. It is not very likely that I'll do that in the next time (unless a customer asks me too). It's not what I consider an interesting project
gschaider is offline   Reply With Quote

Old   June 25, 2011, 16:05
Question Problem with OF_2.0.x and pyFoamPlotWatcher.py
  #220
New Member
 
Join Date: Oct 2009
Location: Germany
Posts: 18
Rep Power: 7
Aurel is on a distinguished road
Hi,

the installation of the current pyFOAM version (0.5.5) as a regular user worked fine. I followed the Wiki (http://openfoamwiki.net/index.php/Co...m#Installation).

With the new OF version 2.0.x I've got problems. SimpleFoam doesn't work at all with pitzDaily tutorial.
I receive following message:

"aurel@aurel-desktop:~/OpenFOAM/aurel-2.0.x/run/pitzDaily$ simpleFoam > log & pyFoamPlotWatcher.py log
[1] 5283
Traceback (most recent call last):
File "/home/aurel/OpenFOAM/PyFOAM/bin/pyFoamPlotWatcher.py", line 3, in <module>
from PyFoam.Applications.PlotWatcher import PlotWatcher
ImportError: No module named PyFoam.Applications.PlotWatcher
aurel@aurel-desktop:~/OpenFOAM/aurel-2.0.x/run/pitzDaily$ "

For assistance to find the error I would be very grateful.

Best regards

Marc
Aurel 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 09:28


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