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

# Source case functions
. "$WM_PROJECT_DIR/bin/tools/casesFunctions.sh"

caseNumber=$(foamDictionary caseParameterDict -entry case -value)
latestTime=$(foamListTimes -functionEntries | tail -n 1)
targetDirectory="validation/reference/${caseNumber}"
mkdir -p "$targetDirectory"

# Temporal averaging
mpypost avg --starttime 0.5 postProcessing/holdupLiquidC/0/volFieldValue.dat
mpypost avg --starttime 0.5 postProcessing/holdupLiquidD/0/volFieldValue.dat
mpypost avg --starttime 0.5 postProcessing/pressureProbes/0/p

# Copy results from latest run into reference directory
cp -f \
    postProcessing/interfaceMean/"${latestTime}"/filmThickness_*_[0-9.-]*.dat \
    "${targetDirectory}"
cp -f postProcessing/report/filmThickness_1.00.png "${targetDirectory}"
cp -f postProcessing/liquidCrossSection/"${latestTime}"/layerAverage.xy \
    "${targetDirectory}"
cp -f postProcessing/holdupLiquidC/0/volFieldValue_avg.csv \
    "${targetDirectory}"/holdupLiquidC_avg.csv
cp -f postProcessing/holdupLiquidD/0/volFieldValue_avg.csv \
    "${targetDirectory}"/holdupLiquidD_avg.csv
cp -f postProcessing/pressureProbes/0/p_avg.csv "${targetDirectory}"

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