#!/bin/bash

if ! which gnuplot > /dev/null 2>&1
then
    echo 'gnuplot not found - skipping graph creation' >&2
    exit 1
fi

gnuplot -p <<EOF

    FILE = "../postProcessing/phasesVolume/0/volFieldValue.dat"
    R1FILE = 'reference_noPhaseMassController/phasesVolume/volFieldValue.dat'
    R2FILE = 'reference/phasesVolume/volFieldValue.dat'

    domainVolume=0.006

    set linetype 1 lc rgb 'blue'   lw 3 dt 1
    set linetype 2 lc rgb 'blue'   lw 1 dt 1
    set linetype 3 lc rgb 'blue'   lw 1 dt 2
    set linetype 4 lc rgb 'red'    lw 3 dt 1
    set linetype 5 lc rgb 'red'    lw 1 dt 1
    set linetype 6 lc rgb 'red'    lw 1 dt 2
    set linetype 7 lc rgb 'black'  lw 3 dt 2

    set term pngcairo size 1000,800
    set grid
    set key top left horizontal
    set xlabel 't [s]'


    set output 'phasesVolume.png'
    set ylabel '<r_{/Symbol a}> [-]'

    plot FILE u 1:(\$4/domainVolume)       w l lt 1 t 'liquid'  , \
         FILE u 1:(\$2/domainVolume)       w l lt 2 t 'liquidC' , \
         FILE u 1:(\$3/domainVolume)       w l lt 3 t 'liquidD' , \
         FILE u 1:(\$7/domainVolume)       w l lt 4 t 'gas'     , \
         FILE u 1:(\$5/domainVolume)       w l lt 5 t 'gasC'    , \
         FILE u 1:(\$6/domainVolume)       w l lt 6 t 'gasD'    , \
         FILE u 1:((\$4+\$7)/domainVolume) w l lt 7 t 'total'


    set output 'totalLiquidVolume.png'
    set ylabel "V_L [m^3]"

    plot R1FILE u 1:(\$4/domainVolume) w l lt 7 t 'no phaseMassController', \
         R2FILE u 1:(\$4/domainVolume) w l lt 3 t 'reference', \
           FILE u 1:(\$4/domainVolume) w l lt 1 t 'current'
EOF

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