|
[Sponsors] |
[PyFoam] First discussion thread about PyFoam |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 16, 2018, 17:48 |
|
#301 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Code:
nu nu [0 2 -1 0 0 0 0] 1e-06; 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 Code:
nu 23; Code:
dict["nu"][2]=23 Code:
nu nu [0 2 -1 0 0 0 0] 23; Code:
In [1]: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile In [2]: pf=ParsedParameterFile("Examples/other/capillaryRise/constant/transportProperties") 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 |
||
March 7, 2018, 09:40 |
|
#302 |
New Member
Khomenko Maxim
Join Date: Aug 2015
Posts: 18
Rep Power: 11 |
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) |
|
March 14, 2018, 07:56 |
|
#303 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
__________________
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 |
||
June 28, 2018, 20:12 |
PyFoam downlaods but does not work
|
#304 |
Member
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9 |
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. |
|
June 28, 2018, 22:45 |
|
#305 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
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 |
||
June 29, 2018, 00:25 |
Installed PyFoam
|
#306 |
Member
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9 |
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 29, 2018 at 00:26. Reason: To be nice. |
|
June 29, 2018, 15:13 |
To be more specific about install.
|
#307 |
Member
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9 |
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. |
|
July 3, 2018, 20:12 |
Fixed Problem. I think.
|
#308 | |
Member
Chris Harding
Join Date: Dec 2016
Posts: 76
Rep Power: 9 |
Quote:
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 |
||
July 6, 2018, 16:16 |
How to Manipulate non dictionary file with PyFoam?
|
#309 |
Member
Jeff
Join Date: May 2016
Posts: 44
Rep Power: 10 |
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 |
|
August 8, 2018, 06:25 |
Problem with PyFoam
|
#310 | |
New Member
Viet-Dung NGUYEN
Join Date: Aug 2018
Posts: 4
Rep Power: 8 |
Hello HappyS5,
I have the same error. How you resolved it ? VD Quote:
|
||
December 27, 2018, 18:32 |
Using pyFoamPVSnapshot.py with vtk-data
|
#311 |
New Member
Hans Xaver
Join Date: Dec 2018
Location: Germany
Posts: 8
Rep Power: 7 |
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 |
|
December 29, 2018, 19:59 |
|
#312 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
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 |
||
January 31, 2019, 08:08 |
|
#313 |
Member
ssa
Join Date: Sep 2018
Posts: 93
Rep Power: 8 |
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. |
|
January 31, 2019, 09:44 |
|
#314 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
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 |
||
February 2, 2019, 09:03 |
|
#315 | |||||
New Member
Join Date: Nov 2018
Posts: 4
Rep Power: 8 |
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:
Quote:
Quote:
I've tried running pyFoamVersion.py. This is the output: Quote:
While attempting to use some of the scripts (to check whether my problem was only with some of them or global), I got: Quote:
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 |
||||||
April 9, 2019, 10:30 |
problem with pickledPlots
|
#316 |
New Member
Luismi
Join Date: Mar 2019
Posts: 1
Rep Power: 0 |
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]) |
|
January 28, 2020, 19:04 |
|
#317 |
Senior Member
Join Date: Jul 2019
Posts: 148
Rep Power: 7 |
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. |
|
January 29, 2020, 12:18 |
|
#318 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
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 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" ); } "count", "sum", "min", "max" are also possible. Finding their meaning is left as an exercise to the reader
__________________
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 |
||
March 11, 2020, 17:36 |
|
#319 |
New Member
Harry
Join Date: Jan 2019
Posts: 1
Rep Power: 0 |
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 |
|
March 12, 2020, 14:07 |
|
#320 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
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 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 |
||
|
|
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 |