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] problems with pyFoamSamplePlot.py (https://www.cfd-online.com/Forums/openfoam-community-contributions/61326-problems-pyfoamsampleplot-py.html)

gschaider October 22, 2009 05:52

Quote:

Originally Posted by olivier (Post 233583)
Then I am missing something, because I am poiting at the NumPy installation in the PYTHONPATH. I will try to have a look at it tomorrow. I hate when I am not admin...

Olivier

You're pointing AT numpy or one direcotry ABOVE it? Second is correct

bernarde November 30, 2009 04:09

Hi all

I had the same problem with the blank gnuplot's:

Quote:

Warning: empty x range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
I'm running Suse 11.1 and OF 1.6. I found the Numpy and Scipy aren't installed in Suse by default. Thus I had to install them from here:

http://software.opensuse.org/search

(just search for numpy and scipy and install both).

The plots then worked fine.

Regards

Bernard

bernarde November 30, 2009 04:14

Just another question - is there any way to zoom into certain areas of the plot?

If I right-click on the plot, I get a square that I can drag. I though this would produce a zoom of the area in the square, however I just get the following in the console:

Quote:

line 0: warning: Skipping unreadable file "/tmp/tmpDLaJzj.gnuplot/fifo"
line 0: warning: Skipping unreadable file "/tmp/tmpRWr59v.gnuplot/fifo"
line 0: No data in plot
The plots just remain the same.

gschaider November 30, 2009 07:42

Quote:

Originally Posted by bernarde (Post 238137)
Hi all

I had the same problem with the blank gnuplot's:



I'm running Suse 11.1 and OF 1.6. I found the Numpy and Scipy aren't installed in Suse by default. Thus I had to install them from here:

http://software.opensuse.org/search

(just search for numpy and scipy and install both).

The plots then worked fine.

Regards

Bernard

Yeah. It seems there are problems with Numeric (which is used as a fallback if numpy is not installed) especially on SuSE. pyFoamVersion.py says something in that sense, but it is not very clear Bernhard

gschaider November 30, 2009 07:47

Quote:

Originally Posted by bernarde (Post 238139)
Just another question - is there any way to zoom into certain areas of the plot?

If I right-click on the plot, I get a square that I can drag. I though this would produce a zoom of the area in the square, however I just get the following in the console:



The plots just remain the same.

That is a problem of the gnuplot-terminal (which by default is x11). That can not do it. There are gnuplot-terminals that could do it, but they are not supported by pyFoam. What you can try with the most recent PyFoam is use the plotting-implementation matplotlib. That can do that (zooming). The problem is that it does not work on all platforms (only one of two I tested so far ;) ), so: good luck Bernhard

hemph December 1, 2009 10:12

Quote:

Originally Posted by bernarde (Post 238137)
Hi all

I had the same problem with the blank gnuplot's:



I'm running Suse 11.1 and OF 1.6. I found the Numpy and Scipy aren't installed in Suse by default. Thus I had to install them from here:

http://software.opensuse.org/search

(just search for numpy and scipy and install both).

The plots then worked fine.

Regards

Bernard

Perfect! Got my graphs back again :)
//Rasmus

gschaider December 1, 2009 11:07

Quote:

Originally Posted by gschaider (Post 238177)
That is a problem of the gnuplot-terminal (which by default is x11). That can not do it. There are gnuplot-terminals that could do it, but they are not supported by pyFoam. What you can try with the most recent PyFoam is use the plotting-implementation matplotlib. That can do that (zooming). The problem is that it does not work on all platforms (only one of two I tested so far ;) ), so: good luck Bernhard

