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   January 16, 2018, 16:48
Default
  #301
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 mbookin View Post
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?
The problem with OpenFOAM dictionaries is that only the C++-code that reads it knows what things actually mean. For instance for a dictionary entry
Code:
nu              nu [0 2 -1 0 0 0 0] 1e-06;
the value is just a bunch of input tokens "nu" "[" "0" ....
Only when dimensionedScalar uses that stream of tokens to initialize itself then it would make sense.
(another example would be "(0 1 0)": is it a vector or a list of lables or a list of scalars? Only the reading code can tell)

PyFoam tries to make sense of these as much as it can but is not carvoyant (it does a little interpretation)

For instance in the above example it interprets the value as a tuple with 3 items: a word, a dimensionSet and a value.

Now if the above example was read into a ParsedParameterFile with the name dict then
Code:
dict["nu"]=23
would throw away the whole tuple and you'd get
Code:
nu 23;
What you want is
Code:
dict["nu"][2]=23
which would give you
Code:
nu              nu [0 2 -1 0 0 0 0] 23;
Hint: to understand how a dictionary is represented by PyFoam use ipython. Start with something like
Code:
In [1]: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile

In [2]: pf=ParsedParameterFile("Examples/other/capillaryRise/constant/transportProperties")
and play around with pf

PS: the problem is the same for every library that tries to interpret Foam-dictionaries without knowing "what the solver wants"
PPS: of course I could interpret "a name, a dimension set, a number" as "dimensionedScalar". But that would break support for cases where actually "a name, a dimension set, a number" is meant (quite possible)
__________________
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   March 7, 2018, 08:40
Default
  #302
New Member
 
Khomenko Maxim
Join Date: Aug 2015
Posts: 16
Rep Power: 10
mbookin is on a distinguished road
Dear Bernard!

Thank you for your answers, could you please illuminate here one more issue on the pyFoam.

I use CSVCollection class for post-processing of logs after parsing dictionaries in the loop. The problem is that this class rewrites csv file every new loop, but I need to append new line every time. Is there a method or a workaround to append the line to existed csv file?
Code:
csv = CSVCollection (origCase.name+ ".csv")
for g in [1,2,3,4,5]
    ...
    ...
    lines = logfile.readlines()
    outputRegex=re.compile(pattern)
    for line in lines:
            match=re.search(outputRegex,line)
            if match:
                csv[" DCv "]=DCv
                csv[" rho2 "]=rho2
                csv[" nu2 "]=nu2
                csv[" leftWSP "]=float(match.group(1))
                csv[" rightWSP "]=float(match.group(2))
                csv.write()
                break
    if match:
        print ' outPut ok'
    else:
        print ' not found %s in %s' % (pattern, logfile)
This loop will make 5 lines in csv file, but running it twise will result in the same 5 lines, but not 10 that I need. Could you please help me here?
mbookin is offline   Reply With Quote

Old   March 14, 2018, 06:56
Default
  #303
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 mbookin View Post
Dear Bernard!

Thank you for your answers, could you please illuminate here one more issue on the pyFoam.

I use CSVCollection class for post-processing of logs after parsing dictionaries in the loop. The problem is that this class rewrites csv file every new loop, but I need to append new line every time. Is there a method or a workaround to append the line to existed csv file?
Code:
csv = CSVCollection (origCase.name+ ".csv")
for g in [1,2,3,4,5]
    ...
    ...
    lines = logfile.readlines()
    outputRegex=re.compile(pattern)
    for line in lines:
            match=re.search(outputRegex,line)
            if match:
                csv[" DCv "]=DCv
                csv[" rho2 "]=rho2
                csv[" nu2 "]=nu2
                csv[" leftWSP "]=float(match.group(1))
                csv[" rightWSP "]=float(match.group(2))
                csv.write()
                break
    if match:
        print ' outPut ok'
    else:
        print ' not found %s in %s' % (pattern, logfile)
This loop will make 5 lines in csv file, but running it twise will result in the same 5 lines, but not 10 that I need. Could you please help me here?
I'm afraid the only option would be to first read the CSV-file. Then add the data to the CSVCollection and then read the next file. It could be possible to add this to the constructor
__________________
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 28, 2018, 19:12
Default PyFoam downlaods but does not work
  #304
