|
[Sponsors] |
April 5, 2012, 06:42 |
Automate execution of command line
|
#1 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
Hi,
I would like to automate execution of command line with a script (On Ubuntu). Moreover, I want that the second line begin when the first line is finished. For exemple : * cd User/Cas1 * blockMesh * snappyHexMesh * sudo cp Cas1/0 Cas1/3 // copy of the boundary conditions * decomposePar * foamJob -parallel -screen simpleFoam * reconstructPar * cd User/Cas2 * blockMesh * snappyHexMesh * sudo cp Cas1/0 Cas1/3 // copy of the boundary conditions * decomposePar * foamJob -parallel -screen simpleFoam * reconstructPar * cd User/Cas2 * etc ... Thanks all for your help |
|
April 5, 2012, 07:01 |
|
#2 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
That's the default behaviour. Just put all the commands from above in a file that starts with the line "#!/bin/bash", and then run "chmod +x [scriptname]" to make the file executable. That's it.
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
April 5, 2012, 07:54 |
|
#3 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
Ok.
The file is a text file (.txt) ? |
|
April 5, 2012, 08:05 |
|
#4 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
The file is plain text, but the extension is not important. I usually end them in .sh, but if you prefer you can use .txt, or no extension at all.
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
April 5, 2012, 08:36 |
|
#5 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
Ok, thanks.
Edit : It works Last edited by Rider; April 6, 2012 at 05:08. |
|
April 6, 2012, 05:52 |
|
#6 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
Is it possible to use the script to modify the parameters of velocity inlet in the text file ?
|
|
April 9, 2012, 18:04 |
|
#8 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
That is a possibilty. Although these straight replacements always have to make an assumption about what they have to replace ("look for value 42 and replace it with the inlet velocity"). I personally find a solution similar to http://openfoamwiki.net/index.php/Co...ions_for_walls much easier to maintain (but of course I'm not objective)
But of course sed has the advantage to be installed everywhere |
|
April 10, 2012, 08:34 |
|
#9 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
What did you think about gnu m4 ? (
http://www.somogyibence.hu/documents...ckMesh_m4.html) |
|
April 10, 2012, 11:16 |
|
#10 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Seriously: I think the main purpose of M4 is generating text files, not analyzing them. So it might be just the opposite of what you're looking for |
||
April 11, 2012, 02:17 |
|
#11 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
Ok, thanks for your response.
|
|
April 11, 2012, 03:51 |
|
#12 |
Member
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 14 |
Have you an example of BlockMesh script ? (Example of your script wrote with PyFoam)
|
|
April 11, 2012, 16:02 |
|
#13 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
I'm planing to add a more sophisticated templating-mechanism to later versions of PyFoam |
||
August 6, 2012, 06:55 |
|
#14 |
Senior Member
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 18 |
Dear All,
pardon the question, but I think that this does not work. In fact I have my launch.sh file which is the following: Code:
'#!/bin/bash' foamJob -p buoyantPimpleFoam; reconstructPar; cd ../1DegNew/; mapFields -consistent ../1DegStartNew -sourceTime 100; decomposePar; buoyantPimpleDyMFoam_MS; sed -i 's/1/2/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/2/3/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/3/4/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/4/5/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/5/6/' system/controlDict; Any idea about that? Thanks a lot, Samuele |
|
August 6, 2012, 07:05 |
|
#15 |
Senior Member
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19 |
Hi
foamJob sends the solving process to the background and redirects its output to a log file, hence your following commands get to start as soon as the case starts. |
|
August 6, 2012, 07:48 |
|
#16 |
Senior Member
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 18 |
Dear Pablo,
thanks for answering. I know that it is as you say, i.e. that foamJob solves in BG.. What I would like to know is if it is possible to launch all the commands that I give in BG on a server, executing them one after the other. Thanks a lot, Samuele |
|
August 6, 2012, 07:54 |
|
#17 |
Senior Member
Pablo Higuera
Join Date: Jan 2011
Location: Auckland
Posts: 627
Rep Power: 19 |
Hi
it is very easy: Code:
mpirun -np 8 buoyantPimpleFoam -parallel > log Regards |
|
August 6, 2012, 08:02 |
|
#18 |
Senior Member
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 18 |
If I give the command you suggested (i.e. mpirun -np 8 buoyantPimpleFoam -parallel > log), I'll launch the program in foreground and when I close the terminal where I am running it, the execution stops.
Let me try to explain what I wanna do: maybe you can help me. I am performing some simulations on a server. I connect via ssh, from my laptop. The point is that if I am working in serial, I can give Code:
buoyantPimpleFoam > log Code:
ctrl z + bg Code:
disown With mpirun, this syntax doesn't work, hence I user foamJob. What should I do, to you? Thanks a lot, Samuele |
|
August 6, 2012, 17:55 |
|
#19 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
|
||
August 7, 2012, 07:59 |
|
#20 |
Senior Member
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 18 |
If I understood well, I can write a launch.sh file like this:
Code:
'#!/bin/bash' nohup foamJob -p buoyantPimpleFoam; reconstructPar; cd ../1DegNew/; mapFields -consistent ../1DegStartNew -sourceTime 100; decomposePar; buoyantPimpleDyMFoam_MS; sed -i 's/1/2/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/2/3/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/3/4/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/4/5/' system/controlDict; buoyantPimpleDyMFoam_MS; sed -i 's/5/6/' system/controlDict; Thanks a lot, Samuele |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Execution problems in dsmcFOAM | turanc | OpenFOAM Running, Solving & CFD | 3 | April 10, 2017 12:58 |
Execution termination | vidhya | CFX | 2 | April 6, 2011 07:40 |
How to automate geometry, mesh and case setup using starccm+ | jwillie2000 | STAR-CCM+ | 3 | January 26, 2011 11:13 |
Measuring an Execution Time - f90 | su | Main CFD Forum | 11 | July 4, 2008 07:21 |
Background execution on UNIX systems | law | FLUENT | 1 | January 3, 2006 10:53 |