#!/bin/bash
cd "${0%/*}" || exit                                # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions            # Tutorial run functions
. $MULTIPHASE_BIN/tools/RunFunctionsPF
#------------------------------------------------------------------------------

while read -r model
do
    # Configure friction fvModel
    echo -e "\nSetting fvModel for: $model\n"
    sed -e "s/fMODEL/$model/g" constant/fvModels.template > constant/fvModels

    while read -r mesh
    do
        # Configuring and creating well mesh
        let nCells=300/$mesh

        echo -e "\nSetting well mesh for:"
        echo -e "\tNumber of cell = $mesh"
        echo -e "\tCell size = $nCells [m]"

        sed -e "s/meshCELLS/$mesh/g" system/wellMeshingDict.template > system/wellMeshingDict

        echo -e "\nCreating mesh\n"
        runApplication wellMeshing
        runApplication checkMesh

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

        # Running simulation
        runApplication $(getApplication)

        # Post processing plotting and saving data
        runApplication -s 0_0 postProcess -func dpRegion0_0 -region region0

        python3 ${MULTIPHASE_BIN}/pythonScripts/plotResidualsPrgh.py
        python3 postProc.py $model

        # Cleaning directory for next case
        ./Allclean

        # sed -i "s/$mesh/meshCELLS/g" system/wellMeshingDict.template > system/wellMeshingDict

    done < system/zcells

    # sed -i "s/$model/fMODEL/g" constant/fvModels

done < constant/frictionModels