Member
 
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9
HappyS5 is on a distinguished road
Hello,

When I check PyFoam, I get the right path for the $FOAM_TUTORIALS. When I try to run PyFoam, I get the following:


happys5@chris-x:~/OpenFOAM/happys5-5.0/run/cavity/cavity$ pyFoamPlotRunner.py icoFoam
Traceback (most recent call last):
File "/usr/local/bin/pyFoamPlotRunner.py", line 4, in <module>
__import__('pkg_resources').run_script('PyFoam==0. 6.9', 'pyFoamPlotRunner.py')
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1429, in run_script
.format(**locals()),
pkg_resources.ResolutionError: Script 'scripts/pyFoamPlotRunner.py' not found in metadata at '/home/happys5/.local/lib/python2.7/site-packages/PyFoam-0.6.9.dist-info'

Can you help me please.

Note, I am new to Linux, OpenFOAM, and PyFoam. Ubuntu 18.04 is my OS.
HappyS5 is offline   Reply With Quote

Old   June 28, 2018, 21:45
Default
  #305
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 HappyS5 View Post
Hello,

When I check PyFoam, I get the right path for the $FOAM_TUTORIALS. When I try to run PyFoam, I get the following:


happys5@chris-x:~/OpenFOAM/happys5-5.0/run/cavity/cavity$ pyFoamPlotRunner.py icoFoam
Traceback (most recent call last):
File "/usr/local/bin/pyFoamPlotRunner.py", line 4, in <module>
__import__('pkg_resources').run_script('PyFoam==0. 6.9', 'pyFoamPlotRunner.py')
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1429, in run_script
.format(**locals()),
pkg_resources.ResolutionError: Script 'scripts/pyFoamPlotRunner.py' not found in metadata at '/home/happys5/.local/lib/python2.7/site-packages/PyFoam-0.6.9.dist-info'

Can you help me please.

Note, I am new to Linux, OpenFOAM, and PyFoam. Ubuntu 18.04 is my OS.

How did you install PyFoam? Because it seems that this is an installation problem


Bernhard
__________________
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 28, 2018, 23:25
Default Installed PyFoam
  #306
Member
 
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9
HappyS5 is on a distinguished road
Hello,

Thanks for the reply.

I installed PyFoam by both methods. PIP and Sources.

I followed the tutorial of the following video: https://youtu.be/z-UtCF1Cn0o

Last edited by HappyS5; June 28, 2018 at 23:26. Reason: To be nice.
HappyS5 is offline   Reply With Quote

Old   June 29, 2018, 14:13
Default To be more specific about install.
  #307
Member
 
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9
HappyS5 is on a distinguished road
I used:

$ pip install PyFoam

and:

$ sudo apt-get install python-dev
$ sudo apt-get install python-pip
$ pip install Numpy
$ sudo apt-get gnuplot gnuplot-x11
$ pip install PyFoam

From Sources:

I downloaded the tar file from "pypi.python.org" I then extracted the file to a Python folder on my home drive. When I got the above error, I tried running from Downloads folder as well. I changed directory to the extracted python folder.

$ sudo python setup.py install

I then checked that PyFoam was installed correctly.

$ python
>>> import python
>>> import PyFoam.FoamInformation
>>> print PyFoam.FoamInformation.foamTutorials()

The latter gave me the path to my installed OpenFOAM tutorials, which are in the opt/... path.

When I run, I get the errors that I mention above.
HappyS5 is offline   Reply With Quote

Old   July 3, 2018, 19:12
Default Fixed Problem. I think.
  #308
Member
 
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9
HappyS5 is on a distinguished road
Quote:
Originally Posted by gschaider View Post
How did you install PyFoam? Because it seems that this is an installation problem


Bernhard
I went to http://openfoamwiki.net/index.php/Co...#Prerequisites to see their installation procedures.

I performed an install as: $ pip install --user PyFoam

Once I did that, I can run PyFoam so far. I picked that install procedure because of:

Quote: "If you can not write to the global Python installation because you don't have administrative rights try"

Thanks, Bernard, for leading me down the install path. I also read some of your advice at: installation on Ubuntu 12.04
HappyS5 is offline   Reply With Quote

