CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   pyFoam batch set up for OF 1.7 (http://www.cfd-online.com/Forums/openfoam-solving/83976-pyfoam-batch-set-up-1-7-a.html)

eelcovv January 17, 2011 10:05

pyFoam batch set up for OF 1.7
 
Dear all

I am trying to use pyFoam to automate my case set up for a series parameter variation. I would like to perform the following:

1: create a basecase OF director with the grid and all the settings, e.g.: run-base

2 Make a pyFoam python script which
* read the original base case with SolutionDirectory,
* loops over a serie of input parameter,
* clones the base case,
* modifies a value in on of the fields (e.g. the inlet velocity)
* runs the case for a certain time to get a steady state
* stops the case, switch on averaging in controlDict
* continue case to collect the statistics
* go to next case and do the same


The problem is that I even don't get the simplest example of PyFoam running.
I am using OF 1.7 and pyFoam 0.5.4 with python 2.6

I tried to run the example with the density variation of the dambreak
I go to the dambreak directory and now have

Code:

import sys,os,subprocess
from os import path
from PyFoam.Execution.UtilityRunner import UtilityRunner
from PyFoam.Execution.BasicRunner import BasicRunner
from PyFoam.Infrastructure.ClusterJob import SolverJob
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile

curpath=os.path.abspath('.')

#orig=SolutionDirectory(path,archive=None,paraviewLink=False)
orig=SolutionDirectory(curpath,archive=None,paraviewLink=False)

for density in [10,100]:
  print "Density: ",density
  case=orig.cloneCase("damBreakDensity%.0f" % density).name

Everything is removed, because I just want to see how it works, but already I got an error

Code:

Density:  10
Traceback (most recent call last):
  File ".//batchproc.py", line 17, in ?
    case=orig.cloneCase("damBreakDensity%.0f" % density).name
  File "/apps/OpenFOAM/local/PyFoam/lib/python2.6/site-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 240, in cloneCase
    return self.__class__(name,archive=self.archive)
  File "/apps/OpenFOAM/local/PyFoam/lib/python2.6/site-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 69, in __init__
    symlink(path.basename(self.controlDict()),self.controlDict()+".foam")
OSError: [Errno 2] No such file or directory


also I don't see exactly how this SolutionDirectory works.

Does anybody have a working example for me for OF 1.7 use with PyFoam ?

Any hints appreciated

Regards

Eelco

gschaider January 17, 2011 11:51

Quote:

Originally Posted by eelcovv (Post 290767)
Dear all

I am trying to use pyFoam to automate my case set up for a series parameter variation. I would like to perform the following:

1: create a basecase OF director with the grid and all the settings, e.g.: run-base

2 Make a pyFoam python script which
* read the original base case with SolutionDirectory,
* loops over a serie of input parameter,
* clones the base case,
* modifies a value in on of the fields (e.g. the inlet velocity)
* runs the case for a certain time to get a steady state
* stops the case, switch on averaging in controlDict
* continue case to collect the statistics
* go to next case and do the same


The problem is that I even don't get the simplest example of PyFoam running.
I am using OF 1.7 and pyFoam 0.5.4 with python 2.6

I tried to run the example with the density variation of the dambreak
I go to the dambreak directory and now have

Code:

import sys,os,subprocess
from os import path
from PyFoam.Execution.UtilityRunner import UtilityRunner
from PyFoam.Execution.BasicRunner import BasicRunner
from PyFoam.Infrastructure.ClusterJob import SolverJob
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile

curpath=os.path.abspath('.')

#orig=SolutionDirectory(path,archive=None,paraviewLink=False)
orig=SolutionDirectory(curpath,archive=None,paraviewLink=False)

for density in [10,100]:
  print "Density: ",density
  case=orig.cloneCase("damBreakDensity%.0f" % density).name

Everything is removed, because I just want to see how it works, but already I got an error

Code:

Density:  10
Traceback (most recent call last):
  File ".//batchproc.py", line 17, in ?
    case=orig.cloneCase("damBreakDensity%.0f" % density).name
  File "/apps/OpenFOAM/local/PyFoam/lib/python2.6/site-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 240, in cloneCase
    return self.__class__(name,archive=self.archive)
  File "/apps/OpenFOAM/local/PyFoam/lib/python2.6/site-packages/PyFoam/RunDictionary/SolutionDirectory.py", line 69, in __init__
    symlink(path.basename(self.controlDict()),self.controlDict()+".foam")
OSError: [Errno 2] No such file or directory

also I don't see exactly how this SolutionDirectory works.

Does anybody have a working example for me for OF 1.7 use with PyFoam ?

Any hints appreciated

Regards

Eelco

Is the current working directory an OpenFOAM-case? Because that is what your modification assumes. The concrete command that fails tries to generate a symbolic link ./system/controlDict.foam that points to ./system/controlDict (OK. That link is there for historic reasons but other stuff will fail too if this is not a valid OF-case) and there doesn't seem to be a system/controlDict -> failure (SolutionDirectory assumes that the path you give it is a valid OF-directory)

Bernhard

PS: Have you had a look at the two presentations that are available for PyFoam ("Happy foaming with Python" and "Automatization with pyFoam")

eelcovv January 18, 2011 04:43

pyfoam batching example for qsub system
 
1 Attachment(s)
Hi Bernard,

Thanks for you explanation. I have done some trail and error yesterday (also based on the documents you are referring to). I found indeed that the working directory is considered to be an OpenFOAM case. It is not really what I want, because I want a script in the project directory which reads an OpenFOAM case below it which is the base-case (with the default setting and the grid), clones it into a new one, also below the current directory. I have resolved most problems and it is working now as I want it.
For those interested in an extra pyfoam example I have added the python script as an attachment. The script clones a basecase, modifies funkySetFieldsDict based on a varying parameter, decomposes the case and runs it.
In order to run the case in a batch queing system working with qsub I make a system call with the appropriate settings to a perlscript which generates the qsub asci file with is piped to qsub. In this way each case can be submitted. I have looked at the example in the Happy Foaming manual, but I could not get this way of submitting running the OF case from the python scripts working. My approach with job.pl works as well, but is a bit less elegant.

Regards,

Eelco

gschaider January 19, 2011 09:38

Quote:

Originally Posted by eelcovv (Post 290908)
Hi Bernard,

Thanks for you explanation. I have done some trail and error yesterday (also based on the documents you are referring to). I found indeed that the working directory is considered to be an OpenFOAM case. It is not really what I want, because I want a script in the project directory which reads an OpenFOAM case below it which is the base-case (with the default setting and the grid), clones it into a new one, also below the current directory. I have resolved most problems and it is working now as I want it.
For those interested in an extra pyfoam example I have added the python script as an attachment. The script clones a basecase, modifies funkySetFieldsDict based on a varying parameter, decomposes the case and runs it.
In order to run the case in a batch queing system working with qsub I make a system call with the appropriate settings to a perlscript which generates the qsub asci file with is piped to qsub. In this way each case can be submitted. I have looked at the example in the Happy Foaming manual, but I could not get this way of submitting running the OF case from the python scripts working. My approach with job.pl works as well, but is a bit less elegant.

Your queuing system is PBS? I can't comment on that as I only tested/implemented the cluster-stuff with the SGE (http://openfoamwiki.net/index.php/Co...luster_support). Basically there are two requirements:
- the queuing manager has got to accept python as a valid interpreter for cluster-scipts
- PyFoam has to be in the PYTHONPATH

The second requirement can be worked around (if you can't/don't want to install PyFoam on the cluster). BEFORE importing any PyFoam-stuff do

import sys
sys.path.append("/path/to/the/pyfoam/installation/that/is/reachable/from/the/cluster")

and it should find the PyFoam-stuff (the SolverJob-class still won't work on other queuing systems that SGE currently, but I accept patches)

Bernhard


All times are GMT -4. The time now is 04:07.