#!/bin/bash
logfile="log.Allrun"

# basic setup
baseCase=../genericSetup

# parameters defining test matrix
hullVelocityList=( 2 4 8 )
massFlowRateList=( 1e-3 2e-3 4e-3 8e-3 )

for i in ${!hullVelocityList[*]}
do
    hullVelocity=${hullVelocityList[i]}

for j in ${!massFlowRateList[*]}
do
    massFlowRate=${massFlowRateList[j]}

    # derive name for case directory
    caseDir=$(printf "case_U%s_rate%s" "$hullVelocity" "$massFlowRate")
    echo "Case: $caseDir"

    if [ -d "$caseDir" ]; then # skip case if directory already exists

        echo "Case skipped. Directory already exists."
        echo "Case skipped. Directory already exists." >> $logfile

    else # modify base case and run simulation

        # copy base case
        # shellcheck disable=SC2129
            foamCloneCase -add validation "$baseCase" "$caseDir" >> $logfile

        # modify base case

            foamDictionary -entry hull/velocity -set "$hullVelocity" \
                    "$caseDir/constant/caseSettings" \
                    >> $logfile

            foamDictionary -entry injector/massFlowRate -set "$massFlowRate" \
                    "$caseDir/constant/caseSettings" \
                    >> $logfile

        # run case

            "$caseDir/Allrun" >> $logfile & # &: run all at once

    fi

done

done

echo "Done."
