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

[PyFoam] batch set up for OF 1.7

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 17, 2011, 10:05
Default batch set up for OF 1.7
  #1
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19
eelcovv is on a distinguished road
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
eelcovv is offline   Reply With Quote

Old   January 17, 2011, 11:51
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by eelcovv View Post
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")
gschaider is offline   Reply With Quote

Old   January 18, 2011, 04:43
Smile pyfoam batching example for qsub system
  #3
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19
eelcovv is on a distinguished road
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
Attached Files
File Type: gz scripts.tar.gz (2.9 KB, 37 views)
eelcovv is offline   Reply With Quote

Old   January 19, 2011, 09:38
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by eelcovv View Post
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
gschaider is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Level set method---reinitiallization and boundary conditions wenxu OpenFOAM Running, Solving & CFD 2 February 28, 2018 12:43
[mesh manipulation] mirrorMesh and undoing the joining of patches chegdan OpenFOAM Meshing & Mesh Conversion 3 October 21, 2015 09:09
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found piprus OpenFOAM Installation 22 February 25, 2010 14:43
Problems with installation of OpenFoam sheyer OpenFOAM Installation 8 July 28, 2008 04:45
Problems with installation jonititan OpenFOAM Installation 4 November 6, 2005 05:16


All times are GMT -4. The time now is 23:28.