% Complete documentation on the extended LaTeX markup used for Python
% documentation is available in ``Documenting Python'', which is part
% of the standard documentation for Python.  It may be found online
% at:
%
%     http://www.python.org/doc/current/doc/doc.html


%\newcommand{\code}[1]{{\small \tt #1}} %For use with one-line code snippets
	
\documentclass{manual}

\title{AnuGA User Manual}
\author{Howard Silcock, Ole Nielsen, Duncan Gray, Jane Sexton}

% Please at least include a long-lived email address;
% the rest is at your discretion.
\authoraddress{Geoscience Australia \\
  Email: \email{ole.nielsen@ga.gov.au}
}

\date{2 February, 2006}		% update before release!
				% Use an explicit date so that reformatting
				% doesn't cause a new date to be used.  Setting
				% the date to \today can be used during draft
				% stages to make it easier to handle versions.

\release{1.0}			% release version; this is used to define the
				% \version macro

\makeindex			% tell \index to actually write the .idx file
%\makemodindex			% If this contains a lot of module sections.




% Can we get rid of indenting and put a blank line before each para?
% Find out how to change date format
% Relabel sections, subsections
Make conflict here
%\setlength{\parindent}{0mm} %\setlength{\parskip}{3pt}
%\setlength{\oddsidemargin}{0.6in}\setlength{\evensidemargin}{0.6in}
%\addtolength{\textheight}{1in} \addtolength{\textwidth}{0.5in}
%\setlength{\marginparwidth}{0in}
%\setlength{\topmargin}{0mm}\setlength{\headheight}{0in}

\begin{document}
\maketitle

% This makes the contents more accessible from the front page of the HTML.
\ifhtml
\chapter*{Front Matter\label{front}}
\fi

%Subversion keywords:
%
%$LastChangedDate: 2006-01-13 16:43:01 +1100 (Fri, 13 Jan 2006) $
%$LastChangedRevision: 2206 $
%$LastChangedBy: steve $


\begin{abstract}

\noindent
\textbf{AnuGA}\index{AnuGA} is a hydrodynamic modelling tool that
allows users to model realistic flow problems in complex geometries. Examples include dam breaks or    
the effects of natural hazards such as riverine flooding, storm surges and tsunami. 

The user must specify a study area represented by a mesh of triangular
cells, the topography and bathymetry, frictional resistance, initial
values for water level (called \emph{stage}\index{stage} within Anuga), 
boundary
conditions and forces such as windstress or pressure gradients if
applicable.

Anuga tracks the evolution of water depth and horizontal momentum
within each cell over time by solving the shallow water wave equation
governing equation using a finite-volume method.

Anuga cannot model details of breaking waves, flow under ceilings such
as pipes, turbulence and vortices, vertical convection or viscous
flows.

Anuga also incorporates a mesh generator, called \texttt{pmesh}, that
allows the user to set up the geometry of the problem interactively as
well as tools for interpolation and surface fitting, and a number of
auxiliary tools for visualising and interrogating the model output.

Most AnuGA components are written in the object-oriented programming
language Python and most users will interact with Anuga by writing
small Python programs based on the Anuga library
functions. Computationally intensive components are written for
efficiency in C routines working directly with the Numerical Python
structures.


\end{abstract}

\tableofcontents


\chapter{Introduction}


\section{Purpose}

The purpose of this user manual is to introduce the new user to
the software, describe what it can do and give step-by-step
instructions for setting up, configuring and running the software.

\section{Scope}

This manual covers only what is needed to operate the software
after installation. It does not includes instructions for
installing the software or detailed API documentation, both of
which will be covered in separate publications.

\section{Audience}

Readers are assumed to be familiar with the operating environment
and have a general understanding of the problem background, as
well as enough programming experience to adapt the code to
different requirements, as described in this manual,  and to
understand the basic terminology of object-oriented programming.

\section{Structure of This Manual}

This manual is structured as follows:

\begin{itemize}
  \item Background (What Anuga does)
  \item A \emph{Getting Started} section
  \item Anuga's overall architecture, components and file formats
  \item Detailed descriptions of the user interface
\end{itemize}


\pagebreak
\chapter{Getting Started}

This section is designed to assist the reader to get started with
\textbf{AnuGA} by working through a simple example. What follows
is a discussion of the structure and operation of the file
\texttt{bedslope.py}, with just enough detail to allow the reader
to appreciate what's involved in setting up a scenario like the
one it depicts.

\section{Overview}

This example carries out the solution of the shallow-water wave
equation in the simple case of a configuration comprising a flat
bed, sloping at a fixed angle in one direction and having a
constant depth across each line in the perpendicular direction.

The example demonstrates many of the basic ideas involved in
setting up a more complex scenario. In the general case the user
specifies the geometry (bathymetry and topography), the initial
water level, boundary conditions such as tide, and any forcing
terms that may drive the system such as wind stress or atmospheric
pressure gradients. Frictional resistance from the different
terrains in the model is represented by predefined forcing
terms. The boundary is reflective on three sides and a time dependent wave on one side.

The present example, as it represents a simple scenario, does not
include any forcing term, nor is the data taken from a file as it
would be in many typical cases. The quantities involved in the
present problem are:
\begin{itemize}
   \item elevation\index{elevation}
   \item friction\index{friction}
   \item depth\index{depth}
   \item stage\index{stage}
\end{itemize}

%\emph{[More details of the problem background]}

\section{Outline of the Program}

In outline, \texttt{bedslope.py} performs the following steps:

\begin{enumerate}

   \item Sets up a triangular mesh.

   \item Sets certain parameters governing the mode of
operation of the model-specifying, for instance, where to store the model output.


   \item Inputs various quantities describing physical measurements, such
as the elevation, to be specified at each mesh point (vertex).

   \item Sets up the boundary conditions.

   \item Carries out the evolution of the model through a series of time
steps and outputs the results, providing a results file that can
be visualised.

\end{enumerate}

\section{The Code}

%FIXME: we are using the \code function here. This should be used whereever possible
For reference we include below the complete code listing for
\code{bedslope.py}. Subsequent paragraphs provide a `commentary'
that describes each step of the program and explains it significance.


%\emph{[Can't work out how to prevent \LaTeX (or WinEdt) from
%wrapping lines, even in \emph{verbatim} mode, without putting}
%\verb+\\+\emph{s at the ends of lines!]}

{\scriptsize \begin{verbatim}
from pyvolution.mesh_factory import rectangular
from pyvolution.shallow_water import Domain, Reflective_boundary,
     Dirichlet_boundary, Time_boundary, Transmissive_boundary

#Create basic mesh
points, vertices, boundary = rectangular(10,10)

#Create shallow water domain
domain = Domain(points, vertices,boundary)
domain.set_name('bedslope')


#######################
# Initial conditions
def f(x,y):
    return -x/2

domain.set_quantity('elevation', f)
domain.set_quantity('friction', 0.1)

h = 0.05  # Constant depth
domain.set_quantity('stage', expression = 'elevation + %f' %h)


# Boundary conditions
from math import sin, pi
Br = Reflective_boundary(domain)
Bt = Transmissive_boundary(domain) 
Bd = Dirichlet_boundary([0.2,0.,0.])

Bw = Time_boundary(domain=domain,
                   f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0])


domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br})


######################
#Evolution

domain.check_integrity()

for t in domain.evolve(yieldstep = 0.1, finaltime = 4.0):
    domain.write_time()


\end{verbatim}}


\section{Establishing the Mesh}

The first task is to set up the triangular mesh to be used for the
scenario. This is carried out through the statement:

{\small \begin{verbatim}
    points, vertices, boundary = rectangular(10, 10) 
\end{verbatim}}

The function \texttt{rectangular} is imported from a module
\texttt{mesh\_factory} defined elsewhere. (\textbf{AnuGA} also
contains several other schemes that can be used for setting up
meshes, but we shall not discuss these now.) The above assignment
sets up a $10 \times 10$ rectangular mesh, triangulated in a
specific way. In general, the assignment

{\small \begin{verbatim}
    points, vertices, boundary = rectangular(m, n)
\end{verbatim}}

returns:

\begin{itemize}

   \item a list \texttt{points} of length $N$, where $N = (m + 1)(n + 1)$,
comprising the coordinates $(x, y)$ of each of the $N$ mesh
points,

   \item a list \texttt{vertices} of length $2mn$ (each entry specifies the three
vertices of one of the triangles used in the triangulation) , and

   \item a dictionary \texttt{boundary}, used to tag the triangle edges on
the boundaries. Each key corresponds to a triangle edge on one of
the four boundaries and its value is one of \texttt{`left'},
\texttt{`right'}, \texttt{`top'} and \texttt{`bottom'}, indicating
which boundary the edge in question belongs to.

\end{itemize}


\section{Initialising the domain}

These variables are then used to set up a data structure
\texttt{domain}, through the assignment:

{\small \begin{verbatim}
    domain = Domain(points, vertices, boundary)
\end{verbatim}}

This uses a Python class \texttt{Domain}, imported from
\texttt{shallow\_water}, which is an extension of a more generic
class of the same name in the module \texttt{domain}, and inherits
some methods from the generic class but has others specific to the
shallow-water scenarios in which it is used. Specific options for domain 
are set at this point. One of them are to set the basename for the output file

{\scriptsize \begin{verbatim}
    domain.set_name('bedslope')
\end{verbatim}}


\section{Specifying the Quantities}

The next task is to specify a number of quantities that we wish to set
for each mesh point. The class \texttt{Domain} has a method
\texttt{set\_quantity}, used to specify these quantities. It is a
particularly flexible method that allows the user to set quantities in
a variety of ways---using constants, functions, numeric arrays or
expressions involving other quantities, arbitrary data points with
associated values, all of which can be passed as arguments. All
quantities can be initialised using \texttt{set\_quantity}. For
conserved quantities (\texttt{stage, xmomentum, ymomentum}) this is
called the \emph{initial condition}, for other quantities that aren't
updated by the equation, the same interface is used to assign their
values. The code in the present example demonstrates a number of forms
in which we can invoke \texttt{set\_quantity}.


\subsection{Elevation}

The elevation is set using a function, defined through the
statements below, which is specific to this example and specifies
a particularly simple initial configuration for demonstration
purposes:

{\small \begin{verbatim}
    def f(x,y):
        return -x/2
\end{verbatim}}

This simply associates an elevation with each point $(x, y)$ of
the plane.  It specifies that the bed slopes linearly in the $x$
direction, with slope $-\frac{1}{2}$,  and is constant in the $y$
direction.\\ %[screen shot?]
\\
Once the function $f$ is specified, the quantity
\texttt{elevation} is assigned through the simple statement:

{\small \begin{verbatim}
\begin{verbatim}
    domain.set_quantity('elevation', f)
\end{verbatim}}


\subsection{Friction}

The assignment of the friction quantity demonstrates another way
we can use \texttt{set\_quantity} to set quantities---namely,
assign them to a constant numerical value:

{\small \begin{verbatim}
    domain.set_quantity('friction', 0.1)
\end{verbatim}}

This just specifies that the Manning friction coefficient is set
to 0.1 at every mesh point.

\subsection{Depth}

Assigning depth illustrates a more complex way to use
\texttt{set\_quantity}, introducing an expression involving other
quantities:

{\small \begin{verbatim}
    h = 0.05 \# Constant depth
    domain.set_quantity('stage', expression = 'elevation + %f' %h)
\end{verbatim}}

Here the quantity \texttt{stage} is defined by taking the quantity
elevation already defined and adding a constant value $h = 0.05$
to it everywhere. This expresses the fact that the water depth is
everywhere constant, so the surface is a constant height above the
elevation of the bed.

\subsection{Boundary Conditions}

The boundary conditions are specified as follows:

{\small \begin{verbatim}
    Br = Reflective_boundary(domain)

    Bt = Transmissive_boundary(domain)

    Bd = Dirichlet_boundary([0.2,0.,0.])

    Bw = Time_boundary(domain=domain,
                f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0])
\end{verbatim}}

The effect of these statements is to set up four alternative
boundary conditions and store them in variables that can be
assigned as needed. Each boundary condition specifies the
behaviour at a boundary in terms of the behaviour in neighbouring
elements. The boundary conditions may be briefly described as
follows:

\begin{description}
    \item[Reflective boundary] Returns same \texttt{stage} as
    as present in its neighbour volume but momentum vector reversed 180 degrees (reflected).
    Specific to the shallow water equation as it works with the
    momentum quantities assumed to be the second and third conserved
    quantities.
    \item[Transmissive boundary]Returns same conserved quantities as
    those present in its neighbour volume.
    \item[Dirichlet boundary]Specifies a fixed value at the
boundary.
    \item[Time boundary.]A Dirichlet boundary whose behaviour varies with time.
\end{description}

Once the four boundary types have been specified through the
statements above, they can be applied through a statement of the
form

{\small \begin{verbatim}
    domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br})