Sorry for the misinformation: the x11 terminal CAN do zooming, BUT not if it gets the data from a pipe (which is the case here), so sorry no possibility. So the only way to zoom the graphs is to force writing of the data with --write-files and afterwards visualize that data with the plotting program of your choice (or use --start and/or --end if you'Re only interested in a certain time-range)

Bernhard

braennstroem January 3, 2011 03:32

sorting of parsed dictionary
 
Hello Bernhard,

I have trouble understanding the sorting of your parser using the below expression:
f=ParsedParameterFile(fileDict)

Keys=f["addLayersControls"]["nameConventions"].keys()

for the fileDict:
addLayersControls
{
nameConventions // alphabetic order
{
GRO { nSurfaceLayers 4; }
ROT { nSurfaceLayers 6; }
WW { nSurfaceLayers 12; }
}
}

I would like to have the same order as it is listed in the dict;
unfortunately I get this order: ['WW', 'GRO', 'ROT'].

Do you have a hint or idea, how to get this!?
Would be great!

Regards!
Fabian

gschaider January 3, 2011 05:47

Quote:

Originally Posted by braennstroem (Post 289065)
Hello Bernhard,

I have trouble understanding the sorting of your parser using the below expression:
f=ParsedParameterFile(fileDict)

Keys=f["addLayersControls"]["nameConventions"].keys()

for the fileDict:
addLayersControls
{
nameConventions // alphabetic order
{
GRO { nSurfaceLayers 4; }
ROT { nSurfaceLayers 6; }
WW { nSurfaceLayers 12; }
}
}

I would like to have the same order as it is listed in the dict;
unfortunately I get this order: ['WW', 'GRO', 'ROT'].

Do you have a hint or idea, how to get this!?
Would be great!

Regards!
Fabian

The problem is that a dictionary usually does not have an order of the keys (the order is determined by the implementation). In your example the order of the definition is also the alphabetical order. To get the keys in alphabetical order (which is probably not what you want in the general case) just add Keys.sort(). If you need the stuff in the order of the definition (which in my opinion is not a good idea because that would mean that your OF-code depends on that order too and things might break should the implementation of dictionary.toc change) then something about the library would have to be changed. A quick fix would be to go to Basics/DataStructures.py and add to DictProxy a method
def keys(self): return self._order
(self._order is used to output stuff int the order of the definition) but this fix will NOT change the order if you iterate over the dictionary itself (without .keys())

Bernhard

braennstroem January 3, 2011 06:34

Hi Bernhard,

thanks for the quick response!

Quote:

Originally Posted by gschaider (Post 289078)
The problem is that a dictionary usually does not have an order of the keys (the order is determined by the implementation). In your example the order of the definition is also the alphabetical order. To get the keys in alphabetical order (which is probably not what you want in the general case) just add Keys.sort().

Yes, I tried the sort(), but is not suitable for this task.

Quote:

Originally Posted by gschaider (Post 289078)
If you need the stuff in the order of the definition (which in my opinion is not a good idea because that would mean that your OF-code depends on that order too and things might break should the implementation of dictionary.toc change) then something about the library would have to be changed.

In this case, pyFoam is used as a preprossing tool setting the number of layers in snappyHexMeshDict based on given name conventions. So it 'just' creates the snappyDict according to another Dict... So similar to the regexp stuff from 1.6.x on, I would be able to first set all patches depended on the first entry and the second could overwrite the setting...

Quote:

Originally Posted by gschaider (Post 289078)
A quick fix would be to go to Basics/DataStructures.py and add to DictProxy a method
def keys(self): return self._order
(self._order is used to output stuff int the order of the definition) but this fix will NOT change the order if you iterate over the dictionary itself (without .keys())

Works! Thanks!
Fabian

gschaider January 4, 2011 12:31

Quote:

Originally Posted by braennstroem (Post 289082)
Hi Bernhard,

thanks for the quick response!


Yes, I tried the sort(), but is not suitable for this task.


In this case, pyFoam is used as a preprossing tool setting the number of layers in snappyHexMeshDict based on given name conventions. So it 'just' creates the snappyDict according to another Dict... So similar to the regexp stuff from 1.6.x on, I would be able to first set all patches depended on the first entry and the second could overwrite the setting...


Works! Thanks!
Fabian

In the fix I sent you replace self._order with self._order[:] (this creates a copy of the list which avoids possible side-effects should somebody modify the list he gets - the original for returned a reference to the list)

Bernhard

Toorop September 30, 2011 08:01

Hi,
I would like to create a simple script that renders out a paraview state file at some time. I tried to reverse engineer your paraview related pyFoam utiliities and couldn't quite understand how the desired time is set.
My terminal command is:
Code:

paraview --script=./postproc/paraview/paraPlot.py
paraPlot.py
Code:

from paraview.simple import *

# load the state
servermanager.LoadState("./postproc/paraview/pw_pressure.pvsm")

# make sure that the view in the state is the active one
SetActiveView(GetRenderView())
GetActiveView()

# no success, no output
SetViewTime(800)

# now render and save
Render()
WriteImage("./postproc/paraview/pw_pic.png")

This method is not working, no output is generated. If I left out SetViewTime, there is a picture, but I guess paraview uses the time defined in the state file and my color isn't rescaled to data range as well.

My other try:
Code:

from paraview.simple import *

# load the state
servermanager.LoadState("./postproc/paraview/pw_pressure.pvsm")

# make sure that the view in the state is the active one so we don't have to refer to it by name
SetActiveView(GetRenderView())
view=GetActiveView()

view.ViewTime=0

# now render and save
view.Render()
view.WriteImage("./postproc/paraview/pw_pic.png")

The color is rescaled, but no output.
In both cases the legends aren't scaled to data range.

Is there a solution or one should modify the state file instead?
What's the command for quiting paraview at the end of the script?
Can someone advise some tutorials on python scripting paraview - stream tracer creation, slicing and contour plots, etc? This state file loading is not really impressive, contains a lot of boiler plate stuff, hard to edit and customize. It would be much better the other way around.

Thank you!

elvis September 30, 2011 08:28

Hi,

I think you are better served with Python Scripting http://paraview.org/Wiki/ParaView/Python_Scripting or http://paraview.org/Wiki/Take_a_Scre..._of_a_VTP_File

http://www.openfoamworkshop.org/6th_...rle_slides.pdf =>see slide Batch/reproducible workflow "topic macro"


All times are GMT -4. The time now is 09:44.