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

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

# Run case
runApplication blockMesh
runApplication setFields
runApplication foamRun

# Create plot
( cd validation && ./createGraphs )

# Compare to reference solution
latestTime=$(foamListTimes -latestTime)
case=$(basename "$PWD")
cp validation/attachment:mDot.gz          \
    "${latestTime}"/attachment:mDot.ref.gz
cp validation/surfaceLoading.aggregate.gz \
    "${latestTime}"/surfaceLoading.aggregate.ref.gz

runApplication -s "${case}.attachment:mDot" foamPostProcess -latestTime -func \
    "deviation(field=attachment:mDot, reference=attachment:mDot.ref)"
runApplication -s "${case}.surfaceLoading.aggregate" foamPostProcess          \
    -latestTime -func "deviation(field=surfaceLoading.aggregate, \
    reference=surfaceLoading.aggregate.ref)"

mpytest --suffix "${case}.particleHoldup" almostequal \
    postProcessing/particleHoldup/0/volFieldValue.dat \
    validation/particleHoldup/0/volFieldValue.dat

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