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] tutorial problems (https://www.cfd-online.com/Forums/openfoam-community-contributions/155267-tutorial-problems.html)

Asghari_M June 28, 2015 03:49

tutorial problems
 
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

Asghari_M July 13, 2015 05:44

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!

manoj_nav May 10, 2016 23:10

Hi, Did you find any solution to this?

Manoj

Asghari_M May 14, 2016 13:44

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


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