ENH: polyBoundaryMesh: improved error message
[OpenFOAM-2.0.x.git] / bin / foamClearPolyMesh
blob7e5ee1fe16b8ac66c7435214b4ed931e866c5334
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 # foamClearPolyMesh
28 # Description
29 # Remove the contents of the constant/polyMesh directory
30 # as per the Foam::polyMesh::removeFiles() method.
32 #------------------------------------------------------------------------------
33 usage() {
34 exec 1>&2
35 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
36 cat <<USAGE
38 Usage: ${0##*/} [OPTION]
39 options:
40 -case <dir> specify alternative case directory, default is the cwd
41 -region <name> specify alternative mesh region
42 -help print the usage
44 Remove the contents of the constant/polyMesh directory as per the
45 Foam::polyMesh::removeFiles() method.
47 USAGE
48 exit 1
51 unset caseDir regionName
53 # parse a single option
54 while [ "$#" -gt 0 ]
56 case "$1" in
57 -h | -help)
58 usage
60 -case)
61 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
62 cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
63 caseDir=$2
64 shift 2
66 -region)
67 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
68 regionName=$2
69 shift 2
72 usage "unknown option/argument: '$*'"
74 esac
75 done
77 if [ -n "$regionName" ]
78 then
79 meshDir=$regionName/polyMesh
80 else
81 meshDir=polyMesh
84 # if -case was specified: insist upon 'constant/polyMesh'
85 if [ -n "$caseDir" ]
86 then
87 if [ -d constant/$meshDir ]
88 then
89 # use constant/polyMesh
90 meshDir=constant/$meshDir
91 else
92 echo "Error: no 'constant/$meshDir' in $caseDir" 1>&2
93 exit 1
95 else
96 if [ -d constant/$meshDir ]
97 then
98 # use constant/polyMesh
99 meshDir=constant/$meshDir
100 elif [ -d $meshDir ]
101 then
102 # likely already in constant/ - do not adjust anything
104 elif [ "${PWD##*/}" = polyMesh -a -z "$regionName" ]
105 then
106 # apparently already within polyMesh/
107 meshDir=.
108 else
109 echo "Error: no appropriate 'polyMesh/' directory found" 1>&2
110 exit 1
116 # remove files (mesh itself, modifiers, snappyHexMesh ones) and subdirectories
117 # also remove .gz versions of the same files
119 echo "Clearing ${caseDir:-.}/$meshDir" 1>&2
121 for i in \
122 points \
123 faces \
124 owner \
125 neighbour \
126 cells \
127 boundary \
128 pointZones \
129 faceZones \
130 cellZones \
131 meshModifiers \
132 parallelData \
133 sets \
134 cellLevel \
135 pointLevel \
136 refinementHistory \
137 surfaceIndex \
140 rm -rf $meshDir/$i $meshDir/$i.gz
141 done
143 #------------------------------------------------------------------------------