\end{verbatim}}

This statement stipulates that, in the current example, the left
boundary is fixed, with an elevation of 0.2, while the other
boundaries are all reflective.


\section{Evolution}

The final statement \nopagebreak[3]
{\small \begin{verbatim}
    for t in domain.evolve(yieldstep = 0.1, finaltime = 4.0):
        domain.write_time()
\end{verbatim}}

is the key step that causes the configuration of the domain to
`evolve' in accordance with the model embodied in the code, over a
series of steps indicated by the values of \texttt{yieldstep} and
\texttt{finaltime}, which can be altered as required.
The yieldstep control the time interval between model output. Behind the scenes more timesteps are generally taken.




\section{Output}

%Give details here of the form of the output and explain how it can
%be used with swollen. Include screen shots.//

The output is a NetCDF file with the extension \texttt{.sww}. It
contains stage and momentum information and can be used with the
\texttt{swollen} visualisation package to generate a visual display.


\section{How to Run the Code}

The code can be run in various ways:

\begin{itemize}
\item{from a Windows command line} as in \texttt{python bedslope.py}

\item{within the Python IDLE environment}

\item{within emacs}

\item{from a Linux command line} as in \texttt{python bedslope.py}
\end{itemize}




\appendix
\chapter{Glossary}

\begin{description}

    \item[AnuGA] name of software (joint development between ANU and GA)
    
    \item[Conserved quantity]    

    \item[Default order] is this really needed?

    \item[Domain]

    \item[Dirichlet boundary]

    \item[Elevation] - refers to bathymetry and topography

    \item[bathymetry] offshore

    \item[topography] onshore

    \item[Evolution] integration of the shallow water wave equations over time

    \item[Forcing term]

    \item[IDLE] development environment shipped with Python

    \item[Manning friction coefficient]
    
    \item[Mesh]    triangulation of domain

    \item[Grid] evenly spaced

    \item[NetCDF]

    \item[pmesh] does this really need to be here? it's a class/module?

    \item[pyvolution] does this really need to be here? it's a class/module?

    \item[Quantity] conserved (state, x and y momentum)

    \item[Reflective boundary]

    \item[Smoothing] is this really needed?

    \item[Stage]

    \item[Swollen] visualisation tool

    \item[Time boundary] defined in the manual (flog from there)

    \item[Transmissive boundary] defined in the manual (flog from there)

    \item[xmomentum] conserved quantity (note, two-dimensional SWW equations say only x and y and NOT z)
    
    \item[ymomentum]  conserved quantity 

    \item[resolution]   refers to the maximal area of each triangular cell in the mesh

    \item[easting]   

    \item[northing]   

    \item[latitude]   

    \item[longitude]   

    \item[edge]   

    \item[vertex]  
 
    \item[finite volume]  

    \item[flux]  

    \item[Digital Elevation Model (DEM)]   


\end{description}

The \code{\e appendix} markup need not be repeated for additional
appendices.


%
%  The ugly "%begin{latexonly}" pseudo-environments are really just to
%  keep LaTeX2HTML quiet during the \renewcommand{} macros; they're
%  not really valuable.
%
%  If you don't want the Module Index, you can remove all of this up
%  until the second \input line.
%

%begin{latexonly}
%\renewcommand{\indexname}{Module Index}
%end{latexonly}
%\input{mod\jobname.ind}		% Module Index 

%begin{latexonly}
\renewcommand{\indexname}{Index}
%end{latexonly}
\input{\jobname.ind}			% Index



\end{document}