Old   July 6, 2018, 15:16
Default How to Manipulate non dictionary file with PyFoam?
  #309
Member
 
Jeff
Join Date: May 2016
Posts: 44
Rep Power: 9
jf_vt is on a distinguished road
Hi
a number of files in an OF case are not containing a dictionary.
Example: reactions file or definition file for utilities ( setSet and so forth)

Is there a PyFoam class that can be used to manipulate them ?

Right now I call a subprocess within my Python scripts with sed command for these files.
It does the job but is cumbersome on many levels

Thanks
JF
jf_vt is offline   Reply With Quote

Old   August 8, 2018, 05:25
Default Problem with PyFoam
  #310
New Member
 
Viet-Dung NGUYEN
Join Date: Aug 2018
Posts: 4
Rep Power: 7
Viet-Dung is on a distinguished road
Hello HappyS5,

I have the same error. How you resolved it ?

VD


Quote:
Originally Posted by HappyS5 View Post
Hello,

When I check PyFoam, I get the right path for the $FOAM_TUTORIALS. When I try to run PyFoam, I get the following:


happys5@chris-x:~/OpenFOAM/happys5-5.0/run/cavity/cavity$ pyFoamPlotRunner.py icoFoam
Traceback (most recent call last):
File "/usr/local/bin/pyFoamPlotRunner.py", line 4, in <module>
__import__('pkg_resources').run_script('PyFoam==0. 6.9', 'pyFoamPlotRunner.py')
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1429, in run_script
.format(**locals()),
pkg_resources.ResolutionError: Script 'scripts/pyFoamPlotRunner.py' not found in metadata at '/home/happys5/.local/lib/python2.7/site-packages/PyFoam-0.6.9.dist-info'

Can you help me please.

Note, I am new to Linux, OpenFOAM, and PyFoam. Ubuntu 18.04 is my OS.
Viet-Dung is offline   Reply With Quote

Old   December 27, 2018, 17:32
Default Using pyFoamPVSnapshot.py with vtk-data
  #311
New Member
 
Hans Xaver
Join Date: Dec 2018
Location: Germany
Posts: 8
Rep Power: 7
hansihans is on a distinguished road
Hi everyone,

Is it possible to use pyFoamPVSnapshot.py with some vtk-data ? I generated a state-file and tried, but it does not work:

>>pyFoamPVSnapshot.py --state-file=electrolyte.pvsm VTK/electrolyte/quickTest_120.vtk

Executing PVSnapshot with pvpython trough a proxy-script options:
Traceback (most recent call last):
File "/tmp/pyFoamPVSnapshot_zIGXs9.py", line 4, in <module>
PVSnapshot()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PVSnapshot.py", line 54, in __init__
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PyFoamApplication.py", line 495, in __init__
result=self.run()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PVSnapshot.py", line 419, in run
archive=None)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 69, in __init__
self.reread()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 560, in reread
procDirs = self.processorDirs()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 600, in processorDirs
for f in listdir(self.name):
OSError: [Errno 20] Not a directory: '/home/hans/OpenFOAM/hans-6/run/openfuelcell/run/quickTest/VTK/electrolyte/quickTest_120.vtk'
Error: Return code 1 executing /tmp/pyFoamPVSnapshot_zIGXs9.py


I tried to call the command without the file (error message says it is not a directory) like this:

>>pyFoamPVSnapshot.py --state-file=electrolyte.pvsm VTK/electrolyte/

Executing PVSnapshot with pvpython trough a proxy-script options:
Error in /tmp/pyFoamPVSnapshot_mjulaB.py : FatalError in PyFoam: 'PyFoam FATAL ERROR on line 125 of file /usr/local/lib/python2.7/dist-packages/PyFoam/Paraview/StateFile.py: Wrong number of Readers in State-File. Need 1 but got 0'
Error: Return code 255 executing /tmp/pyFoamPVSnapshot_mjulaB.py


So my question are:
1 Is it possible to use PVSnapshot with vtk-files ? It is just because in my case there are several regions that are nicely splittet in vtk-files.

2 Or is there a possibility to use it for only specific regions of the case ? (maybe with a option like "(foamToVTK) -region electrolyte")

