Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / bin / paraFoam
blob48eab6ebe0551f01d61893ff29e9998fc19e33c1
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2004-2011 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
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 # paraFoam
28 # Description
29 # start paraview with the OpenFOAM libraries
31 # Note
32 # combining -block or -builtin options with the -region option yields
33 # undefined behaviour
34 #------------------------------------------------------------------------------
35 usage() {
36 exec 1>&2
37 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
38 cat<<USAGE
40 Usage: ${0##*/} [OPTION] [PARAVIEW_OPTION]
41 options:
42 -block use blockMesh reader (uses .blockMesh extension)
43 -builtin use VTK builtin OpenFOAM reader (uses .foam extension)
44 -case <dir> specify alternative case directory, default is the cwd
45 -region <name> specify alternative mesh region
46 -touch only create the file (eg, .blockMesh, .OpenFOAM, etc)
47 -touchAll create .blockMesh, .OpenFOAM files (and for all regions)
48 -help print the usage
51 paraview options start with a double dashes
53 * start paraview $ParaView_VERSION with the OpenFOAM libraries
55 USAGE
56 exit 1
59 # We want to do nice exit when running paraview to give paraview opportunity
60 # to clean up
61 unset FOAM_ABORT
63 unset regionName optTouch
65 # reader extension
66 extension=OpenFOAM
68 # parse options
69 while [ "$#" -gt 0 ]
71 case "$1" in
72 -h | -help)
73 usage
75 -block | -blockMesh)
76 extension=blockMesh
77 shift
79 -builtin)
80 extension=foam
81 shift
83 -case)
84 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
85 cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
86 shift 2
88 -region)
89 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
90 regionName=$2
91 shift 2
93 -touch)
94 optTouch=true
95 shift
97 -touchAll)
98 optTouch=all
99 shift
102 shift
103 break # stop here, treat balance as paraview options
105 --*)
106 break # stop here, treat this and balance as paraview options
109 usage "unknown option/argument: '$*'"
111 esac
112 done
116 # check for --data=... argument
118 hasDataArg()
120 hasData=false
121 while [ "$#" -gt 0 ]
123 case "$1" in
124 (--data=*)
125 hasData=true
126 break
128 esac
129 shift
130 done
133 hasDataArg $@
136 # get a sensible caseName from the directory name
137 caseName=${PWD##*/}
138 caseFile="$caseName.$extension"
139 fvControls="system"
141 if [ -n "$regionName" ]
142 then
143 caseFile="$caseName{$regionName}.$extension"
144 fvControls="$fvControls/$regionName"
147 case "${optTouch:-false}" in
148 all)
149 extension=OpenFOAM
150 if [ -f constant/polyMesh/blockMeshDict ]
151 then
152 touch "$caseName.blockMesh"
153 echo "created '$caseName.blockMesh'"
155 touch "$caseName.$extension"
156 echo "created '$caseName.$extension'"
157 # discover probable regions
158 for region in constant/*
160 if [ -d $region -a -d $region/polyMesh ]
161 then
162 regionName=${region##*/}
163 touch "$caseName{$regionName}.$extension"
164 echo "created '$caseName{$regionName}.$extension'"
166 done
167 exit 0
169 true)
170 touch "$caseFile"
171 echo "created '$caseFile'"
172 exit 0
174 esac
177 # parent directory for normal or parallel results
178 case "$caseName" in
179 processor*) parentDir=".." ;;
180 *) parentDir="." ;;
181 esac
184 if [ "${hasData:-false}" = true ]
185 then
187 # has --data=.., send directly to paraview
188 exec paraview "$@"
190 else
192 # check existence of essential files
193 warn="WARN file does not exist:"
194 case $extension in
195 blockMesh)
196 for check in \
197 system/controlDict \
198 constant/polyMesh/blockMeshDict \
201 [ -s "$parentDir/$check" ] || {
202 [ -n "$warn" ] && echo "$warn" 1>&2
203 echo " $parentDir/$check" 1>&2
204 unset warn
206 done
209 builtin | OpenFOAM)
210 for check in \
211 system/controlDict \
212 $fvControls/fvSchemes \
213 $fvControls/fvSolution \
216 [ -s "$parentDir/$check" ] || {
217 [ -n "$warn" ] && echo "$warn" 1>&2
218 echo " $parentDir/$check" 1>&2
219 unset warn
221 done
223 esac
225 # only create/remove caseFile if it didn't already exist
226 [ -e $caseFile ] || {
227 trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT
228 touch "$caseFile"
229 echo "created temporary '$caseFile'"
232 # For now filter out any ld.so errors. Caused by non-system compiler?
233 paraview --data="$caseFile" "$@" 2>&1 | fgrep -v 'Inconsistency detected by ld.so'
237 #------------------------------------------------------------------------------