#!/bin/sh -e
cd "${0%/*}" || exit                                  # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions          # Tutorial run functions
#------------------------------------------------------------------------------

# Case identifier variable
caseTag=1

while read -r fluxValue
do
    echo "\n========== CASE $caseTag ==========\n"

    # Create and modify mesh
    runApplication wellMeshing
    runApplication topoSet
    runApplication checkMesh

    # Create 0 directory
    cp -a 0.orig/. 0 -R

    # Applying case flux value to boundary conditions
    sed -i "s/FLUXVALUE/$fluxValue/g" 0/U.oil

    # Running simulation
    runApplication $(getApplication)

    # Post processing
    runApplication -s 0_0 postProcess -func dpRegion0_0 -region region0
    runApplication -s 0_1 postProcess -func dpRegion0_1 -region region0

    python3 postProcess.py

    # Update case tag
    caseTag=$(( $caseTag + 1 ))

    # Cleaning directory for next case
    ./Allclean

done < 0.orig/icvFlowRate

#------------------------------------------------------------------------------
