CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Run case from a script?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By fumiya

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 6, 2013, 13:42
Default Run case from a script?
  #1
Member
 
Miro
Join Date: Jan 2013
Location: Europe
Posts: 51
Rep Power: 13
miro2000 is on a distinguished road
Hello everyone, sorry if it's the wrong place for this question.

I would like to create a script that will run my case after i set the dictionaries.
This is similar to Allrun script in tutorials, and i was looking through those but i don't quite understand them.
I tried to modify allRun from one of the tutorials (motorBike) but that is way off.

I guess this maybe is more of a Linux question, but i don't know where else to ask. Thank you for your help. I'm running Ubuntu 12.04.

-miro
miro2000 is offline   Reply With Quote

Old   July 7, 2013, 02:58
Default
  #2
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 19
fumiya is on a distinguished road
Hi,

Please upload your script file and provide more information about the problems
you have encountered.

Fumiya
fumiya is offline   Reply With Quote

Old   July 7, 2013, 03:32
Default
  #3
Member
 
Miro
Join Date: Jan 2013
Location: Europe
Posts: 51
Rep Power: 13
miro2000 is on a distinguished road
Thanks for help!

The c/p of Allrun script from motorbike tutorial:
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

# copy motorbike surface from resources folder
cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gz constant/triSurface/

runApplication surfaceFeatureExtract

runApplication blockMesh

#runApplication decomposePar
runParallel snappyHexMesh 3 -overwrite

#- For non-parallel running
#cp -r 0.org 0 > /dev/null 2>&1

- For parallel running
ls -d processor* | xargs -i rm -rf ./{}/0 $1
ls -d processor* | xargs -i cp -r 0.org ./{}/0 $1

runParallel patchSummary 6
runParallel potentialFoam 6 -noFunctionObjects -writep
runParallel $(getApplication) 6

runApplication reconstructParMesh -constant
runApplication reconstructPar -latestTime

# ----------------------------------------------------------------- end-of-file
What do first two commands do?
What do ls -d processor* | xargs..... do?

What i want to do :
source //opt/openfoam220/etc/bashrc
blockMesh
decomposePar
surfaceFeatureExtract
foamJob -parallel -screen snappyHexMesh
reconstructParMesh -latestTime -mergeTol 1E-06 -noZero
and later run calculation, but you can see what I mean.

What i have for now:
#!/bin/sh

cd ${0%/*} || exit 1 # run from this directory

runApplication source //opt/openfoam220/etc/bashrc
I run it as a shell script: sh run.sh
and the error:
run.sh: 3: cd: can't cd to run.sh

If i run it without runApplication i get something like "command now found".

Thanks again
miro2000 is offline   Reply With Quote

Old   July 7, 2013, 04:46
Default
  #4
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 19
fumiya is on a distinguished road
  1. #!/bin/sh
    You might want to read this page:
    http://en.wikipedia.org/wiki/Shebang_(Unix)
  2. cd ${0%/*} || exit 1 # run from this directory
    If you execute this script with the command like
    $ sh dir1/dir2/dir3/run.sh
    ${0%/*} means dir1/dir2/dir3 and this line is to move to the directory where the script is.
    If this directory doesn't exist, the script is terminated.

Your error is related to item 2. To avoid the error, go to the case directory
and put your script there and run your script(./run.sh).

Hope this helps,
Fumiya
miro2000 and Danubi like this.
fumiya is offline   Reply With Quote

Old   July 7, 2013, 06:52
Default
  #5
Member
 
Miro
Join Date: Jan 2013
Location: Europe
Posts: 51
Rep Power: 13
miro2000 is on a distinguished road
ok, thank you for your answer.

i have removed everything but:
#!/bin/sh

blockMesh
decomposePar
surfaceFeatureExtract
foamJob -parallel -screen snappyHexMesh
reconstructParMesh -latestTime -mergeTol 1E-06 -noZero
And now it works.

i placed source in ~/.bashrc and now i don't have to enter in manually. However, I have a few more questions:

1. What exactly does bashrc do?
2. I think I will install another version of OF so this will not work.
if i add:source //opt/openfoam220/etc/bashrc to the script
without adding it (source) to ~/.bashrc then it doesn't work and I don't understand why. Isn't it the same as entering it in the terminal?

Thanks for your effort,
-Miro

PS: when i enter source in the script it gives an error that says something like: not found
miro2000 is offline   Reply With Quote

Reply


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
Case running in serial, but Parallel run gives error atmcfd OpenFOAM Running, Solving & CFD 18 March 26, 2016 13:40
Can't run a case in HelyxOS with an imported mesh from Fluent HHOS OpenFOAM Running, Solving & CFD 0 July 2, 2013 07:25
Discretizer: How to run a case in parallel? klausb OpenFOAM 2 January 23, 2011 15:12
Perl script for intialisation pratik mehta CFX 2 September 10, 2008 04:09
Run in parallel a 2mesh case cosimobianchini OpenFOAM Running, Solving & CFD 2 January 11, 2007 07:33


All times are GMT -4. The time now is 17:37.