source: documentation/user_manual/anuga_user_manual.tex @ 2893

Last change on this file since 2893 was 2893, checked in by ole, 18 years ago

Wrote more text to the first example

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 82.0 KB
Line 
1% Complete documentation on the extended LaTeX markup used for Python
2% documentation is available in ``Documenting Python'', which is part
3% of the standard documentation for Python.  It may be found online
4% at:
5%
6%     http://www.python.org/doc/current/doc/doc.html
7
8
9%labels
10%Sections and subsections \label{sec: }
11%Chapters \label{ch: }
12%Equations \label{eq: }
13%Figures \label{fig: }
14
15
16
17\documentclass{manual}
18
19\usepackage{graphicx}
20\usepackage{datetime}
21
22\input{definitions}
23
24\title{\anuga User Manual}
25\author{Geoscience Australia and the Australian National University}
26
27% Please at least include a long-lived email address;
28% the rest is at your discretion.
29\authoraddress{Geoscience Australia \\
30  Email: \email{ole.nielsen@ga.gov.au}
31}
32
33%Draft date
34
35% update before release!
36% Use an explicit date so that reformatting
37% doesn't cause a new date to be used.  Setting
38% the date to \today can be used during draft
39% stages to make it easier to handle versions.
40
41
42\longdate       % Make date format long using datetime.sty
43%\settimeformat{xxivtime} % 24 hour Format
44\settimeformat{oclock} % Verbose
45\date{\today, \ \currenttime}
46
47\ifhtml
48\date{\today} % latex2html does not know about datetime
49\fi
50
51
52
53
54
55\release{1.0}   % release version; this is used to define the
56                % \version macro
57
58\makeindex          % tell \index to actually write the .idx file
59\makemodindex       % If this contains a lot of module sections.
60
61\setcounter{tocdepth}{3}
62\setcounter{secnumdepth}{3}
63
64
65\begin{document}
66\maketitle
67
68
69% This makes the contents more accessible from the front page of the HTML.
70\ifhtml
71\chapter*{Front Matter\label{front}}
72\fi
73
74%Subversion keywords:
75%
76%$LastChangedDate: 2006-05-17 04:06:46 +0000 (Wed, 17 May 2006) $
77%$LastChangedRevision: 2893 $
78%$LastChangedBy: ole $
79
80\input{copyright}
81
82
83\begin{abstract}
84
85\noindent \anuga\index{\anuga} is a hydrodynamic modelling tool that
86allows users to model realistic flow problems in complex geometries.
87Examples include dam breaks or the effects of natural hazards such
88as riverine flooding, storm surges and tsunami.
89
90The user must specify a study area represented by a mesh of triangular
91cells, the topography and bathymetry, frictional resistance, initial
92values for water level (called \emph{stage}\index{stage} within \anuga),
93boundary
94conditions and forces such as windstress or pressure gradients if
95applicable.
96
97\anuga tracks the evolution of water depth and horizontal momentum
98within each cell over time by solving the shallow water wave equation
99governing equation using a finite-volume method.
100
101\anuga cannot model details of breaking waves, flow under ceilings such
102as pipes, turbulence and vortices, vertical convection or viscous
103flows.
104
105\anuga also incorporates a mesh generator, called \code{pmesh}, that
106allows the user to set up the geometry of the problem interactively as
107well as tools for interpolation and surface fitting, and a number of
108auxiliary tools for visualising and interrogating the model output.
109
110Most \anuga components are written in the object-oriented programming
111language Python and most users will interact with \anuga by writing
112small Python programs based on the \anuga library
113functions. Computationally intensive components are written for
114efficiency in C routines working directly with the Numerical Python
115structures.
116
117
118\end{abstract}
119
120\tableofcontents
121
122
123\chapter{Introduction}
124
125
126\section{Purpose}
127
128The purpose of this user manual is to introduce the new user to
129the software, describe what it can do and give step-by-step
130instructions for setting up and running hydrodynamic simulations.
131
132\section{Scope}
133
134This manual covers only what is needed to operate the software
135after installation and configuration. It does not includes instructions for
136installing the software or detailed API documentation, both of
137which will be covered in separate publications and by  documentation in the
138source code.
139
140\section{Audience}
141
142Readers are assumed to be familiar with the operating environment
143and have a general understanding of the problem background, as
144well as enough programming experience to adapt the code to
145different requirements, as described in this manual,  and to
146understand the basic terminology of object-oriented programming.
147
148\section{Structure of This Manual}
149
150FIXME (Ole): Isn't this superseded by the contents section?
151
152This manual is structured as follows:
153
154\begin{itemize}
155  \item Background (What \anuga does)
156  \item A \emph{Getting Started} section
157  \item A detailed description of the public interface
158  \item \anuga 's overall architecture, components and file formats
159  \item Assumptions
160\end{itemize}
161
162
163\pagebreak
164\chapter{Background}
165
166\chapter{Getting Started}
167\label{ch:getstarted}
168
169This section is designed to assist the reader to get started with
170\anuga by working through simple examples. Two examples are discussed;
171the first is a simple but artificial example that is useful to illustrate
172many of the ideas, and the second is a more realistic example.
173
174\section{A Simple Example}
175
176\subsection{Overview}
177
178What follows is a discussion of the structure and operation of a script which we will call \file{runup.py}, with just enough detail to allow
179the reader to appreciate what's involved in setting up a scenario
180like the one it depicts.
181
182This example carries out the solution of the shallow-water wave
183equation in the simple case of a configuration comprising a flat
184bed, sloping at a fixed angle in one direction and having a
185constant depth across each line in the perpendicular direction.
186
187The example demonstrates many of the basic ideas involved in
188setting up a more complex scenario. In the general case the user
189specifies the geometry (bathymetry and topography), the initial
190water level, boundary conditions such as tide, and any forcing
191terms that may drive the system such as wind stress or atmospheric
192pressure gradients. Frictional resistance from the different
193terrains in the model is represented by predefined forcing
194terms. The boundary is reflective on three sides and a time dependent wave on one side.
195
196The present example represents a simple scenario and does not
197include any forcing terms, nor is the data taken from a file as it
198would be in many typical cases.
199
200The conserved quantities involved in the
201problem are stage (absolute height of water surface),
202$x$-momentum and $y$-momentum. Other quantities
203involved in the computation are the friction and elevation.
204
205Water depth can be obtained through the equation
206
207\begin{tabular}{rcrcl}
208  \code{depth} &=& \code{stage} &-& \code{elevation}
209\end{tabular}
210
211
212%\emph{[More details of the problem background]}
213
214\subsection{Outline of the Program}
215
216In outline, \file{runup.py} performs the following steps:
217
218\begin{enumerate}
219
220   \item Sets up a triangular mesh.
221
222   \item Sets certain parameters governing the mode of
223operation of the model-specifying, for instance, where to store the model output.
224
225   \item Inputs various quantities describing physical measurements, such
226as the elevation, to be specified at each mesh point (vertex).
227
228   \item Sets up the boundary conditions.
229
230   \item Carries out the evolution of the model through a series of time
231steps and outputs the results, providing a results file that can
232be visualised.
233
234\end{enumerate}
235
236\subsection{The Code}
237
238%FIXME: we are using the \code function here.
239%This should be used wherever possible
240For reference we include below the complete code listing for
241\file{runup.py}. Subsequent paragraphs provide a
242`commentary' that describes each step of the program and explains it
243significance.
244
245\verbatiminput{examples/runup.py}
246%\verbatiminput{examples/bedslope.py}
247
248\subsection{Establishing the Mesh}
249
250The first task is to set up the triangular mesh to be used for the
251scenario. This is carried out through the statement:
252
253{\small \begin{verbatim}
254    points, vertices, boundary = rectangular(10, 10)
255\end{verbatim}}
256
257The function \function{rectangular} is imported from a module
258\module{mesh\_factory} defined elsewhere. (\anuga also contains
259several other schemes that can be used for setting up meshes, but we
260shall not discuss these now.) The above assignment sets up a $10
261\times 10$ rectangular mesh, triangulated in a specific way. In
262general, the assignment
263
264{\small \begin{verbatim}
265    points, vertices, boundary = rectangular(m, n)
266\end{verbatim}}
267
268returns:
269
270\begin{itemize}
271
272   \item a list \code{points} of length $N$, where $N = (m + 1)(n + 1)$,
273comprising the coordinates \code{(x, y)} of each of the $N$ mesh
274points,
275
276   \item a list \code{vertices} of length $2mn$ (each entry specifies the three
277vertices of one of the triangles used in the triangulation) , and
278
279   \item a dictionary \code{boundary}, used to tag the triangle edges on
280the boundaries. Each key corresponds to a triangle edge on one of
281the four boundaries and its value is one of \code{`left'},
282\code{`right'}, \code{`top'} and \code{`bottom'}, indicating
283which boundary the edge in question belongs to.
284
285\end{itemize}
286
287Since these three variables encapsulate the information needed to
288specify the grid, it may be helpful to consider how they look in a
289very simple case, not directly related to the example at hand.
290Figure \ref{fig:simplemesh} represents a very simple mesh comprising
291just 11 points and three triangles. (To avoid confusion, we should
292emphasise that this particular mesh is \emph{not} generated by
293\code{rectangular}---and is not even rectangular in nature. )
294
295
296\begin{figure}[h]
297  \begin{center}
298    \includegraphics[width=90mm, height=90mm]{triangularmesh.eps}
299  \end{center}
300 
301  \caption{A simple mesh}
302  \label{fig:simplemesh}
303\end{figure}
304
305
306The variables \code{points}, \code{vertices} and \code{boundary}
307represent the data displayed in Figure \ref{fig:simplemesh} as
308follows. The list \code{points} stores the coordinates of the
309points, and may be displayed schematically as in Table \ref{tab:points}.
310
311
312\begin{table}
313  \begin{center}
314    \begin{tabular}[t]{|c|cc|} \hline
315      index & \code{x} & \code{y}\\  \hline
316      0 & 1 & 1\\
317      1 & 4 & 2\\
318      2 & 8 & 1\\
319      3 & 1 & 3\\
320      4 & 5 & 5\\
321      5 & 8 & 6\\
322      6 & 11 & 5\\
323      7 & 3 & 6\\
324      8 & 1 & 8\\
325      9 & 4 & 9\\
326      10 & 10 & 7\\  \hline
327    \end{tabular}
328  \end{center}
329 
330  \caption{Point coordinates for mesh in
331    Figure \protect \ref{fig:simplemesh}}
332  \label{tab:points} 
333\end{table} 
334
335The list \code{vertices} specifies the triangles that make up the
336mesh. It does this by specifying, for each triangle, the indices
337(the numbers shown in the first column above) that correspond to the
338three points at its vertices, taken in an anti-clockwise order
339around the triangle. Thus, in the example shown in Figure
340\ref{fig:simplemesh}, the variable \code{vertices} contains the
341entries shown in Table \ref{tab:vertices}. The starting point is arbitrary so triangle $(0,1,3)$ is considered the same as $(1,3,0)$ and $(3,0,1)$.
342
343
344\begin{table}
345  \begin{center}
346    \begin{tabular}{|c|ccc|} \hline
347      index & \multicolumn{3}{c|}{\code{vertices}}\\ \hline
348      0 & 0 & 1 & 3\\
349      1 & 1 & 2 & 4\\
350      2 & 2 & 5 & 4\\
351      3 & 2 & 6 & 5\\
352      4 & 4 & 5 & 9\\
353      5 & 4 & 9 & 7\\
354      6 & 3 & 4 & 7\\
355      7 & 7 & 9 & 8\\
356      8 & 1 & 4 & 3\\
357      9 & 5 & 10 & 9\\  \hline
358    \end{tabular}
359  \end{center}
360 
361  \caption{Vertices for mesh in
362    Figure \protect \ref{fig:simplemesh}}
363  \label{tab:vertices}   
364\end{table}   
365
366Finally, the variable \code{boundary} identifies the boundary
367triangles and associates a tag with each.
368
369
370
371
372\subsection{Initialising the Domain}
373
374These variables are then used to set up a data structure
375\code{domain}, through the assignment:
376
377{\small \begin{verbatim}
378    domain = Domain(points, vertices, boundary)
379\end{verbatim}}
380
381This uses a Python class \class{Domain}, imported from
382\module{shallow\_water}, which is an extension of a more generic
383class of the same name in the module \refmodule{pyvolution.domain}
384(page \pageref{mod:pyvolution.domain}),
385and inherits
386some methods from the generic class but has others specific to the
387shallow-water scenarios in which it is used. Specific options for
388domain are set at this point. One of them is to set the basename for
389the output file:
390
391{\small \begin{verbatim}
392    domain.set_name('bedslope')
393\end{verbatim}}
394
395
396\subsection{Initial Conditions}
397
398The next task is to specify a number of quantities that we wish to
399set for each mesh point. The class \class{Domain} has a method
400\method{set\_quantity}, used to specify these quantities. It is a
401particularly flexible method that allows the user to set quantities
402in a variety of ways---using constants, functions, numeric arrays or
403expressions involving other quantities, arbitrary data points with
404associated values, all of which can be passed as arguments. All
405quantities can be initialised using \method{set\_quantity}. For
406conserved quantities (\code{stage, xmomentum, ymomentum}) this is
407called the \emph{initial condition}, for other quantities that
408aren't updated by the equation, the same interface is used to assign
409their values. The code in the present example demonstrates a number
410of forms in which we can invoke \method{set\_quantity}.
411
412
413\subsubsection{Elevation}
414
415The elevation, or height of the bed, is set using a function,
416defined through the statements below, which is specific to this
417example and specifies a particularly simple initial configuration
418for demonstration purposes:
419
420{\small \begin{verbatim}
421    def f(x,y):
422        return -x/2
423\end{verbatim}}
424
425This simply associates an elevation with each point \code{(x, y)} of
426the plane.  It specifies that the bed slopes linearly in the
427\code{x} direction, with slope $-\frac{1}{2}$,  and is constant in
428the \code{y} direction.  %[screen shot?]
429
430Once the function \function{f} is specified, the quantity
431\code{elevation} is assigned through the simple statement:
432
433{\small \begin{verbatim}
434    domain.set_quantity('elevation', f)
435\end{verbatim}}
436
437
438\subsubsection{Friction}
439
440The assignment of the friction quantity demonstrates another way we
441can use \method{set\_quantity} to set quantities---namely, assign
442them to a constant numerical value:
443
444{\small \begin{verbatim}
445    domain.set_quantity('friction', 0.1)
446\end{verbatim}}
447
448This just specifies that the Manning friction coefficient is set
449to 0.1 at every mesh point.
450
451\subsubsection{Stage}
452
453The stage (the height of the water surface) is related to the
454elevation and the depth at any time by the equation
455
456
457{\small \begin{verbatim}
458    stage = elevation + depth
459\end{verbatim}}
460
461
462For this example, we simply assign a constant value to \code{stage},
463using the statement
464
465{\small \begin{verbatim}
466    domain.set_quantity('stage', -.4)
467\end{verbatim}}
468
469which specifies that the surface level is set to a height of $-0.4$, i.e. 0.4 units
470below the zero level.
471
472(Although it is not necessary for this example, it may be useful to
473digress here and mention a variant to this requirement, which allows
474us to illustrate another way to use \method{set\_quantity}---namely,
475incorporating an expression involving other quantities. Suppose,
476instead of setting a constant value for the stage, we wished to
477specify a constant value for the \emph{depth}. For such a case we
478need to specify that \code{stage} is everywhere obtained by adding
479that value to the value already specified for \code{elevation}. We
480would do this by means of the statements:
481
482{\small \begin{verbatim}
483    h = 0.05 # Constant depth
484    domain.set_quantity('stage', expression = 'elevation + %f' %h)
485\end{verbatim}}
486
487That is, the value of \code{stage} is set to $\code{h} = 0.05$ plus
488the value of \code{elevation} already defined.
489
490The reader will probably appreciate that this capability to
491incorporate expressions into statements using \method{set\_quantity}
492greatly expands its power.)
493
494\subsection{Boundary Conditions}
495
496The boundary conditions are specified as follows:
497
498{\small \begin{verbatim}
499    Br = Reflective_boundary(domain)
500
501    Bt = Transmissive_boundary(domain)
502
503    Bd = Dirichlet_boundary([0.2,0.,0.])
504
505    Bw = Time_boundary(domain=domain,
506                f=lambda t: [(0.1*sin(t*2*pi)-0.3), 0.0, 0.0])
507\end{verbatim}}
508
509The effect of these statements is to set up a selection of different
510alternative boundary conditions and store them in variables that can be
511assigned as needed. Each boundary condition specifies the
512behaviour at a boundary in terms of the behaviour in neighbouring
513elements. The boundary conditions introduced here may be briefly described as
514follows:
515
516\begin{itemize} 
517    \item \textbf{Reflective boundary} Returns same \code{stage} as
518      as present in its neighbour volume but momentum vector
519      reversed 180 degrees (reflected).
520      Specific to the shallow water equation as it works with the
521      momentum quantities assumed to be the second and third conserved
522      quantities. A reflective boundary condition models a solid wall.
523    \item \textbf{Transmissive boundary} Returns same conserved quantities as
524      those present in its neighbour volume. This is one way of modelling
525      outflow from a domain, but it should be used with caution if flow is
526      not steady state as replication of momentum at the boundary
527      may cause occasional spurious effects. If this occurs,
528      consider using e.g. a Dirichlet boundary condition.
529    \item \textbf{[Dirichlet boundary} Specifies a fixed value at the
530      boundary and assigns initial values to the $x$-momentum and $y$-momentum.
531    \item \textbf {Time boundary} Like a Dirichlet boundary but with behaviour
532      varying with time.
533\end{itemize}
534
535Once the boundary objects have been specified through the
536statements above, they can be applied through a statement of the
537form
538
539{\small \begin{verbatim}
540    domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br})
541\end{verbatim}}
542
543This statement stipulates that, in the current example, the right
544boundary varies with time, as defined by the lambda function, while the other
545boundaries are all reflective.
546
547The reader may wish to experiment by varying the choice of boundary
548types for one or more of the boundaries. In the case of \code{Bd}
549and \code{Bw}, the three arguments in each case represent the
550\code{stage}, $x$-momentum and $y$-momentum, respectively.
551
552{\small \begin{verbatim}
553    Bw = Time_boundary(domain=domain,
554                       f=lambda t: [(0.1*sin(t*2*pi)-0.3), 0.0, 0.0])
555\end{verbatim}}
556
557
558
559\subsection{Evolution}
560
561The final statement \nopagebreak[3]
562{\small \begin{verbatim}
563    for t in domain.evolve(yieldstep = 0.1, duration = 4.0):
564        print domain.timestepping_statistics()
565\end{verbatim}}
566
567is the key step that causes the configuration of the domain to
568`evolve' in accordance with the model embodied in the code, over a
569series of steps indicated by the values of \code{yieldstep} and
570\code{duration}, which can be altered as required.  The value of
571\code{yieldstep} controls the time interval between successive model
572outputs.  Behind the scenes more time steps are generally taken.
573
574
575\subsection{Output}
576
577%Give details here of the form of the output and explain how it can
578%be used with swollen. Include screen shots.//
579
580The output is a NetCDF file with the extension \code{.sww}. It
581contains stage and momentum information and can be used with the
582\code{swollen} visualisation package to generate a visual display.
583See Section \ref{sec:file formats} (page \pageref{sec:file formats})
584for more on NetCDF and other file formats.
585
586
587\section{How to Run the Code}
588
589The code can be run in various ways:
590
591\begin{itemize}
592  \item{from a Windows command line} as in \code{python runup.py}
593  \item{within the Python IDLE environment}
594  \item{within emacs}
595  \item{from a Linux command line} as in \code{python runup.py}
596\end{itemize}
597
598
599\section{Exploring the model output}
600
601Figure \ref{fig:runupstart} shows the domain with water surface as
602specified by the initial condition, $t=0$. Figure \ref{fig:bedslope2}
603shows later snapshots for $t=2.3$ and $t=4$ where the system has been
604evolved and the wave encroaching on the previously dry bed.  All
605figures are screenshots from an interactive animation tool called
606Swollen which is part of ANUGA. Swollen is described in more detail is
607Section \ref{sec:swollen}.
608 
609
610
611\begin{figure}[hbt]
612
613  \centerline{\includegraphics[width=75mm, height=75mm]
614    {examples/runupstart.eps}}
615
616  \caption{Bedslope example viewed with Swollen}
617  \label{fig:runupstart}
618\end{figure}
619
620
621\begin{figure}[hbt]
622
623  \centerline{
624    \includegraphics[width=75mm, height=75mm]{examples/runupduring.eps}
625    \includegraphics[width=75mm, height=75mm]{examples/runupend.eps}
626   }
627
628  \caption{Bedslope example viewed with Swollen}
629  \label{fig:bedslope2}
630\end{figure}
631
632
633
634
635\clearpage
636
637%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
638
639\section{An Example with Real Data}
640
641The following discussion builds on the concepts introduced through
642the \file{runup.py} example and introduces a second
643example, \file{run\_sydney\_smf.py}, that follows the same basic
644outline, but incorporates more complex features and refers to a
645real-life scenario, rather than the artificial illustrative one used
646in \file{runup.py}. The domain of interest surrounds the
647Sydney region, and predominantly covers Sydney Harbour. A
648hypothetical tsunami wave is generated by a submarine mass failure
649situated on the edge of the continental shelf.
650
651\subsection{Overview}
652As in the case of \file{runup.py}, the actions carried
653out by the program can be organised according to this outline:
654
655\begin{enumerate}
656
657   \item Set up a triangular mesh.
658
659   \item Set certain parameters governing the mode of
660operation of the model---specifying, for instance, where to store the
661model output.
662
663   \item Input various quantities describing physical measurements, such
664as the elevation, to be specified at each mesh point (vertex).
665
666   \item Set up the boundary conditions.
667
668   \item Carry out the evolution of the model through a series of time
669steps and outputs the results, providing a results file that can be
670visualised.
671
672\end{enumerate}
673
674
675
676\subsection{The Code}
677
678Here is the code for \file{run\_sydney\_smf.py}:
679
680%\verbatiminput{"runsydneysmf.py"}
681\verbatiminput{examples/runsydney.py}
682
683In discussing the details of this example, we follow the outline
684given above, discussing each major step of the code in turn.
685
686\subsection{Establishing the Mesh}
687
688One obvious way that the present example differs from
689\file{runup.py} is in the use of a more complex method to
690create the mesh. Instead of imposing a mesh structure on a
691rectangular grid, the technique used for this example involves
692building mesh structures inside polygons specified by the user,
693using a mesh-generator referred to as \code{pmesh}.
694
695The following remarks may help the reader understand how
696\code{pmesh} is used.
697
698In its simplest form, \code{pmesh} creates the mesh within a single
699polygon whose vertices are at geographical locations specified by the
700user. The user specifies the \emph{resolution}---that is, the maximal
701area of a triangle used for triangulation---and mesh points are
702created inside the polygon through a random process. Figure
703\ref{fig:pentagon} shows a simple example of this, in which
704the triangulation is carried out within a pentagon.
705
706
707\begin{figure}[hbt]
708
709
710
711  \caption{Mesh points are created inside the polygon}
712  \label{fig:pentagon}
713\end{figure}
714
715Boundary tags are not restricted to \code{`left'}, \code{`right'},
716\code{`bottom'} and \code{`top'}, as in the case of
717\file{runup.py}. Instead the user specifies a list of
718tags appropriate to the configuration being modelled.
719
720While a mesh created inside a polygon offers more flexibility than
721one based on a rectangular grid, using \code{pmesh} in the limited
722form we have described so far still doesn't provide a way to adapt
723to geographic or other features in the landscape, whose presence may
724require us to vary the resolution in the neighbourhood of the
725features. To cope with this requirement, \code{pmesh} also allows
726the user to specify a number of \emph{interior polygons}, which are
727triangulated separately, each according to a separately specified
728resolution. See Figure \ref{fig:interior meshes}.
729
730\begin{figure}[hbt]
731
732
733
734  \caption{Interior meshes with individual resolution}
735  \label{fig:interior meshes}
736\end{figure}
737
738In its general form, \code{pmesh} takes for its input a bounding
739polygon and (optionally) a list of interior polygons. The user
740specifies resolutions, both for the bounding polygon and for each of
741the interior polygons. Given this data, \code{pmesh} first creates a
742triangular mesh inside the bounding polygon, using the specified
743resolution, and then creates a separate triangulation inside each of
744the interior polygons, using the resolution specified for that
745polygon.
746
747The function used to implement this process is
748\function{create\_mesh\_from\_regions}. Its arguments include the
749bounding polygon and its resolution, a list of boundary tags, and a
750list of pairs \code{[polygon, resolution]}, specifying the interior
751polygons and their resolutions.
752
753In practice, the details of the polygons used are read from a
754separate file \file{project.py}. The resulting mesh is output to a
755\emph{meshfile}\index{meshfile}. This term is used to describe a
756file of a specific format used to store the data specifying a mesh.
757(There are in fact two possible formats for such a file: it can
758either be a binary file, with extension \code{.msh}, or an ASCII
759file, with extension \code{.tsh}. In the present case, the binary
760file format \code{.msh} is used. See Section \ref{sec:file formats}
761(page \pageref{sec:file formats}) for more on file formats.)
762\code{pmesh} assigns a name to the file by appending the extension
763\code{.msh} to the name specified in the input file
764\file{project.py}. This name is stored in the variable
765\code{meshname}.
766
767The statements
768
769{\small \begin{verbatim}
770    interior_res = 5000%
771    interior_regions = [[project.harbour_polygon_2, interior_res],
772                    [project.botanybay_polygon_2, interior_res]]
773\end{verbatim}}
774
775are used to read in the specific polygons \code{project.harbour\_polygon\_2} and
776\code{botanybay\_polygon\_2} from \file{project.py} and assign a
777common resolution of 5000 to each. The statement
778
779{\small \begin{verbatim}
780    create_mesh_from_regions(project.diffpolygonall,%
781                         boundary_tags= {'bottom': [0],%
782                                         'right1': [1],%
783                                         'right0': [2],%
784                                         'right2': [3],%
785                                         'top': [4],%
786                                         'left1': [5],%
787                                         'left2': [6],%
788                                         'left3': [7]},%
789                         maximum_triangle_area=100000,%
790                         filename=meshname,%
791                         interior_regions=interior_regions)
792\end{verbatim}}
793
794is then used to create the mesh, taking the bounding polygon to be the polygon
795\code{diffpolygonall} specified in \file{project.py}. The
796argument \code{boundary\_tags} assigns a dictionary, whose keys are the
797names of the boundary tags used for the bounding polygon---\code{`bottom'},
798`right0', `right1', `right2', `top', `left1', `left2' and `left3'---
799and whose values identify the indices of the segments associated with each of these
800tags. (The value associated with each boundary tag is a one-element list.)
801
802
803\subsection{Initialising the Domain}
804
805As with \file{runup.py}, once we have created the mesh, the next
806step is to create the data structure \code{domain}. We did this for
807\file{runup.py} by inputting lists of points and triangles and
808specifying the boundary tags directly. However, in the present case,
809we use a method that works directly with the meshfile
810\code{meshname}, as follows:
811
812
813{\small \begin{verbatim}
814    domain = Domain(meshname, use_cache=True, verbose=True)
815\end{verbatim}}
816
817Providing a filename instead of the lists used in bedslopephysical
818above causes Domain to convert a meshfile
819\code{meshname} into an instance of the data structure
820\code{domain}, allowing us to use methods like \method{set\_quantity}
821to set quantities and to apply other operations.
822
823%(In principle, the
824%second argument of \function{pmesh\_to\_domain\_instance} can be any
825%subclass of \class{Domain}, but for applications involving the
826%shallow-water wave equation, the second argument of
827%\function{pmesh\_to\_domain\_instance} can always be set simply to
828%\class{Domain}.)
829
830The following statements specify a basename and data directory, and
831identify quantities to be stored. For the first two, values are
832taken from \file{project.py}.
833
834{\small \begin{verbatim}
835    domain.set_name(project.basename)%
836    domain.set_datadir(project.outputdir)%
837    domain.set_quantities_to_be_stored(['stage', 'xmomentum',
838        'ymomentum'])
839\end{verbatim}}
840
841
842\subsection{Initial Conditions}
843Quantities for \file{runsydney.py} are set
844using similar methods to those in \file{runup.py}. However,
845in this case, many of the values are read from the auxiliary file
846\file{project.py} or, in the case of \code{elevation}, from an
847ancillary points file.
848
849
850
851\subsubsection{Stage}
852
853For the scenario we are modelling in this case, we use a callable
854object \code{tsunami\_source}, assigned by means of a function
855\function{slump\_tsunami}. This is similar to how we set elevation in
856\file{runup.py} using a function---however, in this case the
857function is both more complex and more interesting.
858
859The function returns the water displacement for all \code{x} and
860\code{y} in the domain. The water displacement is a double Gaussian
861function that depends on the characteristics of the slump (length,
862thickness, slope, etc), its location (origin) and the depth at that
863location.
864
865
866\subsubsection{Friction}
867
868We assign the friction exactly as we did for \file{runup.py}:
869
870{\small \begin{verbatim}
871    domain.set_quantity('friction', 0.03)
872\end{verbatim}}
873
874
875\subsubsection{Elevation}
876
877The elevation is specified by reading data from a file:
878
879{\small \begin{verbatim}
880    domain.set_quantity('elevation',
881                        filename = project.combineddemname + '.pts',
882                        use_cache = True,
883                        verbose = True)
884\end{verbatim}}
885
886However, before this step can be executed, some preliminary steps
887are needed to prepare the file from which the data is taken. Two
888source files are used for this data---their names are specified in
889the file \file{project.py}, in the variables \code{coarsedemname}
890and \code{finedemname}. They contain `coarse' and `fine' data,
891respectively---that is, data sampled at widely spaced points over a
892large region and data sampled at closely spaced points over a
893smaller subregion. The data in these files is combined through the
894statement
895
896{\small \begin{verbatim}
897combine_rectangular_points_files(project.finedemname + '.pts',
898                                 project.coarsedemname + '.pts',
899                                 project.combineddemname + '.pts')
900\end{verbatim}}
901
902The effect of this is simply to combine the datasets by eliminating
903any coarse data associated with points inside the smaller region
904common to both datasets. The name to be assigned to the resulting
905dataset is also derived from the name stored in the variable
906\code{combinedname} in the file \file{project.py}.
907
908\subsection{Boundary Conditions}
909
910Setting boundaries follows a similar pattern to the one used for
911\file{runup.py}, except that in this case we need to associate a
912boundary type with each of the
913boundary tag names introduced when we established the mesh. In place of the four
914boundary types introduced for \file{runup.py}, we use the reflective
915boundary for each of the
916eight tagged segments:
917
918{\small \begin{verbatim}
919    Br = Reflective_boundary(domain)
920    domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br,
921                          'right2': Br, 'top': Br, 'left1': Br,
922                          'left2': Br, 'left3': Br} )
923\end{verbatim}}
924
925\subsection{Evolution}
926
927With the basics established, the running of the `evolve' step is
928very similar to the corresponding step in \file{runup.py}:
929
930{\small \begin{verbatim}
931    import time t0 = time.time()
932
933    for t in domain.evolve(yieldstep = 120, duration = 18000):
934        print domain.timestepping_statistics()
935        print domain.boundary_statistics(tags = 'bottom')
936
937    print 'That took %.2f seconds' %(time.time()
938\end{verbatim}}
939
940%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
941%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
942
943\chapter{\anuga Public Interface}
944\label{ch:interface}
945
946This chapter gives an overview of the features of \anuga available
947to the user at the public interface. These are grouped under the
948following headings:
949
950\begin{itemize}
951    \item Establishing the Mesh
952    \item Initialising the Domain
953    \item Specifying the Quantities
954    \item Initial Conditions
955    \item Boundary Conditions
956    \item Forcing Functions
957    \item Evolution
958\end{itemize}
959
960The listings are intended merely to give the reader an idea of what
961each feature is, where to find it and how it can be used---they do
962not give full specifications. For these the reader
963may consult the code. The code for every function or class contains
964a documentation string, or `docstring', that specifies the precise
965syntax for its use. This appears immediately after the line
966introducing the code, between two sets of triple quotes.
967
968Each listing also describes the location of the module in which
969the code for the feature being described can be found. All modules
970are in the folder \file{inundation} or one of its subfolders, and the
971location of each module is described relative to \file{inundation}. Rather
972than using pathnames, whose syntax depends on the operating system,
973we use the format adopted for importing the function or class for
974use in Python code. For example, suppose we wish to specify that the
975function \function{create\_mesh\_from\_regions} is in a module called
976\module{mesh\_interface} in a subfolder of \module{inundation} called
977\code{pmesh}. In Linux or Unix syntax, the pathname of the file
978containing the function, relative to \file{inundation}, would be
979
980\begin{center}
981%    \code{pmesh/mesh\_interface.py}
982    \code{pmesh}$\slash$\code{mesh\_interface.py}
983\end{center}
984
985while in Windows syntax it would be
986
987\begin{center}
988    \code{pmesh}$\backslash$\code{mesh\_interface.py}
989\end{center}
990
991Rather than using either of these forms, in this chapter we specify
992the location simply as \code{pmesh.mesh_interface}, in keeping with
993the usage in the Python statement for importing the function,
994namely:
995\begin{center}
996    \code{from pmesh.mesh\_interface import create\_mesh\_from\_regions}
997\end{center}
998
999Each listing details the full set of parameters for the class or
1000function; however, the description is generally limited to the most
1001important parameters and the reader is again referred to the code
1002for more details.
1003
1004The following parameters are common to many functions and classes
1005and are omitted from the descriptions given below:
1006
1007%\begin{center}
1008\begin{tabular}{ll}  %\hline
1009%\textbf{Name } & \textbf{Description}\\
1010%\hline
1011\emph{usecache} & Specifies whether caching is to be used\\
1012\emph{verbose} & If \code{True}, provides detailed terminal output
1013to the user\\  % \hline
1014\end{tabular}
1015%\end{center}
1016
1017\section{Mesh Generation}
1018\refmodindex[pmesh.meshinterface]{pmesh.mesh\_interface}
1019\begin{funcdesc}  {create\_mesh\_from\_regions}{bounding_polygon,
1020                             boundary_tags,
1021                             maximum_triangle_area,
1022                             filename=None,
1023                             interior_regions=None,
1024                             poly_geo_reference=None,
1025                             mesh_geo_reference=None,
1026                             minimum_triangle_angle=28.0}
1027Module: \module{pmesh.mesh\_interface}
1028
1029This function allows a user to initiate the automatic creation of a
1030mesh inside a specified polygon. Among the parameters that can be
1031set are the \emph{resolution} (maximal area for any triangle in the
1032mesh) and the minimal angle allowable in any triangle. The user can
1033specify a number of internal polygons within each of which a
1034separate mesh is to be created, generally with a smaller resolution.
1035Additionally, the user specifies a list of boundary tags, one for
1036each edge of the bounding polygon.
1037\end{funcdesc}
1038
1039
1040\begin{funcdesc}  {Mesh}{userSegments=None,
1041                 userVertices=None,
1042                 holes=None,
1043                 regions=None,
1044                 geo_reference=None}
1045Module: \module{pmesh.mesh}
1046
1047% Translate following into layman's language
1048An instance of the class \class{Mesh} is used to store .  This can
1049then be used to build the outline of the mesh and then generate the
1050mesh.
1051\end{funcdesc}
1052
1053
1054\begin{funcdesc}  {add_region_from_polygon}{self, polygon, tags=None,
1055                                max_triangle_area=None, geo_reference=None}
1056Module: \module{pmesh.mesh.Mesh}
1057
1058% Translate following into layman's language
1059This method is used to add a region to a \class{Mesh} instance.  The
1060region is described by the polygon passed in.  Additionally, the
1061user specifies a list of boundary tags, one for each edge of the
1062bounding polygon.
1063
1064
1065\end{funcdesc}
1066
1067\begin{funcdesc}  {add_hole_from_polygon}{self, polygon, tags=None,
1068    geo_reference=None}
1069Module: \module{pmesh.mesh.Mesh}
1070
1071% Translate following into layman's language
1072This method is used to add a `hole'---that is, a region where the
1073triangular mesh will not be generated---to a \class{Mesh} instance.
1074The region is described by the polygon passed in.  Additionally, the
1075user specifies a list of boundary tags, one for each edge of the
1076bounding polygon.
1077\end{funcdesc}
1078
1079\begin{funcdesc}  {generate_mesh}{self,
1080                      maximum_triangle_area=None,
1081                      minimum_triangle_angle=28.0,
1082                      verbose=False}
1083Module: \module{pmesh.mesh.Mesh}
1084
1085% Translate following into layman's language
1086This method is used to generate the triangular mesh.  The  maximal area
1087of any triangle in the mesh can be specified, along with the minimum
1088angle of all triangles.
1089\end{funcdesc}
1090
1091
1092\begin{funcdesc}  {export_mesh_file}{self,ofile}
1093Module: \module{pmesh.mesh.Mesh}
1094
1095% Translate following into layman's language
1096This method is used to save the mesh to a file. \code{ofile} is the name of the mesh file to be writen,
1097including the extension.  Use the extension \code{.msh} for the file to
1098be in NetCDF format and \code{.tsh} for the file to be ASCII format.
1099\end{funcdesc}
1100
1101%%%%%%
1102\section{Initialising Domain}
1103
1104\begin{funcdesc}  {pmesh\_to\_domain\_instance}{file_name, DomainClass, use_cache = False, verbose = False}
1105Module: \module{pyvolution.pmesh2domain}
1106
1107Once the initial mesh file has been created, this function is
1108applied to convert it to a domain object---that is, to a member of
1109the special Python class \class{Domain} (or a subclass of
1110\class{Domain}), which provides access to properties and methods
1111that allow quantities to be set and other operations to be carried
1112out.
1113
1114\code{file\_name} is the name of the mesh file to be converted,
1115including the extension. \code{DomainClass} is the class to be
1116returned, which must be a subclass of \class{Domain} having the same
1117interface as \class{Domain}---in practice, it can usually be set
1118simply to \class{Domain}.
1119
1120This is now superseded by Domain(mesh_filename).
1121\end{funcdesc}
1122
1123
1124\subsection{Key Methods of Domain}
1125
1126\begin{funcdesc} {set\_name}{name}
1127    Module: \refmodule{pyvolution.domain}, page \pageref{mod:pyvolution.domain}  %\code{pyvolution.domain}
1128
1129    Assigns the name \code{name} to the domain.
1130\end{funcdesc}
1131
1132\begin{funcdesc} {get\_name}{}
1133    Module: \module{pyvolution.domain}
1134
1135    Returns the name assigned to the domain by \code{set_name}. If no name has been
1136    assigned, returns \code{`domain'}.
1137\end{funcdesc}
1138
1139\begin{funcdesc} {set\_datadir}{name}
1140    Module: \module{pyvolution.domain}
1141
1142    Specifies the directory used for data, assigning it to the pathname \code{name}. The default value, before
1143    \code{set\_datadir} has been run, is the value \code{default_datadir}
1144    specified in \code{config.py}.
1145
1146    Since different operating systems use different formats for specifying pathnames,
1147    it is necessary to specify path separators using the Python code \code{os.sep}, rather than
1148    the operating-specific ones such as `$\slash$' or `$\backslash$'.
1149    For this to work you will need to include the statement \code{import os}
1150    in your code, before the first appearance of \code{set\_datadir}.
1151
1152    For example, to set the data directory to a subdirectory
1153    \code{data} of the directory \code{project}, you could use
1154    the statements:
1155
1156    {\small \begin{verbatim}
1157        import os
1158        domain.set_datadir{'project' + os.sep + 'data'}
1159    \end{verbatim}}
1160\end{funcdesc}
1161
1162\begin{funcdesc} {get_datadir}{}
1163    Module: \module{pyvolution.domain}
1164
1165    Returns the data directory set by \code{set\_datadir} or, if \code{set\_datadir} has not
1166    been run, returns the value \code{default_datadir} specified in
1167    \code{config.py}.
1168\end{funcdesc}
1169
1170\begin{funcdesc} {set_time}{time=0.0}
1171    Module: \module{pyvolution.domain}
1172
1173    Sets the initial time, in seconds, for the simulation. The
1174    default is 0.0.
1175\end{funcdesc}
1176
1177\begin{funcdesc} {set_default_order}{??}
1178\end{funcdesc}
1179
1180
1181%%%%%%
1182\section{Initial Conditions}
1183
1184\begin{funcdesc}{set\_quantity}{name,
1185    numeric = None,
1186    quantity = None,
1187    function = None,
1188    geospatial_data = None,
1189    filename = None,
1190    attribute_name = None,
1191    alpha = None,
1192    location = 'vertices',
1193    indices = None,
1194    verbose = False,
1195    use_cache = False}
1196  Module: \module{pyvolution.domain}
1197  (see also \module{pyvolution.quantity.set_values})
1198
1199This function is used to assign values to individual quantities for a
1200domain. It is very flexible and can be used with many data types: a
1201statement of the form \code{domain.set\_quantity(name, x)} can be used
1202to define a quantity having the name \code{name}, where the other
1203argument \code{x} can be any of the following:
1204
1205\begin{itemize}
1206\item a number, in which case all vertices in the mesh gets that for
1207the quantity in question.
1208\item a list of numbers or a Numeric array ordered the same way as the mesh vertices.
1209\item a function (e.g.\ see the samples introduced in Chapter 2)
1210\item an expression composed of other quantities and numbers, arrays, lists (for
1211example, a linear combination of quantities)
1212\item the name of a file from which the data can be read. In this case, the optional argument attribute_name will select which attribute to use from the file. If left out, set_quantity will pick one. This is useful in cases where there is only one attribute.
1213\item a geospatial dataset (See ?????). Optional argument attribute_name applies here as with files.
1214\end{itemize}
1215
1216
1217Exactly one of the arguments
1218  numeric, quantity, function, points, filename
1219must be present.
1220
1221
1222Set quantity will look at the type of the second argument (\code{numeric}) and
1223determine what action to take.
1224
1225Values can also be set using the appropriate keyword arguments.
1226If x is a function, for example, \code{domain.set\_quantity(name, x)}, \code{domain.set\_quantity(name, numeric=x)}, and \code{domain.set\_quantity(name, function=x)}
1227are all equivalent.
1228
1229
1230Other optional arguments are
1231\begin{itemize}
1232\item \code{indices} which is a list of ids of triangles to which set_quantity should apply its assignment of values.
1233\item \code{location} determines which part of the triangles to assign to. Options are 'vertices' (default), 'edges', and 'centroids'.
1234\end{itemize}
1235
1236
1237a number, in which case all vertices in the mesh gets that for
1238the quantity in question.
1239\item a list of numbers or a Numeric array ordered the same way as the mesh vertices.
1240
1241
1242\end{funcdesc}
1243
1244
1245
1246
1247
1248
1249
1250%%%
1251\anuga provides a number of predefined initial conditions to be used
1252with \code{set_quantity}.
1253
1254\begin{funcdesc}{tsunami_slump}{length, depth, slope, width=None, thickness=None,
1255                x0=0.0, y0=0.0, alpha=0.0,
1256                gravity=9.8, gamma=1.85,
1257                massco=1, dragco=1, frictionco=0, psi=0,
1258                dx=None, kappa=3.0, kappad=0.8, zsmall=0.01,
1259                domain=None,
1260                verbose=False}
1261This function returns a callable object representing an initial water
1262displacement generated by a submarine sediment failure. These failures can take the form of
1263a submarine slump or slide.
1264
1265The arguments include as a minimum, the slump or slide length, the water depth to the centre of sediment
1266mass, and the bathymetric slope. Other slump or slide parameters can be included if they are known.
1267\end{funcdesc}
1268
1269
1270%%%
1271\begin{funcdesc}{file_function}{filename,
1272                  domain = None,
1273                  quantities = None,
1274                  interpolation_points = None,
1275                  verbose = False,
1276                  use_cache = False}
1277Module: \module{pyvolution.util}
1278
1279Reads the time history of spatial data from NetCDF file and returns
1280a callable object. Returns interpolated values based on the input
1281file using the underlying \code{interpolation_function}.
1282
1283\code{quantities} is either the name of a single quantity to be
1284interpolated or a list of such quantity names. In the second case, the resulting
1285function will return a tuple of values---one for each quantity.
1286
1287\code{interpolation_points} is a list of absolute UTM coordinates
1288for points at which values are sought.
1289
1290To get access to the model time stored within the file funcion use the method \code{f.get_time()}
1291\end{funcdesc}
1292
1293%%%
1294\begin{classdesc}{Interpolation\_function}{self,
1295                 time,
1296                 quantities,
1297                 quantity_names = None,
1298                 vertex_coordinates = None,
1299                 triangles = None,
1300                 interpolation_points = None,
1301                 verbose = False}
1302Module: \module{pyvolution.least\_squares}
1303
1304Given a time series, either as a sequence of numbers or
1305defined at the vertices of a triangular mesh (such
1306as those stored in \code{sww} files), \code{Interpolation\_function}
1307is used to create a callable object that interpolates a value for
1308an arbitrary time \code{t} within the model limits and possibly a
1309point \code{(x, y)} within a mesh region.
1310
1311The actual time series at which data is available is specified by
1312means of an array \code{time} of monotonically increasing times. The
1313quantities containing the values to be interpolated are specified in
1314an array---or dictionary of arrays (used in conjunction with the
1315optional argument \code{quantity\_names}) --- called
1316\code{quantities}. The optional arguments \code{vertex_coordinates}
1317and \code{triangles} represent the spatial mesh associated with the
1318quantity arrays. If omitted the function created by
1319\code{Interpolation\_function} will be a function of \code{t} only.
1320
1321Since, in practice, values need to be computed at specified points,
1322the syntax allows the user to specify, once and for all, a list
1323\code{interpolation\_points} of points at which values are required.
1324In this case, the function may be called using the form \code{f(t,
1325id)}, where \code{id} is an index for the list
1326\code{interpolation\_points}.
1327
1328\end{classdesc}
1329
1330%%%
1331\begin{funcdesc}{set\_region}{functions}
1332[Low priority. Will be merged into set\_quantity]
1333
1334Module:\module{pyvolution.domain}
1335\end{funcdesc}
1336
1337
1338
1339%%%%%%
1340\section{Boundary Conditions}
1341
1342\anuga provides a large number of predefined boundary conditions,
1343represented by objects such as \code{Reflective\_boundary(domain)} and
1344\code{Dirichlet\_boundary([0.2, 0.0, 0.0])}, described in the examples
1345in Chapter 2. Alternatively, you may prefer to ``roll your own'',
1346following the method explained in Section \ref{sec:roll your own}.
1347
1348These boundary objects may be used with the function \code{set\_boundary} described below
1349to assign boundary conditions according to the tags used to label boundary segments.
1350
1351\begin{funcdesc}{set\_boundary}{boundary_map}
1352Module: \module{pyvolution.domain}
1353
1354This function allows you to assign a boundary object (corresponding to a
1355pre-defined or user-specified boundary condition) to every boundary segment that
1356has been assigned a particular tag.
1357
1358This is done by specifying a dictionary \code{boundary\_map}, whose values are the boundary objects
1359and whose keys are the symbolic tags.
1360
1361\end{funcdesc}
1362
1363\begin{funcdesc} {get_boundary_tags}{}
1364Module: \module{pyvolution.mesh}
1365\end{funcdesc}
1366
1367%%%
1368\subsection{Predefined boundary conditions}
1369
1370\begin{classdesc}{Reflective_boundary}{Boundary}
1371Module: \module{pyvolution.shallow\_water}
1372
1373Reflective boundary returns same conserved quantities as those present in
1374the neighbouring volume but reflected.
1375
1376This class is specific to the shallow water equation as it works with the
1377momentum quantities assumed to be the second and third conserved quantities.
1378\end{classdesc}
1379
1380%%%
1381\begin{classdesc}{Transmissive_boundary}{domain = None}
1382Module: \module{pyvolution.generic\_boundary\_conditions}
1383
1384A transmissive boundary returns the same conserved quantities as
1385those present in the neighbouring volume.
1386
1387The underlying domain must be specified when the boundary is instantiated.
1388\end{classdesc}
1389
1390%%%
1391\begin{classdesc}{Dirichlet_boundary}{conserved_quantities=None}
1392Module: \module{pyvolution.generic\_boundary\_conditions}
1393
1394A Dirichlet boundary returns constant values for the conserved
1395quantities.
1396\end{classdesc}
1397
1398%%%
1399\begin{classdesc}{Time_boundary}{domain = None, f = None}
1400Module: \module{pyvolution.generic\_boundary\_conditions}
1401
1402A time-dependent boundary returns values for the conserved
1403quantities as a function \code{f(t)} of time. The user must specify
1404the domain to get access to the model time.
1405\end{classdesc}
1406
1407%%%
1408\begin{classdesc}{File_boundary}{Boundary}
1409Module: \module{pyvolution.generic\_boundary\_conditions}
1410
1411The boundary values are obtained from a file and interpolated. The
1412file is assumed to contain a time series and possibly also spatial
1413information. The conserved quantities are given as a function of
1414time.
1415\end{classdesc}
1416
1417
1418\subsection{User-defined boundary conditions}
1419\label{sec:roll your own}
1420[How to roll your own]
1421
1422
1423
1424
1425
1426\section{Forcing Functions}
1427
1428\anuga provides a number of predefined forcing functions to be used with .....
1429
1430%\begin{itemize}
1431
1432
1433%  \item \indexedcode{}
1434%  [function, arguments]
1435
1436%  \item \indexedcode{}
1437
1438%\end{itemize}
1439
1440
1441
1442\section{Evolution}
1443
1444  \begin{funcdesc}{evolve}{yieldstep = None, finaltime = None, duration = None, skip_initial_step = False}
1445
1446  Module: \module{pyvolution.domain}
1447
1448  This function (a method of \class{domain}) is invoked once all the
1449  preliminaries have been completed, and causes the model to progress
1450  through successive steps in its evolution, storing results and
1451  outputting statistics whenever a user-specified period
1452  \code{yieldstep} is completed (generally during this period the
1453  model will evolve through several steps internally). The user
1454  specifies the total time period over which the evolution is to take
1455  place, by specifying values (in seconds) for either \code{duration}
1456  or \code{finaltime}, as well as the interval in seconds after which
1457  results are to be stored and statistics output.
1458
1459  You can include \method{evolve} in a statement of the type:
1460
1461  {\small \begin{verbatim}
1462      for t in domain.evolve(yieldstep, finaltime):
1463          <Do something with domain and t>
1464  \end{verbatim}}
1465
1466  \end{funcdesc}
1467
1468
1469
1470\subsection{Diagnostics}
1471
1472  \begin{funcdesc}{timestepping_statistics}{}
1473  Module: \module{pyvolution.domain}
1474
1475
1476  \end{funcdesc}
1477
1478
1479  \begin{funcdesc}{boundary\_statistics}{quantities = None, tags = None}
1480  Module: \module{pyvolution.domain}
1481
1482
1483  \end{funcdesc}
1484
1485
1486  \begin{funcdesc}{get_quantity}{name, location='vertices', indices = None}
1487  Module: \module{pyvolution.domain}
1488  Allow access to individual quantities and their methods
1489
1490  \end{funcdesc}
1491
1492
1493  \begin{funcdesc}{get_values}{location='vertices', indices = None}
1494  Module: \module{pyvolution.quantity}
1495
1496  Extract values for quantity as an array
1497
1498  \end{funcdesc}
1499
1500
1501  \begin{funcdesc}{get_integral}{}
1502  Module: \module{pyvolution.quantity}
1503
1504  Return computed integral over entire domain for this quantity
1505
1506  \end{funcdesc}
1507
1508
1509\section{Other}
1510
1511  \begin{funcdesc}{domain.create_quantity_from_expression}{???}
1512
1513  Handy for creating derived quantities on-the-fly.
1514  See \file{Analytical\_solution\_circular\_hydraulic\_jump.py} for an example of use.
1515  \end{funcdesc}
1516
1517
1518  \begin{classdesc}{Geospatial_data}{???}
1519    Module: \module{geospatial_data.geo_spatial_data}
1520    Creates a georeferenced geospatial data object from either arrays or
1521    a file (pts or xya).
1522
1523    Objects of this class can be used with \method{set\_quantity}.
1524   
1525    FIXME (Ole): Describe methods such as get_attributes() etc
1526  \end{classdesc}
1527
1528
1529
1530
1531
1532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1533%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1534
1535\chapter{\anuga System Architecture}
1536
1537From pyvolution/documentation
1538
1539\section{File Formats}
1540\label{sec:file formats}
1541
1542\anuga makes use of a number of different file formats. The
1543following table lists all these formats, which are described in more
1544detail in the paragraphs below.
1545
1546\bigskip
1547
1548\begin{center}
1549
1550\begin{tabular}{|ll|}  \hline
1551
1552\textbf{Extension} & \textbf{Description} \\
1553\hline\hline
1554
1555\code{.sww} & NetCDF format for storing model output
1556\code{f(t,x,y)}\\
1557
1558\code{.tms} & NetCDF format for storing time series \code{f(t)}\\
1559
1560\code{.xya} & ASCII format for storing arbitrary points and
1561associated attributes\\
1562
1563\code{.pts} & NetCDF format for storing arbitrary points and
1564associated attributes\\
1565
1566\code{.asc} & ASCII format of regular DEMs as output from ArcView\\
1567
1568\code{.prj} & Associated ArcView file giving more metadata for
1569\code{.asc} format\\
1570
1571\code{.ers} & ERMapper header format of regular DEMs for ArcView\\
1572
1573\code{.dem} & NetCDF representation of regular DEM data\\
1574
1575\code{.tsh} & ASCII format for storing meshes and associated
1576boundary and region info\\
1577
1578\code{.msh} & NetCDF format for storing meshes and associated
1579boundary and region info\\
1580
1581\code{.nc} & Native ferret NetCDF format\\
1582
1583\code{.geo} & Houdinis ASCII geometry format (?) \\  \par \hline
1584%\caption{File formats used by \anuga}
1585\end{tabular}
1586
1587
1588\end{center}
1589
1590The above table shows the file extensions used to identify the
1591formats of files. However, typically, in referring to a format we
1592capitalise the extension and omit the initial full stop---thus, we
1593refer, for example, to `SWW files' or `PRJ files'.
1594
1595\bigskip
1596
1597A typical dataflow can be described as follows:
1598
1599\subsection{Manually Created Files}
1600
1601\begin{tabular}{ll}
1602ASC, PRJ & Digital elevation models (gridded)\\
1603TSH & Triangular meshes (e.g. created from \code{pmesh})\\
1604NC & Model outputs for use as boundary conditions (e.g. from MOST)
1605\end{tabular}
1606
1607\subsection{Automatically Created Files}
1608
1609\begin{tabular}{ll}
1610ASC, PRJ  $\rightarrow$  DEM  $\rightarrow$  PTS & Convert
1611DEMs to native \code{.pts} file\\
1612
1613NC $\rightarrow$ SWW & Convert MOST boundary files to
1614boundary \code{.sww}\\
1615
1616PTS + TSH $\rightarrow$ TSH with elevation & Least squares fit\\
1617
1618TSH $\rightarrow$ SWW & Convert TSH to \code{.sww}-viewable using
1619Swollen\\
1620
1621TSH + Boundary SWW $\rightarrow$ SWW & Simulation using
1622\code{pyvolution}
1623\end{tabular}
1624
1625
1626
1627
1628\bigskip
1629
1630\subsection{SWW and TMS Formats}
1631
1632The SWW and TMS formats are both NetCDF formats, and are of key
1633importance for \anuga.
1634
1635An SWW file is used for storing \anuga output and therefore pertains
1636to a set of points and a set of times at which a model is evaluated.
1637It contains, in addition to dimension information, the following
1638variables:
1639
1640\begin{itemize}
1641    \item \code{x} and \code{y}: coordinates of the points, represented as Numeric arrays
1642    \item \code{elevation}, a Numeric array storing bed-elevations
1643    \item \code{volumes}, a list specifying the points at the vertices of each of the
1644    triangles
1645    % Refer here to the example to be provided in describing the simple example
1646    \item \code{time}, a Numeric array containing times for model
1647    evaluation
1648\end{itemize}
1649
1650
1651The contents of an SWW file may be viewed using the visualisation
1652tool \code{swollen}, which creates an on-screen geometric
1653representation. See section \ref{sec:swollen} (page
1654\pageref{sec:swollen}) in Appendix \ref{ch:supportingtools} for more
1655on \code{swollen}.
1656
1657Alternatively, there are tools, such as \code{ncdump}, that allow
1658you to convert an NetCDF file into a readable format such as the
1659Class Definition Language (CDL). The following is an excerpt from a
1660CDL representation of the output file \file{bedslope.sww} generated
1661from running the simple example \file{runup.py} of
1662Chapter \ref{ch:getstarted}:
1663
1664\verbatiminput{examples/bedslopeexcerpt.cdl}
1665
1666The SWW format is used not only for output but also serves as input
1667for functions such as \function{file_boundary} and
1668\function{file_function}, described in Chapter \ref{ch:interface}.
1669
1670A TMS file is used to store time series data that is independent of
1671position.
1672
1673
1674\subsection{Meshfile Formats}
1675
1676A meshfile is a file that has a specific format suited to specifying
1677mesh data for \anuga. A meshfile can have one of two formats: it can
1678be either a TSH file, which is an ASCII file, or an MSH file, which
1679is a NetCDF file. A meshfile can be generated from the function
1680\function{create_mesh_from_regions} (see ) and used to initialise a
1681domain.
1682
1683A meshfile describes the outline of the mesh---the vertices and line
1684segments that enclose the region in which the mesh is created---and
1685the triangular mesh itself, which is specified by listing the
1686triangles and their vertices, and the segments, which are those
1687sides of the triangles that are associated with boundary conditions.
1688
1689In addition, a meshfile may contain `holes' and/or `regions'. A hole
1690or region is defined by specifying a point and a number of segments
1691that enclose that point. A hole represents an area where no mesh is
1692to be created, while a region is a labelled area used for defining
1693properties of a mesh, such as friction values.
1694
1695A meshfile can also contain a georeference, which describes an
1696offset to be applied to $x$ and $y$ values---eg to the vertices.
1697
1698
1699\subsection{Formats for Storing Arbitrary Points and Attributes}
1700
1701An XYA file is used to store data representing arbitrary numerical
1702attributes associated with a set of points.
1703
1704The format for an XYA file is:
1705%\begin{verbatim}
1706
1707            first line:     \code{[attribute names]}\\
1708            other lines:  \code{x y [attributes]}\\
1709
1710            for example:\\
1711            \code{elevation, friction}\\
1712            \code{0.6, 0.7, 4.9, 0.3}\\
1713            \code{1.9, 2.8, 5, 0.3}\\
1714            \code{2.7, 2.4, 5.2, 0.3}
1715
1716        The first two columns are always implicitly assumed to be $x$, $y$ coordinates.
1717        Use the same delimiter for the attribute names and the data.
1718
1719        An XYA file can optionally end with lines of this type:
1720
1721            \code{\#geo reference}\\
1722            \code{56}\\
1723            \code{466600.0}\\
1724            \code{8644444.0}
1725
1726        Here the first number specifies the zone (in this case zone 56)  and other numbers specify the
1727        coordinates (in this case (466600.0, 8644444.0)) of the lower left corner.
1728
1729A PTS file is a NetCDF representation of the data held in an XYA
1730file. If the data is associated with a set of $N$ points, then the
1731data is stored using an $N \times 2$ Numeric array of float
1732variables for the points and an $N \times 1$ Numeric array for each
1733attribute.
1734
1735%\end{verbatim}
1736
1737\subsection{ArcView Formats}
1738
1739Files of the three formats ASC, PRJ and ERS are all associated with
1740data from ArcView.
1741
1742An ASC file is an ASCII representation of DEM output from ArcView.
1743It has the following format...
1744
1745A PRJ file is an ArcView file used in conjunction with an ASC file
1746to represent metadata for a DEM.
1747
1748
1749\subsection{DEM Format}
1750
1751A DEM file is a NetCDF representation of regular DEM data.
1752
1753
1754\subsection{Other Formats}
1755
1756
1757
1758
1759\subsection{Basic File Conversions}
1760
1761  \begin{funcdesc}{sww2dem}{basename_in, basename_out = None,
1762            quantity = None,
1763            timestep = None,
1764            reduction = None,
1765            cellsize = 10,
1766            NODATA_value = -9999,
1767            easting_min = None,
1768            easting_max = None,
1769            northing_min = None,
1770            northing_max = None,
1771            expand_search = False,
1772            verbose = False,
1773            origin = None,
1774            datum = 'WGS84',
1775            format = 'ers'}
1776  Module: \module{pyvolution.data\_manager}
1777
1778  Takes data from an SWW file and converts it to DEM format (ASC or
1779  ERS)
1780  \end{funcdesc}
1781
1782
1783  \begin{funcdesc}{dem2pts}{basename_in, basename_out=None,
1784            easting_min=None, easting_max=None,
1785            northing_min=None, northing_max=None,
1786            use_cache=False, verbose=False}
1787  Module: \module{pyvolution.data\_manager}
1788
1789  Takes DEM data (a NetCDF file representation of data from a regular Digital
1790  Elevation Model) and converts it to PTS format.
1791  \end{funcdesc}
1792
1793
1794
1795%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1796%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1797
1798\chapter{Basic \anuga Assumptions}
1799
1800(From pyvolution/documentation)
1801
1802
1803Physical model time cannot be earlier than 1 Jan 1970 00:00:00.
1804If one wished to recreate scenarios prior to that date it must be done
1805using some relative time (e.g. 0).
1806
1807
1808All spatial data relates to the WGS84 datum (or GDA94) and has been
1809projected into UTM with false easting of 500000 and false northing of
18101000000 on the southern hemisphere (0 on the northern).
1811
1812It is assumed that all computations take place within one UTM zone.
1813
1814DEMs, meshes and boundary conditions can have different origins within
1815one UTM zone. However, the computation will use that of the mesh for
1816numerical stability.
1817
1818
1819%OLD
1820%The dataflow is: (See data_manager.py and from scenarios)
1821%
1822%
1823%Simulation scenarios
1824%--------------------%
1825%%
1826%
1827%Sub directories contain scrips and derived files for each simulation.
1828%The directory ../source_data contains large source files such as
1829%DEMs provided externally as well as MOST tsunami simulations to be used
1830%as boundary conditions.
1831%
1832%Manual steps are:
1833%  Creation of DEMs from argcview (.asc + .prj)
1834%  Creation of mesh from pmesh (.tsh)
1835%  Creation of tsunami simulations from MOST (.nc)
1836%%
1837%
1838%Typical scripted steps are%
1839%
1840%  prepare_dem.py:  Convert asc and prj files supplied by arcview to
1841%                   native dem and pts formats%
1842%
1843%  prepare_pts.py: Convert netcdf output from MOST to an sww file suitable
1844%                  as boundary condition%
1845%
1846%  prepare_mesh.py: Merge DEM (pts) and mesh (tsh) using least squares
1847%                   smoothing. The outputs are tsh files with elevation data.%
1848%
1849%  run_simulation.py: Use the above together with various parameters to
1850%                     run inundation simulation.
1851
1852
1853%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1854%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855
1856\appendix
1857
1858\chapter{Supporting Tools}
1859\label{ch:supportingtools}
1860
1861This section describes a number of supporting tools, supplied with \anuga, that offer a
1862variety of types of functionality and enhance the basic capabilities of \anuga.
1863
1864\section{caching}
1865
1866  The \code{cache} function is used to provide supervised caching of function results. A Python
1867  function call of the form
1868
1869      {\small \begin{verbatim}
1870      result = func(arg1,...,argn)
1871      \end{verbatim}}
1872
1873  can be replaced by
1874
1875      {\small \begin{verbatim}
1876      from caching import cache
1877      result = cache(func,(arg1,...,argn))
1878      \end{verbatim}}
1879
1880  which returns the same output but reuses cached
1881  results if the function has been computed previously in the same context.
1882  \code{result} and the arguments can be simple types, tuples, list, dictionaries or
1883  objects, but not unhashable types such as functions or open file objects.
1884  The function \code{func} may be a member function of an object or a module.
1885
1886  This type of caching is particularly useful for computationally intensive
1887  functions with few frequently used combinations of input arguments. Note that
1888  if the inputs or output are very large caching may not save time because
1889  disc access may dominate the execution time.
1890
1891  If the function definition changes after a result has been cached, this will be
1892  detected by examining the functions \code{bytecode (co_code, co_consts,
1893  func_defualts, co_argcount)} and the function will be recomputed.
1894
1895  Options are set by means of the function \code{set_option(key, value)},
1896  where \code{key} is a key associated with a
1897  Python dictionary \code{options}. This dictionary stores settings such as the name of
1898  the directory used, the maximum
1899  number of cached files allowed, and so on.
1900
1901  The \code{cache} function allows the user also to specify a list of dependent files. If any of these
1902  have been changed, the function is recomputed and the results stored again.
1903
1904  %Other features include support for compression and a capability to \ldots
1905
1906
1907   \textbf{USAGE:}
1908
1909    {\small \begin{verbatim}
1910    result = cache(func, args, kwargs, dependencies, cachedir, verbose,
1911                   compression, evaluate, test, return_filename)
1912    \end{verbatim}}
1913
1914
1915\section{swollen}
1916\label{sec:swollen}
1917 The output generated by \anuga may be viewed by
1918means of the visualisation tool \code{swollen}, which takes the
1919\code{sww} file output by \anuga and creates a visual representation
1920of the data. Examples may be seen in Figures \ref{fig:runupstart}
1921and \ref{fig:bedslope2}. To view an \code{sww} file with
1922\code{swollen} in the Windows environment, you can simply drag the
1923icon representing the file over an icon on the desktop for the
1924\code{swollen} executable file (or a shortcut to it). Alternatively,
1925you can operate \code{swollen} from the command line, in both
1926Windows and Linux environments.
1927
1928On successful operation, you will see an interactive moving-picture display. You can use keys and the mouse
1929to slow down, speed up or stop the display, change the viewing position or carry out a number of other
1930simple operations.
1931
1932The main keys operating the interactive screen are:\\
1933
1934\begin{center}
1935\begin{tabular}{|ll|}   \hline
1936
1937\code{w} & toggle wireframe\\
1938
1939space bar & start/stop\\
1940
1941up/down arrows & increase/decrease speed\\
1942
1943left/right arrows & direction in time \emph{(when running)}\\ & step through simulation \emph{(when stopped)}\\
1944
1945left mouse button & rotate\\
1946
1947middle mouse button & pan\\
1948
1949right mouse button & zoom\\  \hline
1950
1951\end{tabular}
1952\end{center}
1953
1954\vfill
1955
1956The following table describes how to operate swollen from the command line:
1957
1958Usage: \code{swollen [options] swwfile \ldots}\\  \nopagebreak
1959Options:\\  \nopagebreak
1960\begin{tabular}{ll}
1961  \code{--display <type>} & \code{MONITOR | POWERWALL | REALITY_CENTER |}\\
1962                                    & \code{HEAD_MOUNTED_DISPLAY}\\
1963  \code{--rgba} & Request a RGBA colour buffer visual\\
1964  \code{--stencil} & Request a stencil buffer visual\\
1965  \code{--stereo} & Use default stereo mode which is \code{ANAGLYPHIC} if not \\
1966                                    & overridden by environmental variable\\
1967  \code{--stereo <mode>} & \code{ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT |}\\
1968                                    & \code{VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE |}\\
1969                                     & \code{ON | OFF} \\
1970  \code{-alphamax <float 0-1>} & Maximum transparency clamp value\\
1971  \code{-alphamin <float 0-1>} & Transparency value at \code{hmin}\\
1972  \code{-cullangle <float angle 0-90>} & Cull triangles steeper than this value\\
1973  \code{-help} & Display this information\\
1974  \code{-hmax <float>} & Height above which transparency is set to
1975                                     \code{alphamax}\\
1976  \code{-hmin <float>} & Height below which transparency is set to
1977                                     zero\\
1978  \code{-lightpos <float>,<float>,<float>} & $x,y,z$ of bedslope directional light ($z$ is
1979                                     up, default is overhead)\\
1980  \code{-loop}  & Repeated (looped) playback of \code{.swm} files\\
1981  \code{-movie <dirname>} & Save numbered images to named directory and
1982                                     quit\\
1983  \code{-nosky} & Omit background sky\\
1984  \code{-scale <float>} & Vertical scale factor\\
1985  \code{-texture <file>} & Image to use for bedslope topography\\
1986  \code{-tps <rate>} & Timesteps per second\\
1987  \code{-version} & Revision number and creation (not compile)
1988                                     date\\
1989\end{tabular}
1990
1991\section{utilities/polygons}
1992
1993  \begin{classdesc}{Polygon_function}{regions, default = 0.0, geo_reference = None}
1994  Module: \code{utilities.polygon}
1995
1996
1997  \end{classdesc}
1998
1999  \begin{funcdesc}{read_polygon}{filename}
2000  Module: \code{utilities.polygon}
2001
2002  Reads the specified file and returns a polygon. Each
2003  line of the file must contain exactly two numbers, separated by a comma, which are interpreted
2004  as coordinates of one vertex of the polygon.
2005  \end{funcdesc}
2006
2007  \begin{funcdesc}{populate_polygon}{polygon, number_of_points, seed = None, exclude = None}
2008  Module: \code{utilities.polygon}
2009
2010  Populates the interior of the specified polygon with the specified number of points,
2011  selected by means of a uniform distribution function.
2012  \end{funcdesc}
2013
2014  \begin{funcdesc}{point_in_polygon}{polygon, delta=1e-8}
2015  Module: \code{utilities.polygon}
2016
2017  Returns a point inside the specified polygon and close to the edge. The distance between
2018  the returned point and the nearest point of the polygon is less than $\sqrt{2}$ times the
2019  second argument \code{delta}, which is taken as $10^{-8}$ by default.
2020  \end{funcdesc}
2021
2022  \begin{funcdesc}{inside_polygon}{points, polygon, closed = True, verbose = False}
2023  Module: \code{utilities.polygon}
2024
2025  Used to test whether a single point---or the members of a list of points---
2026  are inside the specified polygon. If the first argument is a single point,
2027  returns \code{True} if the point is inside the polygon, or \code{False}
2028  otherwise. If the first argument is a list of points, returns a Numeric
2029  array comprising the indices of the points in the list that lie inside the polygon.
2030  (If none of the points are inside, returns \code{zeros((0,), 'l')}.)
2031  Points on the edges of the polygon are regarded as inside if
2032  \code{closed} is set to \code{True} or omitted; otherwise they are regarded as outside.
2033  \end{funcdesc}
2034
2035  \begin{funcdesc}{outside_polygon}{points, polygon, closed = True, verbose = False}
2036  Module: \code{utilities.polygon}
2037
2038  Exactly like \code{inside_polygon}, but with the words `inside' and `outside' interchanged.
2039  \end{funcdesc}
2040
2041  \begin{funcdesc}{point_on_line}{x, y, x0, y0, x1, y1}
2042  Module: \code{utilities.polygon}
2043
2044  Returns \code{True} or \code{False}, depending on whether the point with coordinates
2045  \code{x, y} is on the line passing through the points with coordinates \code{x0, y0}
2046  and \code{x1, y1} (extended if necessary at either end).
2047  \end{funcdesc}
2048
2049  \begin{funcdesc}{separate_points_by_polygon}{points, polygon,
2050                               closed = True, verbose = False}\indexedcode{separate_points_by_polygon}
2051  Module: \code{utilities.polygon}
2052
2053  \end{funcdesc}
2054
2055
2056
2057\section{coordinate_transforms}
2058
2059\section{geo_spatial_data}
2060
2061This describes a class that represents arbitrary point data in UTM
2062coordinates along with named attribute values.
2063
2064TBA
2065
2066\section{pmesh GUI}
2067
2068\section{alpha_shape}
2069
2070
2071\section{utilities/numerical_tools} Do now.
2072
2073\begin{itemize}
2074  \item \indexedcode{ensure_numeric}
2075  \item \indexedcode{mean}
2076  \item
2077\end{itemize}
2078
2079
2080\chapter{Modules available in \anuga}
2081
2082
2083\section{\module{pyvolution.general\_mesh} }
2084\declaremodule[pyvolution.generalmesh]{}{pyvolution.general\_mesh}
2085\label{mod:pyvolution.generalmesh}
2086
2087\section{\module{pyvolution.mesh} }
2088\declaremodule{}{pyvolution.mesh}
2089\label{mod:pyvolution.mesh}
2090
2091\section{\module{pyvolution.domain} --- Generic module for 2D triangular domains for finite-volume computations of conservation laws}
2092\declaremodule{}{pyvolution.domain}
2093\label{mod:pyvolution.domain}
2094
2095
2096\section{\module{pyvolution.quantity}}
2097\declaremodule{}{pyvolution.quantity}
2098\label{mod:pyvolution.quantity}
2099
2100
2101\section{\module{pyvolution.shallow\_water} --- 2D triangular domains for finite-volume computations of the shallow water wave equation. This module contains a specialisation of class Domain from module domain.py consisting of methods specific to the Shallow Water Wave Equation
2102}
2103\declaremodule[pyvolution.shallowwater]{}{pyvolution.shallow\_water}
2104\label{mod:pyvolution.shallowwater}
2105
2106
2107
2108
2109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2110
2111\chapter{Frequently Asked Questions}
2112
2113
2114\section{General Questions}
2115
2116\subsubsection{What is \anuga?}
2117
2118\subsubsection{Why is it called \anuga?}
2119
2120\subsubsection{How do I obtain a copy of \anuga?}
2121
2122\subsubsection{What developments are expected for \anuga in the future?}
2123
2124\subsubsection{Are there any published articles about \anuga that I can reference?}
2125
2126\section{Modelling Questions}
2127
2128\subsubsection{Which type of problems are \anuga good for?}
2129
2130\subsubsection{Which type of problems are beyond the scope of \anuga?}
2131
2132\subsubsection{Can I start the simulation at an arbitrary time?}
2133Yes, using \code{domain.set_time()} you can specify an arbitrary starting time.
2134This is for example useful in conjunction with a file_boundary, which may start hours before anything hits the model boundary. By assigning a later time for the model to start, computational resources aren't wasted.
2135
2136\subsubsection{Can I change values for any quantity during the simulation?}
2137Yes, using \code{domain.set_quantity()} inside the domain.evolve loop you
2138can change values of any quantity. This is for example useful if you wish to
2139let the system settle for a while before assigning an initial condition. Another example would be changing the values for elevation to model e.g. erosion.
2140
2141\subsubsection{Can I change boundary conditions during the simulation?}
2142Not sure, but it would be nice :-)
2143
2144\subsubsection{Why does a file\_function return a list of numbers when evaluated?}
2145Currently, file\_function works by returning values for the conserved
2146quantities \code{stage}, \code{xmomentum} and \code{ymomentum} at a given point in time and space as a triplet. To access e.g.\ \code{stage} one must specify element 0 of the triplet returned by file\_function.
2147
2148\subsubsection{Which diagnostics are available to troubleshoot a simulation?}
2149
2150\subsubsection{How do I use a DEM in my simulation?}
2151You use \code{dem2pts} to convert your DEM to the required .pts format. This .pts file is then called When setting the elevation data to the mesh
2152in \code{domain.set_quantity}
2153
2154\subsubsection{What sort of DEM resolution should I use?}
2155Try and work with the "best" you have available. Onshore DEMs are typically available in 25m, 100m and 250m grids. Note, offshore data is often sparse,
2156or non-existant.
2157
2158\subsubsection{What sort of mesh resolution should I use?}
2159The mesh resolution should be commensurate with your DEM - it does not make sense to put in place a mesh which is finer than your DEM. As an example,
2160if your DEM is on a 25m grid, then the cell resolution should be of the order of 315$m^2$ (this represents half the area of the square grid). Ideally,
2161you need a fine mesh over regions where the DEM changes rapidly, and other areas of significant interest, such as the coast.
2162
2163\subsubsection{How often should I store the output?}
2164This will depend on what you are trying to answer with your model and how much memory you have available on your machine. If you need
2165to look in detail at the evolution, then you will need to balance against your storage requirements and the duration of the simulation.
2166If the sww file exceeds 1Gb, another sww file will be created until the end of the simulation. As an example, to store all the conserved
2167quantities on a mesh with approximately 300000 triangles on a 2 min interval for 5 hours will result in approximately 350Mb sww file.
2168
2169\subsection{Boundary Conditions}
2170
2171\subsubsection{How do I create a Dirichlet boundary condition?}
2172
2173\subsubsection{How do I know which boundary tags are available?}
2174The method \code{domain.get_boundary_tags()} will return a list of
2175available tags for use with \code{domain.set_boundary_condition()}.
2176
2177
2178
2179
2180
2181\chapter{Glossary}
2182
2183\begin{itemize}
2184    \item \indexedbold{\anuga} Name of software (joint development between ANU and GA)
2185
2186    \item \indexedbold{domain} The domain of a function is the set of all input values to the function.
2187
2188    \item \indexedbold{Dirichlet boundary} - A Dirichlet boundary condition imposed on a differential equation
2189 which specifies the values the solution is to take on the boundary of the domain.
2190
2191    \item \indexedbold{elevation} - refers to bathymetry and topography
2192
2193    \item \indexedbold{bathymetry} - offshore elevation
2194
2195    \item \indexedbold{topography} - onshore elevation
2196
2197    \item \indexedbold{evolution} - integration of the shallow water wave equations over time
2198
2199    \item \indexedbold{forcing term}
2200
2201    \item \indexedbold{IDLE} - Development environment shipped with Python
2202
2203    \item \indexedbold{Manning friction coefficient}
2204
2205    \item \indexedbold{mesh}    - Triangulation of domain
2206
2207    \item \indexedbold{meshfile}  [generic word for either .tsh or
2208    .msh file]
2209
2210    \item \indexedbold{points file}  [generic word for either .pts or
2211    .xya file]
2212
2213    \item \indexedbold{grid} - evenly spaced mesh
2214
2215    \item \indexedbold{NetCDF}
2216
2217    \item \indexedbold{pmesh} does this really need to be here? it's a class/module?
2218
2219    \item \indexedbold{pyvolution} does this really need to be here? it's a class/module?
2220
2221    \item \indexedbold{conserved quantity} conserved (stage, x and y momentum)
2222
2223    \item \indexedbold{reflective boundary}
2224
2225    \item \indexedbold{smoothing} is this really needed?
2226
2227    \item \indexedbold{stage}
2228
2229%    \item \indexedbold{try this}
2230
2231    \item \indexedbold{swollen} - visualisation tool
2232
2233    \item \indexedbold{time boundary} - defined in the manual (flog from there)
2234
2235    \item \indexedbold{transmissive boundary} - defined in the manual (flog from there)
2236
2237    \item \indexedbold{xmomentum} - conserved quantity (note, two-dimensional SWW equations say only x and y and NOT z)
2238
2239    \item \indexedbold{ymomentum}  - conserved quantity
2240
2241    \item \indexedbold{resolution} -  The maximal area of a triangular cell in a mesh
2242
2243    \item \indexedbold{polygon} - A sequence of points in the plane. (Arbitrary polygons can be created
2244    in this way.)
2245    \anuga represents a polygon in one of two ways. One way is to represent it as a
2246    list whose members are either Python tuples
2247    or Python lists of length 2. The unit square, for example, would be represented by the
2248    list
2249    [ [0,0], [1,0], [1,1], [0,1] ]. The alternative is to represent it as an
2250    $N \times 2$ Numeric array, where $N$ is the number of points.
2251
2252    NOTE: More can be read in the module utilities/polygon.py ....
2253
2254    \item \indexedbold{easting} - A rectangular (x,y) coordinate measurement of distance east from a north-south reference line,
2255usually a meridian used as the axis of origin within a map zone or projection. Easting is a UTM (Universal Transverse Mercator) Coordinate.
2256
2257    \item \indexedbold{northing} - A rectangular (x,y) coordinate measurement of distance north from a north-south reference line,
2258usually a meridian used as the axis of origin within a map zone or projection. Northing is a UTM (Universal Transverse Mercator) Coordinate.
2259
2260
2261    \item \indexedbold{latitude} - The angular distance on a mericlear north and south of the equator, expressed in degrees and minutes.
2262
2263    \item \indexedbold{longitude} - The angular distance east or west, between the meridian of a particular place on Earth and that of the
2264Prime Meridian (located in Greenwich, England) expressed in degrees or time.
2265
2266    \item \indexedbold{edge} - A triangulare cell within the computational mesh can be depicted as a set of vertices joined by lines (the edges).
2267
2268    \item \indexedbold{vertex} - A point at which edges meet.
2269
2270    \item \indexedbold{finite volume} - The method evaluates the terms in the shallow water wave equationas fluxes at the surfaces of each
2271finite volume. Because the flux entering a given volume is identical to that leaving the adjacent volume, these methods are conservative.
2272Another advantage of the finite volume method is that it is easily formulated to allow for unstructured meshes.
2273The method is used in many computational fluid dynamics packages.
2274
2275
2276    \item \indexedbold{flux} - the amount of flow through the volume per unit time
2277
2278    \item \indexedbold{Digital Elevation Model (DEM)} - DEMs are digital files consisting of points of elevations,
2279sampled systematically at equally spaced intervals.
2280
2281
2282\end{itemize}
2283
2284The \code{\e appendix} markup need not be repeated for additional
2285appendices.
2286
2287
2288%
2289%  The ugly "%begin{latexonly}" pseudo-environments are really just to
2290%  keep LaTeX2HTML quiet during the \renewcommand{} macros; they're
2291%  not really valuable.
2292%
2293%  If you don't want the Module Index, you can remove all of this up
2294%  until the second \input line.
2295%
2296
2297%begin{latexonly}
2298%\renewcommand{\indexname}{Module Index}
2299%end{latexonly}
2300\input{mod\jobname.ind}        % Module Index
2301%
2302%begin{latexonly}
2303%\renewcommand{\indexname}{Index}
2304%end{latexonly}
2305\input{\jobname.ind}            % Index
2306
2307
2308
2309\end{document}
Note: See TracBrowser for help on using the repository browser.