#!/bin/bash -l
#SBATCH -J ${job}
#SBATCH -p batch
#SBATCH --nodes 1
#SBATCH --ntasks-per-node 32
#SBATCH --cpus-per-task 1
#SBATCH --exclusive
#SBATCH --mem=100g
#SBATCH -A cnms
#SBATCH -t 10:00:00
#SBATCH --mail-type=FAIL
#SBATCH --mail-user=${USER}@ornl.gov

date

module purge
module load PE-gnu/3.0
#module load anaconda3

export LAMMPS=~/NUFEB/lammps/src/lmp_png

ldd $LAMMPS

base=$PWD

#run NUFEB simulations
for dir in runs/*/
do
cd "$dir"
mpirun -np 32 $LAMMPS -in *.lammps > nufeb.log
cd "$base"
done

#check if the previous run went ok, exit if not
if [ $? -ne 0 ]
then
    echo "Something went wrong while running simulations, exiting"
    exit
fi

date

#do the post-processing tasks here

#create tarballs for the VTK files
if ${VTK}
then
    for dir in runs/*/
    do
    cd "$dir"
    tar -zcf VTK.tar.gz *.vtr *.vtu *.vti
    rm *.vtr *.vtu *.vti
    cd "$base"
    done
fi

#check if the previous run went ok, exit if not
if [ $? -ne 0 ]
then
    echo "Something went wrong while creating tarballs, exiting"
    exit
fi


