#!/bin/sh
# Compile and run a small Poisson problem against the installed library.
set -e
cd "$AUTOPKGTEST_TMP"
export OMPI_MCA_rmaps_base_oversubscribe=1 OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1

cat > dirichlet.cc <<'EOT'
#include "rheolef.h"
using namespace rheolef;
using namespace std;
int main(int argc, char**argv) {
  environment rheolef (argc, argv);
  geo omega (argv[1]);
  space Xh (omega, argv[2]);
  Xh.block ("boundary");
  trial u (Xh); test v (Xh);
  form  a  = lazy_integrate (dot(grad(u),grad(v)));
  field lh = lazy_integrate (v);
  field uh (Xh);
  uh ["boundary"] = 0;
  problem p (a);
  p.solve (lh, uh);
  dout << uh;
}
EOT

$(rheolef-config --cxx) $(rheolef-config --includes) -o dirichlet dirichlet.cc $(rheolef-config --libs)
echo "build: OK"

mkgeo_grid -t 10 > square.geo
./dirichlet square.geo P1 > square.field
test -s square.field
echo "run: OK"
