#!/bin/bash

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

gnuplot<<EOF
    solver = system("foamDictionary -dict ../system/controlDict -entry solver -value")

    set term pngcairo size 800,400

    set output "divPhi.png"
    plot '../postProcessing/probes/0/divPhi'  w l lt 1 t "div(phi) at pRef", \
         '../validation/reference/divPhi' w l lt 2 t "div(phi) at pRef Ref"

    set term pngcairo size 400,800

    set size ratio -1
    set xrange [0:0.08]
    set yrange [0:0.3]
    set xtics  0.04
    set key outside below

    scale_factor = 0.005

    dx(ux,uy) = scale_factor*ux/sqrt(ux**2 + uy**2)
    dy(ux,uy) = scale_factor*uy/sqrt(ux**2 + uy**2)

    do for [time in "0.1 2"] {
        set output 'waterVelocity_'.time.'.png'
        reffile = '../validation/reference/'.time.'/cutPlane.xy'

        plot '../postProcessing/cutPlaneSurface/'.time.'/cutPlane.xy' using 1:3:(dx(\$4,\$6)):(dy(\$4,\$6)) with vectors head filled lt 1 t 'U.water', \
            reffile using 1:3:(dx(\$4,\$6)):(dy(\$4,\$6)) with vectors head filled lt 2 t 'U.water Ref.', \
    }
EOF

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