#!/bin/sh
#PBS -N tutCAE
#PBS -j oe
##PBS -m abe
#PBS -W group_list=cin_staff
#PBS -q private
#PBS -l walltime=0:30:00
#PBS -l select=1:ncpus=1:mpiprocs=1:mem=12gb
#PBS -A cin_staff
#PBS -V
##PBS -M r.pieri@scsitaly.com

cd $PBS_O_WORKDIR

NPROCS=`wc -l < $PBS_NODEFILE`
EXEC1=`which surfaceFeatureExtract`
EXEC2=`which blockMesh`
EXEC3=`which snappyHexMesh`
EXEC4=`which createPatch`

CHECK=`which checkMesh`

SOLVER=`which pimpleFoam`

echo "Job started at `date` on nodes: `cat $PBS_NODEFILE` "

# -------------------------------------------------------------------------------- #
#                                       MESH                                       #
# -------------------------------------------------------------------------------- #

#cp ../NLR-7301.stl constant/triSurface/
cp ../NLR-7301-airfoil.stl constant/triSurface/NLR-7301.stl

echo "Creating background mesh ... "
time $EXEC2 >& blockMesh.out

echo "Castellating and snapping  ... "
time $EXEC3 -overwrite >& snappy.out

echo "Checking mesh ... "
time $CHECK -constant >& checkMesh.out
'''
# -------------------------------------------------------------------------------- #
#                                      SOLVER                                      #
# -------------------------------------------------------------------------------- #

echo "Removing 0 directory ... "
rm -r 0
cp -r 0.org 0

echo "Renumbering mesh ... "
renumberMesh -overwrite >& renumber.out

echo "Decomposing ... "
decomposePar >& decomp.out

echo "Running solver ... "
### potentialFoam >& poten.out
time mpirun -machinefile $PBS_NODEFILE -np $NPROCS $SOLVER -parallel >& run.out

echo "Reconstructing case ... "
reconstructPar >& reconstruct.out

echo "Sampling outlet ... "
sample >& sample.out

echo "Patch average on Inlet surface"
patchAverage p pump_Inlet > pAverage.out
'''
echo "Job finisched at `date` "