3 Another question: can I also plot some graphs inside paraview or export the data of it (to plot it by myself with python) using PVSnapshot (or another pyFoam utility)?


I made a automatization script for parametervariation with pyfoam so far and as lazy as I am I do not want to save all the pictures with paraview by hand


thanks a lot
hansihans is offline   Reply With Quote

Old   December 29, 2018, 18:59
Default
  #312
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 hansihans View Post
Hi everyone,

Is it possible to use pyFoamPVSnapshot.py with some vtk-data ? I generated a state-file and tried, but it does not work:

>>pyFoamPVSnapshot.py --state-file=electrolyte.pvsm VTK/electrolyte/quickTest_120.vtk

Executing PVSnapshot with pvpython trough a proxy-script options:
Traceback (most recent call last):
File "/tmp/pyFoamPVSnapshot_zIGXs9.py", line 4, in <module>
PVSnapshot()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PVSnapshot.py", line 54, in __init__
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PyFoamApplication.py", line 495, in __init__
result=self.run()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PVSnapshot.py", line 419, in run
archive=None)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 69, in __init__
self.reread()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 560, in reread
procDirs = self.processorDirs()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 600, in processorDirs
for f in listdir(self.name):
OSError: [Errno 20] Not a directory: '/home/hans/OpenFOAM/hans-6/run/openfuelcell/run/quickTest/VTK/electrolyte/quickTest_120.vtk'
Error: Return code 1 executing /tmp/pyFoamPVSnapshot_zIGXs9.py


I tried to call the command without the file (error message says it is not a directory) like this:

>>pyFoamPVSnapshot.py --state-file=electrolyte.pvsm VTK/electrolyte/

Executing PVSnapshot with pvpython trough a proxy-script options:
Error in /tmp/pyFoamPVSnapshot_mjulaB.py : FatalError in PyFoam: 'PyFoam FATAL ERROR on line 125 of file /usr/local/lib/python2.7/dist-packages/PyFoam/Paraview/StateFile.py: Wrong number of Readers in State-File. Need 1 but got 0'
Error: Return code 255 executing /tmp/pyFoamPVSnapshot_mjulaB.py


So my question are:
1 Is it possible to use PVSnapshot with vtk-files ? It is just because in my case there are several regions that are nicely splittet in vtk-files.

2 Or is there a possibility to use it for only specific regions of the case ? (maybe with a option like "(foamToVTK) -region electrolyte")

3 Another question: can I also plot some graphs inside paraview or export the data of it (to plot it by myself with python) using PVSnapshot (or another pyFoam utility)?


I made a automatization script for parametervariation with pyfoam so far and as lazy as I am I do not want to save all the pictures with paraview by hand


thanks a lot

pyFoamSnapshot only replaces sources that are either the built-in OF-Paraview-Reader (extension: .foam) or the paraFoam-plugin (extension: .OpenFOAM). Other sources (VTK-files and similar) are left untouched


Specifying regions with pyFoamSnapshot is not possible


You can use PyFoam to read timeline data. Below are the relevan quotes from the PyFoam-Release notes. There is some documentation in the sources of the module

Code:
*** Paraview-module to read additional data
    A new module =PyFoam.Paraview.Data= reads additional data usually
    written by OpenFOAM. These are converted to =vtkArray= using the
    following functions and can be used in =Programmable filters=:
    - setSampleData :: reads the data from sampled sets
    - setTimelineData :: reads data from a timeline directory
    - setPlotData :: reads pickled plot data using =RedoPlot=
*** New function =setCurrentTimeline= in =PyFoam.Paraview.Data= to get data at time
    This function reads timeline data at a specified position. Return
    the interpolated values from the current simulation time as a
    table

    Use in =Programmable Filter=. Set output type to =vtkTable=.  To
    get the values from a timeline
    =postProcessing/swakExpression_pseudoTime/0/pseudoTime= use
: from PyFoam.Paraview.Data import setCurrentTimeline
: setCurrentTimeline(self.GetOutput(),"swakExpression_pseudoTime","pseudoTime")

    To print the values pipe into a =PythonAnnotation=-filter. Set
    ArrayAssociation to =Row Data= and use an Expression like
