#!/bin/bash

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

gnuplot<<EOF

#\*------------------------------General settings-----------------------------*/

TIME = system("foamListTimes -case .. -latestTime")

set term pngcairo size 800,600 color enhanced
set title 'Monodisperse Pipe Flow'
set xlabel 'r (mm)'
set xrange [0:25]

set style line 1 lt -1 lw 1 pt 1
set style line 2 lt 2 lw 2 pt 2
set style line 3 lt 3 lw 2 pt 3
set style line 4 lt 4 lw 2 pt 4
set style line 5 lt 5 lw 2 pt 5

#\*------------------------Radial void fraction profile-----------------------*/

set output 'alphaG.png'
set ylabel '{/Symbol a}_g (-)'

plot '../postProcessing/graph/'.TIME.'/line.csv' u (\$1*1000):2 t 'Simulation' w l ls 1

#\*-----------------------Radial solid fraction profile-----------------------*/

set output 'alphaS.png'
set ylabel '{/Symbol a}_s (-)'

plot '../postProcessing/graph/'.TIME.'/line.csv' u (\$1*1000):3 t 'Simulation' w l ls 1

#\*------------------------Radial gas velocity profile------------------------*/

set output 'velocityG.png'
set ylabel 'w_g (m/s)'

plot '../postProcessing/graph/'.TIME.'/line.csv' u (\$1*1000):6 t 'Simulation' w l ls 1

#\*-----------------------Radial solid velocity profile-----------------------*/

set output 'velocityS.png'
set ylabel 'w_s (m/s)'

plot '../postProcessing/graph/'.TIME.'/line.csv' u (\$1*1000):9 t 'Simulation' w l ls 1

#\*--------------------Radial bubble slip velocity profile--------------------*/

set output 'slipVelocityG.png'
set ylabel 'w_{g-rel} (m/s)'

plot '../postProcessing/graph/'.TIME.'/line.csv' u (\$1*1000):(\$6-\$12) t 'Simulation' w l ls 1

#\*-------------------Radial particle slip velocity profile-------------------*/

set output 'slipVelocityS.png'
set ylabel 'w_{s-rel} (m/s)'

plot '../postProcessing/graph/'.TIME.'/line.csv' u (\$1*1000):(\$9-\$12) t 'Simulation' w l ls 1

EOF

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