#!/bin/bash
cd "${0%/*}" || exit 1    # Run from this directory

# Source run functions
. "$WM_PROJECT_SITE/$WM_PROJECT_VERSION/bin/tools/RunFunctions"

runApplication blockMesh -dict system/blockMeshDict.target
mkdir -p constant/targetMesh/polyMesh
mv constant/polyMesh/* -t constant/targetMesh/polyMesh
runApplication -append blockMesh -dict system/blockMeshDict.initial
runApplication foamRun

latestTime=$(foamListTimes -latestTime)
cp "0/U.air1" "${latestTime}/U.air1.ref"
cp "0/U.water" "${latestTime}/U.water.ref"
cp "0/alpha.air1" "${latestTime}/alpha.air1.ref"
cp "0/alpha.water" "${latestTime}/alpha.water.ref"
runApplication -s "U.air1" foamPostProcess \
    -func \
        "deviation(field=U.air1, reference=U.air1.ref, maxAbsDev=1e-12)" \
    -latestTime
runApplication -s "U.water" foamPostProcess \
    -func \
        "deviation(field=U.water, reference=U.water.ref, maxAbsDev=1e-12)" \
    -latestTime
runApplication -s "alpha.air1" foamPostProcess \
    -func \
        "deviation(field=alpha.air1, reference=alpha.air1.ref, \
    maxAbsDev=1e-12)" \
    -latestTime
runApplication -s "alpha.water" foamPostProcess \
    -func \
        "deviation(field=alpha.water, reference=alpha.water.ref, \
        maxAbsDev=1e-12)" \
    -latestTime

( cd validation && ./createGraphs )

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