: "Time = %.1f (%.1f)" % (average,t_value)
    (this assumes that there is a column =average=)

    Hint: this reads string values as well. But in that case the value has to be
    converted with =val.GetValue(0)= in the expression
__________________
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 31, 2019, 07:08
Default
  #313
Member
 
ssa
Join Date: Sep 2018
Posts: 93
Rep Power: 7
ssa_cfd is on a distinguished road
Hi,

I am using pyFoamCaseReport.py and I have few suggestions.

The code only reads the linear solver for p. I think if other solvers are mentioned in combination like "(U|k|epsilon)" , it doesn't read.

And Is it possible to get data from fvschemes in case report.?

Thanks,
ssa.
ssa_cfd is offline   Reply With Quote

Old   January 31, 2019, 08:44
Default
  #314
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 ssa_cfd View Post
Hi,

I am using pyFoamCaseReport.py and I have few suggestions.

The code only reads the linear solver for p. I think if other solvers are mentioned in combination like "(U|k|epsilon)" , it doesn't read.

And Is it possible to get data from fvschemes in case report.?

Thanks,
ssa.

Hi!


The problem with reporting the linear solvers that match a regular expression is that you're opening a can of worms here: Your example is quite straightforward: report solver for U, k, epsilon. But what to do for "p.*"? Apart from the "usual suspects" p, p_rgh, pcorr this would report for a possibly infinte number of fields from "p0" to "proud2SayThatThisIsAlsoALegitimateFieldName". Of course one possiblity would be to have a "positive list" of solvers to report (U, p, p_rgh ...) but that would often report solvers that are not used in the current case



For the fvSchemes I didn't implement anything because I couldn't think of a meaningful report that goes beyond slightly reformatting the contents of this file. Also the "regular expression"-case



That doesn't mean that I'm completely against these extensions but before attempting an implementation I would need concrete suggestions how that output should look like


Bernhard
__________________
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   February 2, 2019, 08:03
Default
  #315
New Member
 
Join Date: Nov 2018
Posts: 4
Rep Power: 7
miguel.delasheras is on a distinguished road
Hello everyone: I'm trying to (unsuccessfully) install pyFoam in my computer. I've been trying to follow the instructions provided in this link:

https://openfoamwiki.net/index.php/C...e_installation

I followed the steps to make the installation as root. My terminal window looks like this:

Quote:
MacBook-Air-de-Fernando:PyFoam-0.6.10 Fernando$ pwd
/Users/Fernando/Downloads/PyFoam-0.6.10
MacBook-Air-de-Fernando:PyFoam-0.6.10 Fernando$ sudo python setup.py install
Password:
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
/usr/bin/python -E -c pass
TEST PASSED: /Library/Python/2.7/site-packages/ appears to support .pth files

...
...
... (and on)

Processing dependencies for PyFoam==0.6.10
Searching for numpy==1.8.0rc1
Best match: numpy 1.8.0rc1
Adding numpy 1.8.0rc1 to easy-install.pth file

Using /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Finished processing dependencies for PyFoam==0.6.10
Everything seemed to be okay, so I followed the instructions to carry out some testing for the installation. However, the line:

Quote:
print PyFoam.FoamInformation.foamTutorials()
returned nothing. I've checked the path where my pyFoam directory is, and it seems to be available to Python:

Quote:
print PyFoam.FoamInformation.foamTutorials()

