Skip to content

Commit be6669b

Browse files
authored
Simplify the openfoam_remove_empty_dirs.sh script (#879)
1 parent b8cbf76 commit be6669b

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

‎changelog-entries/879.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Rewrote the openfoam_remove_empty_dirs.sh script to make it simpler, more general, and to allow it to work with collated output. [#879](https://github.com/precice/tutorials/pull/879)
Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
#! /bin/sh
1+
#!/usr/bin/env bash
22

3-
# Cleaning up stray functionObjectProperties files, see https://github.com/precice/openfoam-adapter/issues/26
3+
# Cleaning up stray functionObjectProperties files to not polute the post-processed time steps,
4+
# see https://github.com/precice/openfoam-adapter/issues/26
45
openfoam_remove_empty_dirs() {
56
(
67
set -e -u
7-
echo "Cleaning up any time directories without results"
88

9-
for f in [0-9]* [0-9]*.[0-9]*; do
10-
if ! [ -f "${f}/U" ] && ! [ -f "${f}/T" ] && ! [ -f "${f}/U.gz" ] && ! [ -f "${f}/T.gz" ] && ! [ -f "${f}/D" ] && ! [ -f "${f}/pointD" ] && ! [ -f "${f}/DD" ] && ! [ -f "${f}/pointDD" ] && ! [ -f "${f}/D.gz" ] && ! [ -f "${f}/pointD.gz" ] && ! [ -f "${f}/DD.gz" ] && ! [ -f "${f}/pointDD.gz" ]; then
11-
rm -rf "${f}"
12-
fi
13-
done
14-
if [ -d processor0 ]; then
15-
for d in processor*; do
16-
cd "${d}"
17-
for f in [0-9]* [0-9]*.[0-9]*; do
18-
if ! [ -f "${f}/U" ] && ! [ -f "${f}/T" ] && ! [ -f "${f}/U.gz" ] && ! [ -f "${f}/T.gz" ] && ! [ -f "${f}/D" ] && ! [ -f "${f}/pointD" ] && ! [ -f "${f}/DD" ] && ! [ -f "${f}/pointDD" ] && ! [ -f "${f}/D.gz" ] && ! [ -f "${f}/pointD.gz" ] && ! [ -f "${f}/DD.gz" ] && ! [ -f "${f}/pointDD.gz" ]; then
19-
rm -rf "${f}"
9+
DIRECTORIES_TO_CHECK=("." "processor"*)
10+
OPENFOAM_RESULT_FILES=("p" "U" "T" "D" "pointD" "DD" "pointDD")
11+
12+
echo "Cleaning up any time directories without results to make post-processing easier."
13+
echo "Searching in the following directories: " "${DIRECTORIES_TO_CHECK[@]}"
14+
echo "Keeping all time directories that include any of the following files: " "${OPENFOAM_RESULT_FILES[@]}"
15+
echo "and removing the rest..."
16+
17+
# Search the current and every processor* directory for common results files.
18+
# If there are none, remove the directory.
19+
for pd in "${DIRECTORIES_TO_CHECK[@]}"; do
20+
for d in "${pd}"/[0-9]* "${pd}"/[0-9]*.[0-9]*; do
21+
KEEP_DIRECTORY=false
22+
for r in "${OPENFOAM_RESULT_FILES[@]}"; do
23+
# OpenFOAM can be configured to store files either as compressed or uncompressed
24+
if [[ -f "${d}/${r}" ]] || [[ -f "${d}/${r}.gz" ]]; then
25+
KEEP_DIRECTORY=true
26+
break;
27+
fi
28+
done
29+
if ! [[ ${KEEP_DIRECTORY} == true ]]; then
30+
# None of the expected result files found - delete the directory
31+
rm -rfv "${d}"
2032
fi
2133
done
22-
cd ..
23-
done
24-
fi
25-
echo "Done."
34+
done
35+
echo "Done."
2636
)
2737
}

0 commit comments

Comments
 (0)