Removed unnecessary return statement
[foam-extend-3.2.git] / bin / foamClearPolyMesh
blob4c5c8036ab06f5bef589c5975629b099272fbc5d
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration |
6 # \\ / A nd | For copyright notice see file Copyright
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend 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 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamClearPolyMesh
28 # Description
29 # Remove the contents of the constant/polyMesh directory
30 # as per the Foam::polyMesh::removeFiles() method.
32 #------------------------------------------------------------------------------
33 usage() {
34 while [ "$#" -ge 1 ]; do echo "$1" 1>&2; shift; done
35 cat <<USAGE 1>&2
37 usage: ${0##*/} [-case dir] [-region name]
39 Remove the contents of the constant/polyMesh directory
40 as per the Foam::polyMesh::removeFiles() method.
42 USAGE
43 exit 1
46 unset caseDir regionName
48 # parse a single option
49 while [ "$#" -gt 0 ]
51 case "$1" in
52 -h | -help)
53 usage
55 -case)
56 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
57 cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
58 caseDir=$2
59 shift 2
61 -region)
62 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
63 regionName=$2
64 shift 2
67 usage "unknown option/argument: '$*'"
69 esac
70 done
72 if [ -n "$regionName" ]
73 then
74 meshDir=$regionName/polyMesh
75 else
76 meshDir=polyMesh
79 # if -case was specified: insist upon 'constant/polyMesh'
80 if [ -n "$caseDir" ]
81 then
82 if [ -d constant/$meshDir ]
83 then
84 # use constant/polyMesh
85 meshDir=constant/$meshDir
86 else
87 echo "Error: no 'constant/$meshDir' in $caseDir" 1>&2
88 exit 1
90 else
91 if [ -d constant/$meshDir ]
92 then
93 # use constant/polyMesh
94 meshDir=constant/$meshDir
95 elif [ -d $meshDir ]
96 then
97 # likely already in constant/ - do not adjust anything
99 elif [ "${PWD##*/}" = polyMesh -a -z "$regionName" ]
100 then
101 # apparently already within polyMesh/
102 meshDir=.
103 else
104 echo "Error: no appropriate 'polyMesh/' directory found" 1>&2
105 exit 1
111 # remove files (mesh itself, modifiers, snappyHexMesh ones) and subdirectories
113 echo "Clearing ${caseDir:-.}/$meshDir" 1>&2
115 for i in \
116 points \
117 faces \
118 owner \
119 neighbour \
120 cells \
121 boundary \
122 pointZones \
123 faceZones \
124 cellZones \
125 meshModifiers \
126 parallelData \
127 sets \
128 cellLevel \
129 pointLevel \
130 refinementHistory \
131 surfaceIndex \
132 points.gz \
133 faces.gz \
134 owner.gz \
135 neighbour.gz \
136 cells.gz \
137 boundary.gz \
138 pointZones.gz \
139 faceZones.gz \
140 cellZones.gz \
141 meshModifiers.gz \
142 parallelData.gz \
143 sets.gz \
144 cellLevel.gz \
145 pointLevel.gz \
146 refinementHistory.gz \
147 surfaceIndex.gz \
150 rm -rf $meshDir/$i
151 done
153 #------------------------------------------------------------------------------