intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / bin / foamJob
blob1aad5fca99d81c5d51ab5fa0ef7df55cbf0b8e0f
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 # Script
27 # foamJob
29 # Description
31 #------------------------------------------------------------------------------
32 usage() {
33 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
34 cat<<USAGE
36 usage: ${0##*/} [OPTION] <application> ...
38 options:
39 -case dir specify case directory
40 -s also sends output to screen
41 -p parallel run of processors
42 -v ver specify OpenFOAM version
43 -help this usage
45 * run an OpenFOAM job in background.
46 Redirects the output to 'log' in the case directory
48 USAGE
49 exit 1
52 unset version
54 # replacement for possibly buggy 'which'
55 findExec() {
56 case "$1" in
57 */*)
58 if [ -x "$1" ] ; then
59 echo "$1"
60 return 0
63 esac
65 oldIFS=$IFS
66 IFS=':'
67 for d in $PATH
69 # echo "testing: $d/$1" 1>&2
70 if [ -x "$d/$1" -a ! -d "$d/$1" ] ; then
71 # echo "Found exec: $d/$1" 1>&2
72 IFS=$oldIFS
73 echo "$d/$1"
74 return 0
76 done
77 IFS=$oldIFS
78 echo ""
79 return 1
82 # grep for $1
83 getPID() {
84 ps -u $LOGNAME -o 'pid,args' | fgrep "$1 " | fgrep -v grep | head -1 | awk '{ print $1 }'
88 consultGuide() {
89 cat<<EOF
91 Please consult the User Guide for details of parallel running
92 EOF
95 # MAIN SCRIPT
96 #~~~~~~~~~~~~
97 SCREEN=no
98 PARALLEL=no
101 # parse options
102 while [ "$#" -gt 0 ]
104 case "$1" in
105 -h | -help)
106 usage
108 -case)
109 [ "$#" -ge 2 ] || usage "'-case' option requires an argument"
110 caseDir=$2
111 shift 2
112 cd "$caseDir" 2>/dev/null || usage "directory does not exist: '$caseDir'"
115 SCREEN=yes
116 shift
119 PARALLEL=yes
120 shift
123 shift
124 version=$1
125 shift
128 shift
129 break
132 usage "invalid option '$1'"
135 break
137 esac
138 done
140 if [ "$#" -lt 1 ]; then
141 usage "No application specified"
144 # use foamExec for a specified version and for remote (parallel) runs
145 if [ -n "$version" -o "$PARALLEL" = yes ]; then
146 APPLICATION=`findExec foamExec`
147 if [ $? -ne 0 ]; then
148 usage "'foamExec' not found"
150 if [ -n "$version" ]; then
151 APPLICATION="$APPLICATION -v $version"
153 else
154 APPLICATION=`findExec $1`
155 if [ $? -ne 0 ]; then
156 usage "Application '$1' executable not found"
158 echo "Application : $1"
159 shift
162 if [ "$PARALLEL" = no ]; then
164 # RUN ON SINGLE PROCESSOR
166 if [ "$SCREEN" = no ]; then
167 echo "Executing: $APPLICATION $@ > log 2>&1 &"
168 $APPLICATION $@ > log 2>&1 &
169 else
170 echo "Executing: $APPLICATION $@ | tee log &"
171 $APPLICATION $@ | tee log &
172 wait $!
174 else
177 # IS THE CASE DECOMPOSED?
179 if [ -r "processor0" ] ; then
180 NPROCS="`/bin/ls -1d processor* | wc -l`"
181 else
182 echo "Case is not currently decomposed"
183 if [ -r system/decomposeParDict ] ; then
184 echo "system/decomposeParDict exists"
185 echo "Try decomposing with \"foamJob decomposePar\""
186 exit 1
187 else
188 echo "Cannot find system/decomposeParDict file required to decompose the case for parallel running."
189 consultGuide
190 exit 1
194 # LOCATE MPIRUN
196 mpirun=`findExec mpirun`
197 if [ $? -ne 0 ]; then
198 usage "'mpirun' not found"
200 mpiopts="-np $NPROCS"
203 # IS THE MACHINE READY TO RUN PARALLEL?
205 echo "Parallel processing using $WM_MPLIB with $NPROCS processors"
206 case "$WM_MPLIB" in
207 LAM)
208 lamPid=`getPID lamd`
209 if [ ! "$lamPid" ] ; then
210 echo "No LAM daemon running."
211 if [ -r system/machines ] ; then
212 echo "system/machines file exists"
213 echo "Try starting the LAM multicomputer with \"lamboot -v system/machines\""
214 exit 1
215 else
216 echo "Cannot find a 'machines' file for LAM in system/"
217 echo "required to start a LAM multicomputer"
218 consultGuide
219 exit 1
221 else
222 echo "LAM daemon running (PID $lamPid). Proceeding with MPI run."
225 OPENMPI)
226 # add hostfile info
227 for hostfile in \
228 hostfile \
229 machines \
230 system/hostfile \
231 system/machines \
234 if [ -r $hostfile ]; then
235 mpiopts="$mpiopts -hostfile $hostfile"
236 break
238 done
240 esac
243 # RUN IN PARALLEL
245 if [ "$SCREEN" = no ] ; then
246 echo "Executing: mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
247 $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1 &
248 else
249 echo "Executing: mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
250 $mpirun $mpiopts $APPLICATION $@ -parallel | tee log
254 #------------------------------------------------------------------------------