\chapter{ Descripton of program structure}
\section{ Single domain setup}

The program XBeach consists of a main \textit{Fortran 90} program, xbeach.f90, and a number of \textit{subroutines} that operate on two \textit{derived types (structures)}:

\begin{enumerate}
\item  par -- this contains general input parameters

\item  s     -- this contains all the arrays for a given computational domain
\end{enumerate}

For a single-domain run, one structure s is passed between flow, wave, sediment and bed update solvers, which extract the arrays they need from the structure elements to local variables, do their thing and pass the results back to the relevant structure elements. This makes the overall program clear, prevents long parameter lists and makes it easy to add input variables or arrays where needed. The various subroutines and their purposes are outlined in Table 3.1.

Table 3.1. Overview of Fortran 90 subroutine calls by xbeach.f90

\begin{tabular}{|p{1.7in}|p{2.2in}|} \hline 
Function call & Purpose \\ \hline 
wave\_input(par) & Creates elements of structure par containing wave input parameters \\ \hline 
flow\_input(par) & Adds elements of structure par containing flow input parameters \\ \hline 
sed\_input(par) & Adds elements of structure par containing sediment input parameters \\ \hline 
grid\_bathy(s) & Creates grid and bathymetry and stores them in structure s \\ \hline 
distribute\_par(par) & MPI \\ \hline 
space\_alloc\_scalars(sglobal) & allocates space \\ \hline 
grid\_bathy(s,par) & sets up grid and bathymetry \\ \hline 
xmpi\_determine\_processor\_grid(s\%nx & s\%ny) \\ \hline 
readtide(s,par) & Read tide levels \\ \hline 
readwind (s, par) & Read wind field \\ \hline 
init\_output & Read output requests and initialize output files \\ \hline 
wave\_init (s,par) & Initialises arrays (elements of s) for wave computations \\ \hline 
flow\_init (s,par) & Initialises arrays (elements of s) for flow computations \\ \hline 
gwinit(s,par) & Initialises arrays (elements of s) for groundwater module \\ \hline 
sed\_init (s,par) & Initialises arrays (elements of s) for sediment computations \\ \hline 
init\_output(sglobal,slocal,par,it) &  \\ \hline 
call readkey &  \\ \hline 
\end{tabular}

\eject 

\begin{tabular}{|p{1.7in}|p{2.2in}|} \hline 
\multicolumn{2}{|p{1in}|}{\textbf{Start time loop}} \\ \hline 
timestep (s,par,it) & Calculate automatic timestep \\ \hline 
wave\_bc (s,par) & Wave boundary conditions update, each timestep \\ \hline 
gwbc(s,par) & Groundwater boundary conditions update, each timestep \\ \hline 
flow\_bc (s,par) & Flow boundary conditions update, each timestep \\ \hline 
wave\_timestep(s,par) & Carries out one wave timestep, OR \\ \hline 
wave\_stationary(s,par) & Carries out stationary wave computation \\ \hline 
gwflow(par,s) & carries out flow timestep of groundwater flow \\ \hline 
flow\_timestep (s,par) & Carries out one flow timestep \\ \hline 
drifter (s,par) &  \\ \hline 
transus(s,par) & Carries out one suspended plus bedload transport timestep \\ \hline 
bed\_update(s,par) & Carries out one bed level update timestep \\ \hline 
var\_output(it,s,par) & Performs output \\ \hline 
\textbf{End time loop} &  \\ \hline 
\end{tabular}
\section{ Implementation of parallel computing using MPI}

We refer to the ``Parallelization Report''.

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "xbeach_manual"
%%% End: 
