#!/bin/sh
# autopkgtest check
# (C) 2014 Anton Gladky

set -e

export OMPI_MCA_orte_rsh_agent=/bin/false

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

cat <<EOF > demo.tst
# Title: Hydrostatic balance with solid boundaries and viscosity
#
# Description:
#
# Checks that hydrostatic balance is accurately computed when coupled
# with the Crank-Nicholson discretisation of viscous terms.
#
# Author: St\'ephane Popinet
# Command: gerris2D hydrostatic.gfs
# Version: 1.1.3
# Required files:
1 0 GfsSimulation GfsBox GfsGEdge {} {
    Refine 3
    Source V -1
    SourceViscosity 1e-2
    Solid (ellipse(0.,0.,0.24,0.24))
    Time { iend = 10 }
    ApproxProjectionParams { tolerance = 1e-12 }
    ProjectionParams { tolerance = 1e-12 }

    OutputScalarNorm { istep = 1 } v { v = V }
    EventScript { start = end } { 
        if awk '{if (\$9 > 1.5e-12) { print \$9 > "/dev/stderr"; exit (1); }}' < v ; then
            exit 0;
        else
            exit \$GFS_STOP;
        fi
    }
}
GfsBox {
    bottom = Boundary
}
EOF

gerris2D ./demo.tst
ls -ln
cat v
rm v
echo "run: OK"
