#!/bin/bash
cd ${0%/*} || exit 1 # Run from this directory

# Source PATO run functions
. $PATO_DIR/src/applications/utilities/runFunctions/RunFunctions

# Initialize the script
pato_init

# source OpenFOAM and PATO if darwin
if [ "$(uname)" = "Darwin" ]; then
    source $FOAM_ETC/bashrc
    source $PATO_DIR/bashrc
fi

# Source tutorial run functions
. "$WM_PROJECT_DIR/bin/tools/RunFunctions"

# Create 0 folder
if [ ! -d 0 ]; then
    cp -r origin.0 0
fi

# Extract fibres surface on a sub-set of the triSurface  (dictionnaire: surfaceSubsetDict)
surfaceSubset constant/triSurface/cube_minus_sphere.obj constant/triSurface/fibres.obj system/surfaceSubsetDict

# Extract surface features (dictionnaire: surfaceFeaturesDict)
surfaceFeatures

# Create background mesh (dictionnaire: blockMeshDict)
blockMesh

# Create final mesh (dictionaire: snappyHexMeshDict, meshQualityDict)
snappyHexMesh -overwrite

# Check the Mesh for information
checkMesh

# Decompose the mesh for parallel running (dictionnaire: decomposeParDict)
mv constant/polyMesh constant/fluid 

# Make the linear system more diagonal dominant. It will speed-up the linear solvers.
renumberMesh -overwrite -region fluid 

# To run in parallel the solver. getApplication finds solver name from "application" entry in controlDict
$(getApplication)

# To plot the drag coefficient
#gnuplot plot/plot_cd

# To visualize the streamlines
#paraview postProcessing/sets/streamlines/fluid/600/track0_U.vtk 

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