|
1 | | -#! /bin/sh |
| 1 | +#!/usr/bin/env bash |
2 | 2 |
|
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 |
4 | 5 | openfoam_remove_empty_dirs() { |
5 | 6 | ( |
6 | 7 | set -e -u |
7 | | - echo "Cleaning up any time directories without results" |
8 | 8 |
|
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}" |
20 | 32 | fi |
21 | 33 | done |
22 | | - cd .. |
23 | | - done |
24 | | - fi |
25 | | - echo "Done." |
| 34 | + done |
| 35 | + echo "Done." |
26 | 36 | ) |
27 | 37 | } |
0 commit comments