BUG: radialActuactionDiskSource: corrected maxR calculation.
[OpenFOAM-2.0.x.git] / bin / foamJob
blob4eda40490e5dfc2307c337131a2621aee08f0eef
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamJob
28 # Description
29 # Run an OpenFOAM job in background.
30 # Redirects the output to 'log' in the case directory.
32 #------------------------------------------------------------------------------
33 usage() {
34 exec 1>&2
35 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
36 cat<<USAGE
38 Usage: ${0##*/} [OPTION] <application> ...
39 options:
40 -case <dir> specify alternative case directory, default is the cwd
41 -parallel parallel run of processors
42 -screen also sends output to screen
43 -version <ver> specify an alternative OpenFOAM version
44 -help print the usage
46 * run an OpenFOAM job in background.
47 Redirects the output to 'log' in the case directory
49 USAGE
50 exit 1
53 unset version
55 # replacement for possibly buggy 'which'
56 findExec() {
57 case "$1" in
58 */*)
59 if [ -x "$1" ]
60 then
61 echo "$1"
62 return 0
65 esac
67 oldIFS=$IFS
68 IFS=':'
69 for d in $PATH
71 # echo "testing: $d/$1" 1>&2
72 if [ -x "$d/$1" -a ! -d "$d/$1" ]
73 then
74 # echo "Found exec: $d/$1" 1>&2
75 IFS=$oldIFS
76 echo "$d/$1"
77 return 0
79 done
80 IFS=$oldIFS
81 echo ""
82 return 1
87 # MAIN SCRIPT
88 #~~~~~~~~~~~~
89 unset parallelOpt screenOpt
92 # parse options
93 while [ "$#" -gt 0 ]
95 case "$1" in
96 -h | -help)
97 usage
99 -case)
100 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
101 cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
102 shift 2
104 -p | -parallel)
105 parallelOpt=true
106 shift
108 -s | -screen)
109 screenOpt=true
110 shift
112 -v | -version)
113 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
114 version="$2"
115 shift 2
118 shift
119 break
122 usage "invalid option '$1'"
125 break
127 esac
128 done
130 [ "$#" -ge 1 ] || usage "No application specified"
133 # use foamExec for a specified version
134 # also need foamExec for remote (parallel) runs
135 if [ -n "$version" -o "$parallelOpt" = true ]
136 then
137 # when possible, determine if application even exists
138 if [ -z "$version" ]
139 then
140 findExec $1 >/dev/null || usage "Application '$1' not found"
143 # use foamExec for dispatching
144 APPLICATION=`findExec foamExec` || usage "'foamExec' not found"
146 [ -n "$version" ] && APPLICATION="$APPLICATION -version $version"
148 # attempt to preserve the installation directory 'FOAM_INST_DIR'
149 if [ -d "$FOAM_INST_DIR" ]
150 then
151 APPLICATION="$APPLICATION -prefix $FOAM_INST_DIR"
154 else
155 APPLICATION=`findExec $1` || usage "Application '$1' not found"
156 echo "Application : $1"
157 shift
161 if [ "$parallelOpt" = true ]
162 then
163 # parallel
164 # ~~~~~~~~
167 # is the case decomposed?
169 if [ -r "processor0" ]
170 then
171 NPROCS="`/bin/ls -1d processor* | wc -l`"
172 else
173 echo "Case is not currently decomposed"
174 if [ -r system/decomposeParDict ]
175 then
176 echo "system/decomposeParDict exists"
177 echo "Try decomposing with \"foamJob decomposePar\""
178 exit 1
179 else
180 echo "Cannot find system/decomposeParDict file required to decompose the case for parallel running."
181 echo "Please consult the User Guide for details of parallel running"
182 exit 1
187 # locate mpirun
189 mpirun=`findExec mpirun` || usage "'mpirun' not found"
190 mpiopts="-np $NPROCS"
193 # is the machine ready to run parallel?
195 echo "Parallel processing using $WM_MPLIB with $NPROCS processors"
196 case "$WM_MPLIB" in
197 *OPENMPI)
198 # add hostfile info
199 for hostfile in \
200 hostfile \
201 machines \
202 system/hostfile \
203 system/machines \
206 if [ -r $hostfile ]
207 then
208 mpiopts="$mpiopts -hostfile $hostfile"
209 break
211 done
213 esac
216 # run (in parallel)
218 if [ "$screenOpt" = true ]
219 then
220 echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
221 $mpirun $mpiopts $APPLICATION $@ -parallel | tee log
222 else
223 echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
224 $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1 &
227 else
229 # run (on single processor)
231 if [ "$screenOpt" = true ]
232 then
233 echo "Executing: $APPLICATION $@ | tee log &"
234 $APPLICATION $@ | tee log &
235 wait $!
236 else
237 echo "Executing: $APPLICATION $@ > log 2>&1 &"
238 $APPLICATION $@ > log 2>&1 &
242 #------------------------------------------------------------------------------