#!/bin/sh

cd ${0%/*} || exit 1

. $WM_PROJECT_DIR/bin/tools/RunFunctions

gasSpecies="air H2O none"

runApplication blockMesh

for g in $gasSpecies
do
    [ $g != "none" ] && setArg="-set $g" || setArg="-remove"
    foamDictionary -entry inertSpecie $setArg constant/thermophysicalProperties.gas
    runApplication -s $g.gas $(getApplication)
    mv postProcessing postProcessing_$g.gas
done

gnuplot << EOF

set terminal eps enhanced size 5.83,8.27
set output 'postProcessing.eps'

set lmargin at screen 0.15
set rmargin at screen 0.84

gasSpecies = '$gasSpecies'

set multiplot layout 3,1

set xlabel "Time (s)"

set ytics nomirror
set y2tics
set ylabel 'Gas volume fraction'
set y2label 'Liquid volume fraction'

plot \
    'postProcessing_none.gas/plot/0/alpha.gas' w l lc 1 t 'Gas', \
    for [g in gasSpecies] \
    'postProcessing_'.g.'.gas/plot/0/alpha.gas' w l lc 1 notitle, \
    'postProcessing_none.gas/plot/0/alpha.liquid' w l axes x1y2 lc 2 t 'Liquid', \
    for [g in gasSpecies] \
    'postProcessing_'.g.'.gas/plot/0/alpha.liquid' w l axes x1y2 lc 2 notitle

set ytics mirror
unset y2tics
set ylabel 'Temperature (K)'
unset y2label

plot \
    'postProcessing_none.gas/plot/0/T.gas' w l lc 1 t 'Gas', \
    for [g in gasSpecies] \
    'postProcessing_'.g.'.gas/plot/0/T.gas' w l lc 1 notitle, \
    'postProcessing_none.gas/plot/0/T.liquid' w l lc 2 t 'Liquid', \
    for [g in gasSpecies] \
    'postProcessing_'.g.'.gas/plot/0/T.liquid' w l lc 2 notitle

set ytics nomirror
set y2tics
set ylabel "Vapour mass fraction"
set y2label "Air mass fraction"

plot \
    'postProcessing_none.gas/plot/0/H2O.gas' w l lc 1 t 'H2O', \
    for [g in gasSpecies] \
    'postProcessing_'.g.'.gas/plot/0/H2O.gas' w l lc 1 notitle, \
    'postProcessing_none.gas/plot/0/air.gas' w l axes x1y2 lc 2 t 'Air', \
    for [g in gasSpecies] \
    'postProcessing_'.g.'.gas/plot/0/air.gas' w l axes x1y2 lc 2 notitle

unset multiplot

EOF
