#!/bin/sh

currDir=`pwd`
application=`basename $currDir`
cases="damBreak damBreakFine"

tutorialPath=`dirname $0`/..
. $tutorialPath/RunFunctions

setDamBreakFine ()
{
    blockMeshDict="$case/constant/polyMesh/blockMeshDict"
    controlDict="$case/system/controlDict"        
    sed \
    -e s/"23 8"/"46 10"/g \
    -e s/"19 8"/"40 10"/g \
    -e s/"23 42\(.*\) 1 1)"/"46 76\1 2 1)"/g \
    -e s/"4 42\(.*\) 1 1)"/"4 76\1 2 1)"/g \
    -e s/"19 42\(.*\) 1 1)"/"40 76\1 2 1)"/g \
    $blockMeshDict > temp.$$
    mv temp.$$ $blockMeshDict
    sed \
    -e s/"\(deltaT[ \t]*\) 0.001;"/"\1 5e-04;"/g \
    -e s/"\(endTime[ \t]*\) 1;"/"\1 0.4;"/g \
    $controlDict > temp.$$
    mv temp.$$ $controlDict    
}

for case in $cases
do
    if [ "$case" = "damBreakFine" ] 
    then
        cloneCase damBreak $case
        setDamBreakFine
        cp damBreak/0/gamma.org $case/0/gamma
    fi

    runApplication blockMesh $case
    runApplication setFields $case
    if [ "$case" = "damBreakFine" ]
    then
        runApplication decomposePar $case
        hostname > $case/system/machines
        runParallel $application $case 4 $case/system/machines
        runApplication reconstructPar $case
    else
        runApplication $application $case
    fi
done
