CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] tutorial problems

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Asghari_M

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2015, 04:49
Default tutorial problems
  #1
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Hi All Foamers,

I am going to learn PyFoam programming by doInletVariation.py tutorial file.
Pyton program for this file has been presented at following link:
https://openfoamwiki.net/index.php/C...ter_Variation;

However, I executed it into pyton and encountered some errors such as follows:
Code:
OSError: [Errno 2] No such file or directory: 'pitzDaily/InletVariation'
Or,
Code:
run.start()
  File "<stdin>", line 1
    run.start()
    ^
IndentationError: unexpected indent
Also, I ran its own program (doInletVariation.py) in example directory. Again, I faced some errors such as follows:
Code:
/home/myfoam/OpenFOAM/PyFoam-0.6.4/examples/doInletVariation.py: line 3: $'Example for an automatic variation of an inlet-Parameter. Runs the solver\nand after it has finished runs utilies that postprocess the output.\nCollects some results': command not found
from: can't read /var/mail/PyFoam.Execution.ConvergenceRunner
from: can't read /var/mail/PyFoam.Execution.UtilityRunner
from: can't read /var/mail/PyFoam.LogAnalysis.BoundingLogAnalyzer
from: can't read /var/mail/PyFoam.RunDictionary.SolutionFile
from: can't read /var/mail/PyFoam.RunDictionary.SolutionDirectory
/home/myfoam/OpenFOAM/PyFoam-0.6.4/examples/doInletVariation.py: line 16: syntax error near unexpected token `('
/home/myfoam/OpenFOAM/PyFoam-0.6.4/examples/doInletVariation.py: line 16: `dire=SolutionDirectory(case,archive="InletVariation")'
My version of Pyton, PyFoam and OpenFoam are 2.7.6, 0.6.4 and 2.3.1 , respectively.

Can anyone help me how to overcome these problems?!
M.Asghari
manoj_nav likes this.

Last edited by Asghari_M; July 4, 2015 at 17:09.
Asghari_M is offline   Reply With Quote

Old   July 13, 2015, 06:44
Default
  #2
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
I present the doInletVariation.py code text for all foamers as follows:
Code:
 
from PyFoam.Execution.ConvergenceRunner import ConvergenceRunner
from PyFoam.Execution.UtilityRunner import UtilityRunner
from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer
from PyFoam.RunDictionary.SolutionFile import SolutionFile
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
 
solver="simpleFoam"
case="pitzDaily"
pCmd="calcPressureDifference"
mCmd="calcMassFlow"
 
dire=SolutionDirectory(case,archive="InletVariation")
dire.clearResults()
dire.addBackup("PyFoamSolve.logfile")
dire.addBackup("PyFoamSolve.analyzed")
dire.addBackup("Pressure.analyzed")
dire.addBackup("MassFlow.analyzed")
 
sol=SolutionFile(dire.initialDir(),"U")
 
maximum=1.
nr=10
 
f=dire.makeFile("InflowVariationResults")
 
for i in range(nr+1):
    # Set the boundary condition at the inlet
    val=(maximum*i)/nr
    print "Inlet velocity:",val
    sol.replaceBoundary("inlet","(%f 0 0)" %(val))
 
    # Run the solver
    run=ConvergenceRunner(BoundingLogAnalyzer(),argv=[solver,".",case],silent=True)
    run.start()
    
    print "Last Time = ",dire.getLast()
 
    # Get the pressure difference (Using an external utility)
    pUtil=UtilityRunner(argv=[pCmd,".",case],silent=True,logname="Pressure")
    pUtil.add("deltaP","Pressure at .* Difference .*\] (.+)")
    pUtil.start()
 
    deltaP=pUtil.get("deltaP")[0]
 
    # Get the mass flow
    mUtil=UtilityRunner(argv=[mCmd,".",case,"-latestTime"],silent=True,logname="MassFlow")
    mUtil.add("mass","Flux at (.+?) .*\] (.+)",idNr=1)
    mUtil.start()
 
    massFlow=mUtil.get("mass",ID="outlet")[0]
 
    # Archive the results
    dire.lastToArchive("vel=%g" % (val))
 
    # Clear results
    dire.clearResults()
 
    # Output current stuff
    print "Vel: ",val,"DeltaP: ",deltaP,"Mass Flow:",massFlow
    f.writeLine( (val,deltaP,massFlow) )
    
sol.purgeFile()
I think errors are related to these two following lines of main pyfoam program:
solver="simpleFoam"
case="pitzDaily"
Isn't anyone to help me to find any remedy?
Welcome to any view!
Asghari_M is offline   Reply With Quote

Old   May 11, 2016, 00:10
Default
  #3
Member
 
Manoj
Join Date: Jun 2013
Posts: 38
Rep Power: 13
manoj_nav is on a distinguished road
Hi, Did you find any solution to this?

Manoj
manoj_nav is offline   Reply With Quote

Old   May 14, 2016, 14:44
Default
  #4
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Hi.
In my opinion, it is a little complex. I preferred to use bash scripting instead of it. To me,it is a little simpler.
Finally I couldn't find a definite solution by Pyfoam programming. I required it for an inverse problem.
Asghari
Asghari_M is offline   Reply With Quote

Reply

Tags
pyfoam tutorial error


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
Tutorial for subcooled nucleate boiling Asghari FLUENT 42 December 10, 2018 12:42
Problem on Fluent Tutorial: Horizontal Film Boilig Feng FLUENT 2 April 13, 2013 06:34
Needed Benchmark Problems for FSI Mechstud Main CFD Forum 4 July 26, 2011 13:13
Problems with channelOodles tutorial alberto OpenFOAM Running, Solving & CFD 0 June 5, 2007 10:08
Rotor/stator tutorial, and how to... gilberto CFX 5 January 21, 2002 10:41


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