Lines 1-133
Link Here
|
1 |
#!/bin/sh |
1 |
#!/bin/sh |
2 |
#------------------------------------------------------------------------------ |
2 |
# |
3 |
# ========= | |
3 |
# Copyright (c) 2008-2009 Takuya OSHIMA <oshima@eng.niigata-u.ac.jp>. |
4 |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4 |
# All rights reserved. |
5 |
# \\ / O peration | |
5 |
# |
6 |
# \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. |
6 |
# Redistribution and use in source and binary forms, with or without |
7 |
# \\/ M anipulation | |
7 |
# modification, are permitted provided that the following conditions are |
8 |
#------------------------------------------------------------------------------- |
8 |
# met: |
9 |
# License |
9 |
# |
10 |
# This file is part of OpenFOAM. |
10 |
# * Redistributions of source code must retain the above copyright |
11 |
# |
11 |
# notice, this list of conditions and the following disclaimer. |
12 |
# OpenFOAM is free software; you can redistribute it and/or modify it |
12 |
# |
13 |
# under the terms of the GNU General Public License as published by the |
13 |
# * Redistributions in binary form must reproduce the above copyright |
14 |
# Free Software Foundation; either version 2 of the License, or (at your |
14 |
# notice, this list of conditions and the following disclaimer in the |
15 |
# option) any later version. |
15 |
# documentation and/or other materials provided with the |
16 |
# |
16 |
# distribution. |
17 |
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT |
17 |
# |
18 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
18 |
# * Neither the name of the author nor the names of any contributors |
19 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
19 |
# may be used to endorse or promote products derived from this |
20 |
# for more details. |
20 |
# software without specific prior written permission. |
21 |
# |
21 |
# |
22 |
# You should have received a copy of the GNU General Public License |
22 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
23 |
# along with OpenFOAM; if not, write to the Free Software Foundation, |
23 |
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
24 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
24 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
25 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR |
26 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
27 |
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
28 |
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
29 |
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
30 |
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
31 |
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
32 |
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 |
# |
33 |
# |
26 |
# Script |
34 |
# Script |
27 |
# paraFoam |
35 |
# pvFoam |
28 |
# |
36 |
# |
29 |
# Description |
37 |
# Description |
30 |
# start paraview with the OpenFOAM libraries |
38 |
# ParaView interface script for use with vtkPOpenFOAMReader. |
31 |
# |
|
|
32 |
#------------------------------------------------------------------------------ |
33 |
usage() { |
34 |
while [ "$#" -ge 1 ]; do echo "$1"; shift; done |
35 |
cat<<USAGE |
36 |
|
37 |
usage: ${0##*/} [OPTION] |
38 |
options: |
39 |
-case dir specify alternative case directory |
40 |
-region name specify mesh region name |
41 |
-touch only create the .OpenFOAM file |
42 |
|
43 |
* start paraview $ParaView_VERSION with the OpenFOAM libraries |
44 |
|
39 |
|
45 |
USAGE |
40 |
# Adjust as necessary. |
|
|
41 |
# You might also want to set LD_LIBRARY_PATH or DYLD_LIBRARY_PATH. |
42 |
paraviewPath="`which paraview`" |
43 |
# or in full path like paraviewPath=/opt/ParaView3/bin/paraview |
44 |
|
45 |
if [ ! -x "${paraviewPath}" -o -d "${paraviewPath}" ]; then |
46 |
# not using LINENO which is not supported by dash (yet) |
47 |
echo "ParaView not found; set paraviewPath at line" `awk '/paraviewPath/{print FNR;exit 0}' $0` "of $0." |
46 |
exit 1 |
48 |
exit 1 |
47 |
} |
49 |
fi |
48 |
|
50 |
|
49 |
unset regionName touchOnly |
51 |
ext=foam |
|
|
52 |
casePath=. |
53 |
script=${0##*/} |
54 |
background=yes |
55 |
trapCommand=trap |
50 |
|
56 |
|
51 |
# parse options |
57 |
while [ $# -gt 0 ] |
52 |
while [ "$#" -gt 0 ] |
|
|
53 |
do |
58 |
do |
54 |
case "$1" in |
59 |
case "$1" in |
55 |
-h | -help) |
60 |
-case) |
56 |
usage |
61 |
if [ $# -lt 2 ]; then |
57 |
;; |
62 |
echo "-case requires path specification" |
58 |
-case) |
63 |
exit 1 |
59 |
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" |
64 |
fi |
60 |
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'" |
65 |
shift |
61 |
shift 2 |
66 |
casePath="$1" |
62 |
;; |
67 |
;; |
63 |
-region) |
68 |
-clientServer|-cs) |
64 |
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" |
69 |
if [ $# -lt 2 ]; then |
65 |
regionName=$2 |
70 |
echo "-clientServer or -cs requires specification of the server resource name" |
66 |
shift 2 |
71 |
exit 1 |
67 |
;; |
72 |
fi |
68 |
-touch) |
73 |
shift |
69 |
touchOnly=true |
74 |
csResourceName="$1" |
70 |
shift |
75 |
;; |
71 |
;; |
76 |
-foreground|-fg) |
72 |
*) |
77 |
background=no |
73 |
usage "unknown option/argument: '$*'" |
78 |
;; |
74 |
;; |
79 |
-keepStub|-ks) |
|
|
80 |
trapCommand=: |
81 |
;; |
82 |
-help) |
83 |
echo "Usage: ${script} [-case <dir>] [-clientServer|-cs <server resource name>] [-foreground|-fg] [-keepStub|-ks] [-help]" |
84 |
exit 0 |
85 |
;; |
75 |
esac |
86 |
esac |
|
|
87 |
shift |
76 |
done |
88 |
done |
77 |
|
89 |
|
78 |
# get a sensible caseName |
90 |
# cd to the case directory |
79 |
caseName=${PWD##*/} |
91 |
if ! cd "${casePath}" > /dev/null 2>&1; then |
80 |
caseFile="$caseName.OpenFOAM" |
92 |
echo "Cannot change directory to \"${casePath}\"; exiting" |
81 |
fvControls="system" |
93 |
exit 1 |
82 |
|
|
|
83 |
if [ -n "$regionName" ] |
84 |
then |
85 |
caseFile="$caseName{$regionName}.OpenFOAM" |
86 |
fvControls="$fvControls/$regionName" |
87 |
fi |
88 |
|
89 |
if [ -n "$touchOnly" ] |
90 |
then |
91 |
touch "$caseFile" |
92 |
echo "created '$caseFile'" |
93 |
exit 0 |
94 |
fi |
94 |
fi |
95 |
|
95 |
|
96 |
# parent directory for normal or parallel results |
96 |
caseName="${PWD##*/}" |
97 |
case "$caseName" in |
|
|
98 |
processor*) parentDir=".." ;; |
99 |
*) parentDir="." ;; |
100 |
esac |
101 |
|
102 |
# check existence of essential files |
103 |
for check in system/controlDict $fvControls/fvSchemes $fvControls/fvSolution |
104 |
do |
105 |
[ -s "$parentDir/$check" ] || usage "file does not exist: '$parentDir/$check'" |
106 |
done |
107 |
|
97 |
|
|
|
98 |
# see if caseName starts with controlDict or the case is in the root directory. |
99 |
if [ "${caseName#controlDict}" != "${caseName}" -o ! "${caseName}" ]; then |
100 |
# Use case.foam as file name given to ParaView |
101 |
caseName="case" |
102 |
fi |
108 |
|
103 |
|
109 |
case "$ParaView_VERSION" in |
104 |
fileName="${caseName}.${ext}" |
110 |
2*) |
105 |
if [ -e "${fileName}" ]; then |
111 |
trap "rm -f paraFoam.pvs $caseFile 2>/dev/null; exit 0" EXIT TERM INT |
106 |
if [ ! -r "${fileName}" ]; then |
112 |
touch "$caseFile" |
107 |
echo "Stub ${fileName} exists but not readable; exiting" |
113 |
|
108 |
exit 1 |
114 |
# since we are now in the cwd, %CASE% is '$PWD/$caseFile' |
109 |
fi |
115 |
sed -e s@%CASE%@$PWD/$caseFile@g \ |
110 |
trapCommand=: |
116 |
$WM_PROJECT_DIR/bin/tools/paraFoam.pvs > paraFoam.pvs |
111 |
else |
117 |
|
112 |
if ! touch "${fileName}" > /dev/null 2>&1; then |
118 |
paraview paraFoam.pvs |
113 |
echo "Cannot create stub ${fileName}; exiting" |
119 |
;; |
114 |
exit 1 |
120 |
|
115 |
fi |
121 |
*) |
116 |
fi |
122 |
# only create/remove caseFile if it didn't already exist |
|
|
123 |
[ -e $caseFile ] || { |
124 |
trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT |
125 |
touch "$caseFile" |
126 |
echo "created temporary '$caseFile'" |
127 |
} |
128 |
|
117 |
|
129 |
paraview --data="$caseFile" |
118 |
# set the locale where ParaView is run under to "C" so that the |
130 |
;; |
119 |
# interpretation of decimal points by the system routines are not |
|
|
120 |
# affected |
121 |
export LANG=C |
122 |
export LC_ALL=C |
123 |
|
124 |
# specify fileName with full path so that it can easily be accessed |
125 |
# later with File->Recent Files |
126 |
if [ "${background}" = "yes" ]; then |
127 |
( |
128 |
${trapCommand} "rm -f \"${fileName}\" ; exit 0" \ |
129 |
EXIT HUP INT PIPE ALRM TERM USR1 USR2 ; |
130 |
if [ "${csResourceName}" ]; then |
131 |
"${paraviewPath}" --data="${PWD}/${fileName}" \ |
132 |
--server="${csResourceName}" |
133 |
else |
134 |
"${paraviewPath}" --data="${PWD}/${fileName}" |
135 |
fi |
136 |
) & |
137 |
else |
138 |
${trapCommand} "rm -f \"${fileName}\" ; exit 0" \ |
139 |
EXIT HUP INT PIPE ALRM TERM USR1 USR2 |
140 |
if [ "${csResourceName}" ]; then |
141 |
"${paraviewPath}" --data="${PWD}/${fileName}" \ |
142 |
--server="${csResourceName}" |
143 |
else |
144 |
"${paraviewPath}" --data="${PWD}/${fileName}" |
145 |
fi |
146 |
fi |
131 |
|
147 |
|
132 |
esac |
|
|
133 |
#------------------------------------------------------------------------------ |
148 |
#------------------------------------------------------------------------------ |