#!/bin/sh

# This script is setup to run in serial for demonstration purposes.
# A realistic scenario is that you are running this on a cluster.
# In this case, run
# decomposePar
# after constructing the grid and run funkySetFields and the solver
# in parallel.
# After the solver is done, run
# reconstructPar -latestTime
# The paths in the rm command below have to also be adjusted.

# Copy dummy initial conditions
cp -r 0.org 0

# Generate the grid
blockMesh

# Run
# decomposePar
# here if running in parallel

# You can additionally run
# renumberMesh
# to make its numbering better suited for the simulations, resulting in some
# speedup

# Generate initial conditions
funkySetFields -time 0

# Run the solver. It will stop at time 250, which corresponds to the
# initial transient. You may want to make an initial investigation of
# the results at this point, to check for any obvious issues. There
# should not be any, but this is just good practice in general.
pimpleFoam

# Remove the mean fields to restart the averages. This way new averages
# will not be contaminated by the initial transient.
rm 250/*Mean
rm -r 250/uniform

# Change the endTime in the controlDict to 750 and run the solver again.
pimpleFoam

# Run
# reconstructPar
# here if running in parallel

# Average fields in xz
postChannelFlow -latestTime

# Compute the TKE budgets
channelBudgets -latestTime