CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Automate execution of command line

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

Reply
 
LinkBack Thread Tools Display Modes
Old   April 5, 2012, 06:42
Default Automate execution of command line
  #1
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
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
Rider is offline   Reply With Quote

Old   April 5, 2012, 07:01
Default
  #2
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 919
Rep Power: 17
akidess will become famous soon enough
Quote:
Originally Posted by Rider View Post
Moreover, I want that the second line begin when the first line is finished.
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.
*Help define the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oam-technology
akidess is offline   Reply With Quote

Old   April 5, 2012, 07:54
Default
  #3
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
Ok.

The file is a text file (.txt) ?
Rider is offline   Reply With Quote

Old   April 5, 2012, 08:05
Default
  #4
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 919
Rep Power: 17
akidess will become famous soon enough
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.
*Help define the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oam-technology
akidess is offline   Reply With Quote

Old   April 5, 2012, 08:36
Default
  #5
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
Ok, thanks.

Edit : It works

Last edited by Rider; April 6, 2012 at 05:08.
Rider is offline   Reply With Quote

Old   April 6, 2012, 05:52
Default
  #6
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
Is it possible to use the script to modify the parameters of velocity inlet in the text file ?
Rider is offline   Reply With Quote

Old   April 6, 2012, 07:34
Default
  #7
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 919
Rep Power: 17
akidess will become famous soon enough
Yes. Learn how to use sed or awk to manipulate text files.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Help define the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oam-technology
akidess is offline   Reply With Quote

Old   April 9, 2012, 18:04
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,914
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by akidess View Post
Yes. Learn how to use sed or awk to manipulate text files.
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
gschaider is offline   Reply With Quote

Old   April 10, 2012, 08:34
Default
  #9
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
What did you think about gnu m4 ? (
http://www.somogyibence.hu/documents...ckMesh_m4.html)
Rider is offline   Reply With Quote

Old   April 10, 2012, 11:16
Default
  #10
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,914
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Rider View Post
What did you think about gnu m4 ? (
http://www.somogyibence.hu/documents...ckMesh_m4.html)
Sincerely hate it since I had to configure a sendmail-server. But I'm a man of many prejudices, so don't take my word.

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
gschaider is offline   Reply With Quote

Old   April 11, 2012, 02:17
Default
  #11
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
Ok, thanks for your response.
Rider is offline   Reply With Quote

Old   April 11, 2012, 03:51
Default
  #12
Member
 
Join Date: Apr 2012
Location: France
Posts: 72
Rep Power: 5
Rider is on a distinguished road
Have you an example of BlockMesh script ? (Example of your script wrote with PyFoam)
Rider is offline   Reply With Quote

Old   April 11, 2012, 16:02
Default
  #13
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,914
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Rider View Post
Have you an example of BlockMesh script ? (Example of your script wrote with PyFoam)
Have a look at slide 42ff of http://web.student.chalmers.se/group...amAdvanced.pdf

I'm planing to add a more sophisticated templating-mechanism to later versions of PyFoam
gschaider is offline   Reply With Quote

Old   August 6, 2012, 06:55
Default
  #14
Senior Member
 
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 490
Rep Power: 9
samiam1000 is on a distinguished road
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;
The problem is that the reconstructPar starts before the foamJob -p buoyantPimpleFoam is ended.

Any idea about that?

Thanks a lot,
Samuele
samiam1000 is offline   Reply With Quote

Old   August 6, 2012, 07:05
Default
  #15
Senior Member
 
Pablo Higuera
Join Date: Jan 2011
Posts: 237
Rep Power: 7
Phicau is on a distinguished road
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.
Phicau is offline   Reply With Quote

Old   August 6, 2012, 07:48
Default
  #16
Senior Member
 
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 490
Rep Power: 9
samiam1000 is on a distinguished road
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
samiam1000 is offline   Reply With Quote

Old   August 6, 2012, 07:54
Default
  #17
Senior Member
 
Pablo Higuera
Join Date: Jan 2011
Posts: 237
Rep Power: 7
Phicau is on a distinguished road
Hi

it is very easy:

Code:
mpirun -np 8 buoyantPimpleFoam -parallel > log
where you just have to change the number of processors.

Regards
Phicau is offline   Reply With Quote

Old   August 6, 2012, 08:02
Default
  #18
Senior Member
 
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 490
Rep Power: 9
samiam1000 is on a distinguished road
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
and then
Code:
ctrl z + bg
and then
Code:
disown
.

With mpirun, this syntax doesn't work, hence I user foamJob.

What should I do, to you?

Thanks a lot,
Samuele
samiam1000 is offline   Reply With Quote

Old   August 6, 2012, 17:55
Default
  #19
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,914
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by samiam1000 View Post
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
and then
Code:
ctrl z + bg
and then
Code:
disown
.

With mpirun, this syntax doesn't work, hence I user foamJob.

What should I do, to you?

Thanks a lot,
Samuele
Use the nohup command before mpirun. This makes it ignore the "death" of the shell
gschaider is offline   Reply With Quote

Old   August 7, 2012, 07:59
Default
  #20
Senior Member
 
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 490
Rep Power: 9
samiam1000 is on a distinguished road
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;
Is that correct?

Thanks a lot,
Samuele
samiam1000 is offline   Reply With Quote

Reply

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execution termination vidhya CFX 2 April 6, 2011 07:40
Execution problems in dsmcFOAM turanc OpenFOAM Running, Solving & CFD 2 March 10, 2011 11:04
How to automate geometry, mesh and case setup using starccm+ jwillie2000 STAR-CCM+ 3 January 26, 2011 12: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 11:53


All times are GMT -4. The time now is 03:56.