|
[Sponsors] |
[PyFoam] run pyFoam utilities from python script |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 9, 2014, 19:41 |
run pyFoam utilities from python script
|
#1 |
Member
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17 |
Hi,
sorry for this stupid question. The pyFoam utilities are very useful! How can I run these utilities from a python script. Example: How to run a solver on a case as with pyFoamPlotRunner.py? Regards |
|
March 10, 2014, 15:23 |
|
#2 | |
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 |
||
March 10, 2014, 16:06 |
|
#3 |
Member
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17 |
Hi gschaider,
thank you for your kind reply. I've read all your presentations. I'm climbing the learning curve . I'll try what is written in the slides 43/44. Thanks for the help! bye |
|
March 10, 2014, 16:41 |
|
#4 |
Member
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17 |
In the wiki I can find:
pyFoamPlotRunner.py: Runs an OpenFoam solver. Needs the usual 3 arguments (<solver> <directory> <case>) If I run (from another directory "/anotherDir", not /mydir/) pyFoamPlotRunner.py icoFoam /mydir mycase it returns an error: "Case /anotherDir does not have a 'system' directory' in Application-class: PlotRunner Case anotherDir does not have a 'system' directory' in Application-class: PlotRunner" This is the first step to solve in order to use the utilities as classes. thank you |
|
March 10, 2014, 18:26 |
|
#5 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
That is the old (pre-1.5) calling convention. To select a case-directory nowadays the -case-option is used
__________________
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, 2014, 08:53 |
|
#6 |
Member
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17 |
If I write the case variable directly in the script it returs the error:
"... does not have a 'system' directory' in Application-class: PlotRunner Case anotherDir does not have a 'system' directory'..." How have I to modify the code in order to run the script in a different path and not in the case path? Code:
import sys case = "/mydir/caseName" proc = 1 from PyFoam . Applications . Decomposer import Decomposer from PyFoam . Applications . Runner import Runner from PyFoam . Applications . PlotRunner import PlotRunner Runner ( args =["--clear","blockMesh","-case", case ]) Runner ( args =["setFields","-case", case ]) Decomposer ( args =[ case , str ( proc ) ]) PlotRunner ( args =["--proc=%d"% proc ,"--with-all","--progress","icoFoam","-case", case ]) Runner ( args =["reconstructPar","-case", case ]) |
|
March 11, 2014, 17:32 |
|
#7 |
Member
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17 |
Hi again,
there was a space between the "-" and the "case" so it didn't work. Now it works! Thank you. |
|
March 11, 2014, 17:44 |
|
#8 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
BTW: which version of PyFoam do you use? I can't reproduce your problem (but I've got others. For instance does the decomposer complain that 1 CPU is very little)
__________________
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 26, 2022, 13:50 |
airfoil optimization with openfoam and python
|
#9 |
New Member
hossein
Join Date: May 2016
Posts: 7
Rep Power: 10 |
Hey guys,
I want to do a shape optimization for an airfoil in python and want to have open foam as my fluid solver. My question is how to link these two to get the fluid flow data in open foam as a result of shape optimization? |
|
January 27, 2022, 04:04 |
|
#10 |
Senior Member
|
A naive approach consists of the following three steps:
1/ define an Allrun bash shell script that define geometry, generate mesh, run simulation and writes quantities (pressure distribution) of interest to file; 2/ define python function that runs the Allrun script (via shell commands), reads quantities on interest to file (possibly using dataframes) and compute the quality (cost functional) of the current design (shape of airfoil);c 3/ pass above python function as argument to function that does optimization (genetic algorithm or Cobyla algorithm); A less naive (and possibly smarter approach) is to use some form of a mesh morphing technique to avoid remeshing at each iteration. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[ANSYS Meshing] how can I run .txt script file in ANSYS Meshing | oozcan | ANSYS Meshing & Geometry | 7 | December 8, 2016 12:13 |
Slicing extracted part of a volume in Python script | wilmbas | OpenFOAM Post-Processing | 4 | April 28, 2016 18:14 |
[General] How can I use python script to generate animation from 2000 frames of vtk datasets | LieyuShi | ParaView | 3 | March 10, 2016 14:37 |
Working directory via command line | Luiz | CFX | 4 | March 6, 2011 21:02 |
batch file script to run unsteady flow (les) | andi | FLUENT | 0 | April 20, 2004 04:50 |