感谢版主和若水提供的建议,通过在bash脚本中加入循环执行语句,配合controlDict中timeActivatedFileUpdate函数实现需求的效果。其中bash脚本如下,供有需求的人参考。
while (( (echo "$time_start < $time_end" | bc -l) ))
do
# Step 1: Run setFields in parallel mode
mpirun -np $TOTAL_TASKS setFields -parallel > log.setFields_$time_start 2>&1
# Step 2: Run the case from time_start to time_start + time_step
# ControlDict will be updated using timeActivatedFileUpdate function
mpirun -np $TOTAL_TASKS icoFoam -parallel > log.icoFoam_$time_start 2>&1
# Increment time_start for the next interval
time_start=$(echo "$time_start + $time_step" | bc)
done