>>> import sys
>>> print sys.path
['', '/Library/Python/2.7/site-packages/pip-19.0.1-py2.7.egg', '/Library/Python/2.7/site-packages/PyFoam-0.6.10-py2.7.egg', '/Users/Fernando/my_python/lib/python-2.7/site-packages', '/Users/Fernando/Downloads/PyFoam-0.6.10'
... (and on)
I did notice that the executable was actually inside a sub-folder named Olesen_centralInstallation (including files for additional features, as far as I know). I moved it to the directory in red so that Python would be able to determine its path correctly.

I've tried running pyFoamVersion.py. This is the output:

Quote:
MacBook-Air-de-Fernando:~ Fernando$ pyFoamVersion.py

...

Python 2.7 is one development platform for PyFoam (along with Python 3)
PYTHONPATH: /Users/Fernando/my_python/lib/python-2.7/site-packages:

Location of this utility: /usr/local/bin/pyFoamVersion.py

PyFoam WARNING on line 202 of file /Library/Python/2.7/site-packages/PyFoam-0.6.10-py2.7.egg/PyFoam/FoamInformation.py : Basedir /Users/Fernando/OpenFOAM for fork openfoam does not exist or is not a directory
PyFoam WARNING on line 202 of file /Library/Python/2.7/site-packages/PyFoam-0.6.10-py2.7.egg/PyFoam/FoamInformation.py : Basedir /Users/Fernando/foam for fork extend does not exist or is not a directory
PyFoam WARNING on line 202 of file /Library/Python/2.7/site-packages/PyFoam-0.6.10-py2.7.egg/PyFoam/FoamInformation.py : Basedir /Users/Fernando/OpenFOAM for fork openfoamplus does not exist or is not a directory

Version () (reported as number )Fork openfoam of the installed 0 versions:

... (and on)
I don't know what to do about those warnings typed in red.

While attempting to use some of the scripts (to check whether my problem was only with some of them or global), I got:

Quote:
PyFoam WARNING on line 381 of file /Library/Python/2.7/site-packages/PyFoam-0.6.10-py2.7.egg/PyFoam/Applications/PyFoamApplication.py : $WM_PROJECT_VERSION unset. PyFoam will not be able to determine the OpenFOAM-version and behave strangely
Along with a "Broken pipe" error. I'm wondering if this has to do with the fact that I'm running OpenFoam with a Docker installation. I tried to install pyFoam with the files in this link as well:
https://bitbucket.org/bgschaid/swak4...foamdockerfile (

but I only found one file for my 6.0 version which I didn't know how to treat.

I don't know if this is too much information or too little. Please let me know if you have any suggestions, I have tried many different approaches before asking. Thank you
miguel.delasheras is offline   Reply With Quote

Old   April 9, 2019, 09:30
Default problem with pickledPlots
  #316
New Member
 
Luismi
Join Date: Mar 2019
Posts: 1
Rep Power: 0
luismhy_foam is on a distinguished road
Hi everyone!

I have a little problem with the file pickledPlots. I´ḿ trying to execute a script which basically solve different simulations by changing the inlet velocity of a basic elbow. The idea is to create a loop in which the script will change this parameter and write the results in an Excel sheet (besides some plots are obtained as well).

The script works perfectly, but I have the problem that the different results in the Excel sheets are the same for each case, and they are the results of the first velocity used.

By looking into the cause of this problem, I have noticed that the file pickledPlots in each iteration stores the data of the previous iterations. For example, in this case, the pickledPlots of the first simulation weighs 23 kB, the second one 46, the third one 69....I suppose the application RedoPlot is taking into account only the first part of the file and this is the reason for the problem.

By doing the same using different scripts for each velocity, the problem dissappears and each file weighs the same, so I assume the pickled data of each iteration is being stored in some place, but I don´t know where.

I would really appreciate if someone could give me a hand. Thanks in advance!!

Code:
from os import path
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
from PyFoam.Basics.DataStructures import Vector    
from numpy import linspace
from PyFoam.Applications.PlotRunner import PlotRunner
from PyFoam.Applications.RedoPlot import RedoPlot
import psutil

velocity = linspace(0.050,0.060,3) 


templateCase = SolutionDirectory("elbow-template", archive=None, paraviewLink=False)

for vI in velocity:
    case=templateCase.cloneCase("elbow-v%.3f"%vI)
    velBC=ParsedParameterFile(path.join(case.name,"0","U"))
    velBC["boundaryField"]["inlet"]["value"].setUniform(Vector(vI,0,0))
    velBC.writeFile()
    theRun = PlotRunner(args=["--silent","simpleFoam","-case",case.name])
    thePlots=RedoPlot(args=["--pickle-file","codo-v%.3f/Gnuplotting.analyzed/pickledPlots"%vI,"--picture-prefix=v%.3f"%vI])
    theExcel=RedoPlot(args=["--pickle-file","codo-v%.3f/Gnuplotting.analyzed/pickledPlots"%vI,"--excel-files","--file-prefix=v%.3f"%vI])
luismhy_foam is offline   Reply With Quote

Old   January 28, 2020, 18:04
Default
  #317
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
Hi,

I am using 5 PIMPLE iterations. I realized that pyFoamPlotWatch shows only the residuals of the first PIMPLE iteration.

I am wondering if there is a way to plot the fifth PIMPLE iteration since it represents the most updated values of residuals in a time step.

Thanks. I look forward to hearing from you.
Bodo1993 is offline   Reply With Quote

Old   January 29, 2020, 11:18
Default
  #318
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 Bodo1993 View Post
Hi,

I am using 5 PIMPLE iterations. I realized that pyFoamPlotWatch shows only the residuals of the first PIMPLE iteration.

I am wondering if there is a way to plot the fifth PIMPLE iteration since it represents the most updated values of residuals in a time step.

Thanks. I look forward to hearing from you.

Hi. The reason why the first residual is plotted is that usually you want to know "how bad is the solution we started with"


One possibility to get the data you want is to call the watcher like this

Code:
pyFoamPlotWatcher.py PyFoamRunner.pimpleFoam.logfile --write-files --single-data-files
Then in PyFoamRunner.pimpleFoam.logfile.analyzed/linear_p you'll find all the residuals for p and you can plot them with your favourite program


Altnative would be to add to the customRegexp-file something like this:

Code:
lastIteration {
    theTitle "Last residual";
    type dynamic;
    idNr 1;
    expr "^.+:  Solving for (.+), Initial residual = (.+), Final residual = .+, No Iterations [0-9]+.*$";
    titles (
        "last"
    );
    logscale yes;
    accumulation last;
}
firstIteration {
    $lastIteration;
    type dynamicslave;
    master lastIteration;
    accumulation first;
    titles (
        "first"
    );
}
Important is the "accumulation"-keyword that says "take the last version you find at each time-step. Default is "first" (guess what that means. Yep. The first found value is used).



"count", "sum", "min", "max" are also possible. Finding their meaning is left as an exercise to the reader
HappyS5 likes this.
__________________
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   March 11, 2020, 16:36
Default
  #319
New Member
 
Harry
Join Date: Jan 2019
Posts: 1
Rep Power: 0
NowThenSun is on a distinguished road
Hi Bernard,

Thanks for making pyFOAM it's really great. One thing I've been a bit stuck with is when I have multiple versions of openFOAM which I activate through different aliases in my bashrc (e.g. of1912 to source openfoam v1912). This works fine for running pyFoam from the terminal but when trying to run pyFoam commands from a .py script it defaults to a particular version. How would I be able to choose the openFOAM version used by pyfoam within a script?

Thanks
NowThenSun is offline   Reply With Quote

Old   March 12, 2020, 13:07
Default
  #320
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 NowThenSun View Post
Hi Bernard,

Thanks for making pyFOAM it's really great. One thing I've been a bit stuck with is when I have multiple versions of openFOAM which I activate through different aliases in my bashrc (e.g. of1912 to source openfoam v1912). This works fine for running pyFoam from the terminal but when trying to run pyFoam commands from a .py script it defaults to a particular version. How would I be able to choose the openFOAM version used by pyfoam within a script?

Thanks
In a Python-script or in bash-script? PyFoam gets the information through the environment variables from the calling shell. One place where this might not be the place is in super-security-concious OSs like Mac OS X. Those erase some of the Environment variables (mostly PATH etc)


What should work in a shell-script is using the standard-option PyFoam has to select the Distro:
Code:
pyFoamRunner.py --foamVersion=openfoamplus-v1912 checkMesh
if you want to use the functionality of a PyFoam-script in your Python-program you can do something like
Code:
from PyFoam.Applications.Runner import Runner
r=Runner(args=["--foamVersion=openfoamplus-v1906","checkMesh"])
d=r.getData() #  Dictionary with results of the run
__________________
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

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 7, 2019 23:34
udf problem jane Fluent UDF and Scheme Programming 37 February 20, 2018 04:17
Guide: Getting Started with the CFD Online Discussion Forums pete Site Help, Feedback & Discussions 8 July 29, 2016 05:00
Error messages atg enGrid 7 August 30, 2013 11:16
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 14:37


All times are GMT -4. The time now is 16:21.