File size: 3,074 Bytes
ed552fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# run_stokes_loop.sh — 逐个运行 stokes_wave case,替代 batch_run.sh
# 每个 case 独立运行,完成后立即写日志,避免 batch_run.sh 卡住问题

source /usr/share/openfoam/etc/bashrc 2>/dev/null
export WM_PROJECT_DIR=/usr/share/openfoam
export FOAM_APPBIN=/usr/bin
export FOAM_LIBBIN=/usr/lib/openfoam
export PATH=$FOAM_APPBIN:$PATH
export LD_LIBRARY_PATH=$FOAM_LIBBIN${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

DATA_DIR="/mnt/f/agent-workspace/paper2/Exp/data/raw"
CASE_TYPE="stokes_wave"
NCPU=16
LOG="/mnt/f/agent-workspace/paper2/Exp/data/scripts/loop_stokes.log"

log() {
    local msg="[$(date '+%Y-%m-%d %H:%M:%S')] $*"
    echo "$msg"
    echo "$msg" >> "$LOG"
}

check_completed() {
    local log_file="$1/log.interFoam"
    [ -f "$log_file" ] && tail -3 "$log_file" | grep -q "End"
}

log "========================================="
log "  stokes_wave 循环运行 (t01-t49)"
log "  MPI: $NCPU"
log "========================================="

for IDX in $(seq 1 49); do
    CASE_NAME=$(printf "t%02d" $IDX)
    CASE_DIR="$DATA_DIR/$CASE_TYPE/$CASE_NAME"

    if [ ! -d "$CASE_DIR" ]; then
        log "[WARN] $CASE_NAME — 目录不存在,跳过"
        continue
    fi

    if check_completed "$CASE_DIR"; then
        log "[SKIP] $CASE_NAME — 已完成"
        continue
    fi

    CASE_START=$(date +%s)
    log "[START] $CASE_NAME"

    cd "$CASE_DIR" || continue

    # 清理旧 processor 目录
    rm -rf processor*

    # blockMesh
    blockMesh > log.blockMesh 2>&1
    if [ $? -ne 0 ]; then
        log "[FAIL] $CASE_NAME — blockMesh 失败"
        continue
    fi

    # setFields (stokes_wave 需要)
    setFields > log.setFields 2>&1
    if [ $? -ne 0 ]; then
        log "[FAIL] $CASE_NAME — setFields 失败"
        continue
    fi

    # decomposePar
    NX=$(python3 -c "import math; n=int(math.sqrt($NCPU)); print(n if n*n==$NCPU else $NCPU)")
    NY=$(python3 -c "import math; n=int(math.sqrt($NCPU)); print($NCPU//n)")
    sed -i "s/numberOfSubdomains [0-9]*/numberOfSubdomains $NCPU/" system/decomposeParDict
    sed -i "s/n\s*( *[0-9]* *[0-9]* *[0-9]*)/n           ($NX $NY 1)/" system/decomposeParDict
    decomposePar -force > log.decomposePar 2>&1
    if [ $? -ne 0 ]; then
        log "[FAIL] $CASE_NAME — decomposePar 失败"
        continue
    fi

    # interFoam
    mpirun --oversubscribe -np "$NCPU" interFoam -parallel > log.interFoam 2>&1
    INTERFOAM_EXIT=$?

    # reconstructPar(重建所有时间步,不用 -latestTime)
    reconstructPar > log.reconstructPar 2>&1

    # 清理 processor

    CASE_END=$(date +%s)
    CASE_ELAPSED=$((CASE_END - CASE_START))
    CASE_MINS=$((CASE_ELAPSED / 60))
    CASE_SECS=$((CASE_ELAPSED % 60))

    if check_completed "$CASE_DIR"; then
        log "[DONE] $CASE_NAME (${CASE_MINS}m${CASE_SECS}s)"
    else
        log "[FAIL] $CASE_NAME — interFoam 未完成 (${CASE_MINS}m${CASE_SECS}s)"
    fi
done

log "========================================="
log "  stokes_wave 全部完成"
log "========================================="