mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
- less typing than before and avoids relying on bash-specific behaviour (fixes #3448) ENH: add -region support for cleanFaMesh and cleanPolyMesh CONFIG: add bash completion help for -area-region ENH: general improvements for regionProperties - robustness and failsafe for foamListRegions, regionProperties - additional global model switches for regionModels
150 lines
3.6 KiB
Bash
Executable File
150 lines
3.6 KiB
Bash
Executable File
#!/bin/sh
|
|
#------------------------------------------------------------------------------
|
|
# ========= |
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
# \\ / O peration |
|
|
# \\ / A nd | www.openfoam.com
|
|
# \\/ M anipulation |
|
|
#-------------------------------------------------------------------------------
|
|
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
|
# Copyright (C) 2022,2025 OpenCFD Ltd.
|
|
#------------------------------------------------------------------------------
|
|
# License
|
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
|
#
|
|
# Script
|
|
# foamCleanPolyMesh
|
|
#
|
|
# Description
|
|
# Remove the contents of the constant/polyMesh directory
|
|
# as per the Foam::polyMesh::removeFiles() method.
|
|
#
|
|
#------------------------------------------------------------------------------
|
|
usage() {
|
|
exec 1>&2
|
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
cat <<USAGE
|
|
|
|
Usage: ${0##*/} [OPTION]
|
|
options:
|
|
-case <dir> case directory, default is the cwd
|
|
-region <name> mesh region
|
|
-dry-run | -n report actions but do not remove
|
|
-help print the usage
|
|
|
|
Remove the contents of the constant/polyMesh directory as per the
|
|
Foam::polyMesh::removeFiles() method.
|
|
|
|
USAGE
|
|
exit 1
|
|
}
|
|
|
|
#------------------------------------------------------------------------------
|
|
# Parse options
|
|
unset caseDir regionName optDryRun
|
|
|
|
while [ "$#" -gt 0 ]
|
|
do
|
|
case "$1" in
|
|
-h | -help*)
|
|
usage
|
|
;;
|
|
-dry-run | -n)
|
|
optDryRun="(dry-run) "
|
|
;;
|
|
|
|
-case=*)
|
|
caseDir="${1#*=}"
|
|
;;
|
|
|
|
-case)
|
|
caseDir="$2"
|
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
|
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
|
|
caseDir=$2
|
|
shift
|
|
;;
|
|
|
|
-region)
|
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
|
regionName="$2"
|
|
shift
|
|
;;
|
|
|
|
(*)
|
|
usage "unknown option/argument: '$*'"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Remove files (mesh itself, modifiers, snappyHexMesh ones) and subdirectories
|
|
# also remove .gz versions of the same files
|
|
|
|
removeFiles()
|
|
{
|
|
local directory="$1"
|
|
|
|
for i in \
|
|
points faces \
|
|
owner neighbour \
|
|
boundary \
|
|
cells \
|
|
cellZones faceZones pointZones \
|
|
meshModifiers \
|
|
parallelData \
|
|
sets \
|
|
cellLevel pointLevel \
|
|
level0Edge \
|
|
refinementHistory \
|
|
surfaceIndex \
|
|
;
|
|
do
|
|
if [ -n "$optDryRun" ]
|
|
then
|
|
echo "${optDryRun} rm -rf $directory/{$i,$i.gz}"
|
|
else
|
|
rm -rf -- "$directory/$i" "$directory/$i.gz"
|
|
fi
|
|
done
|
|
}
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
meshDir="constant/${regionName}${regionName:+/}polyMesh"
|
|
|
|
if [ -d "$meshDir" ]
|
|
then
|
|
# [OK] has constant/<region>/polyMesh
|
|
:
|
|
|
|
elif [ -n "$caseDir" ]
|
|
then
|
|
# Specified -case, so no extra magic...
|
|
echo "Error: no <$meshDir> in $caseDir" 1>&2
|
|
exit 1
|
|
|
|
else
|
|
# Try some other combinations
|
|
other="${meshDir#constant/}"
|
|
|
|
if [ -d "$other" ]
|
|
then
|
|
# Probably already within constant/
|
|
meshDir="$other}"
|
|
elif [ "${PWD##*/}" = polyMesh ] && [ -z "$regionName" ]
|
|
then
|
|
# Apparently already within polyMesh/
|
|
meshDir=.
|
|
fi
|
|
fi
|
|
|
|
|
|
echo "Cleaning ${caseDir:-.}/$meshDir" 1>&2
|
|
|
|
removeFiles "$meshDir"
|
|
|
|
#------------------------------------------------------------------------------
|