source: documentation/user_manual/anuga_user_manual.tex @ 3241

Last change on this file since 3241 was 3179, checked in by duncan, 19 years ago

Added more pmesh stuff

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 103.2 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%\hyphenation{set\_datadir}
47
48\ifhtml
49\date{\today} % latex2html does not know about datetime
50\fi
51
52
53
54
55
56\release{1.0}   % release version; this is used to define the
57                % \version macro
58
59\makeindex          % tell \index to actually write the .idx file
60\makemodindex       % If this contains a lot of module sections.
61
62\setcounter{tocdepth}{3}
63\setcounter{secnumdepth}{3}
64
65
66\begin{document}
67\maketitle
68
69
70% This makes the contents more accessible from the front page of the HTML.
71\ifhtml
72\chapter*{Front Matter\label{front}}
73\fi
74
75%Subversion keywords:
76%
77%$LastChangedDate: 2006-06-19 05:58:37 +0000 (Mon, 19 Jun 2006) $
78%$LastChangedRevision: 3179 $
79%$LastChangedBy: sexton $
80
81\input{copyright}
82
83
84\begin{abstract}
85\label{def:anuga}
86
87\noindent \anuga\index{\anuga} is a hydrodynamic modelling tool that
88allows users to model realistic flow problems in complex geometries.
89Examples include dam breaks or the effects of natural hazards such
90as riverine flooding, storm surges and tsunami.
91
92The user must specify a study area represented by a mesh of triangular
93cells, the topography and bathymetry, frictional resistance, initial
94values for water level (called \emph{stage}\index{stage} within \anuga),
95boundary
96conditions and forces such as windstress or pressure gradients if
97applicable.
98
99\anuga tracks the evolution of water depth and horizontal momentum
100within each cell over time by solving the shallow water wave equation
101governing equation using a finite-volume method.
102
103\anuga cannot model details of breaking waves, flow under ceilings such
104as pipes, turbulence and vortices, vertical convection or viscous
105flows.
106
107\anuga also incorporates a mesh generator, called \code{pmesh}, that
108allows the user to set up the geometry of the problem interactively as
109well as tools for interpolation and surface fitting, and a number of
110auxiliary tools for visualising and interrogating the model output.
111
112Most \anuga components are written in the object-oriented programming
113language Python and most users will interact with \anuga by writing
114small Python programs based on the \anuga library
115functions. Computationally intensive components are written for
116efficiency in C routines working directly with the Numerical Python
117structures.
118
119
120\end{abstract}
121
122\tableofcontents
123
124
125\chapter{Introduction}
126
127
128\section{Purpose}
129
130The purpose of this user manual is to introduce the new user to the
131inundation software, describe what it can do and give step-by-step
132instructions for setting up and running hydrodynamic simulations.
133
134\section{Scope}
135
136This manual covers only what is needed to operate the software after
137installation and configuration. It does not includes instructions
138for installing the software or detailed API documentation, both of
139which will be covered in separate publications and by documentation
140in the source code.
141
142\section{Audience}
143
144Readers are assumed to be familiar with the operating environment
145and have a general understanding of the subject matter, as well as
146enough programming experience to adapt the code to different
147requirements and to understand the basic terminology of
148object-oriented programming.
149
150\pagebreak
151\chapter{Background}
152
153
154Modelling the effects on the built environment of natural hazards such
155as riverine flooding, storm surges and tsunami is critical for
156understanding their economic and social impact on our urban
157communities.  Geoscience Australia and the Australian National
158University are developing a hydrodynamic inundation modelling tool
159called \anuga to help simulate the impact of these hazards.
160
161The core of \anuga is the fluid dynamics module, called pyvolution,
162which is based on a finite-volume method for solving the shallow water
163wave equation.  The study area is represented by a mesh of triangular
164cells.  By solving the governing equation within each cell, water
165depth and horizontal momentum are tracked over time.
166
167A major capability of pyvolution is that it can model the process of
168wetting and drying as water enters and leaves an area.  This means
169that it is suitable for simulating water flow onto a beach or dry land
170and around structures such as buildings.  Pyvolution is also capable
171of modelling hydraulic jumps due to the ability of the finite-volume
172method to accommodate discontinuities in the solution.
173
174To set up a particular scenario the user specifies the geometry
175(bathymetry and topography), the initial water level (stage),
176boundary conditions such as tide, and any forcing terms that may
177drive the system such as wind stress or atmospheric pressure
178gradients. Gravity and frictional resistance from the different
179terrains in the model are represented by predefined forcing terms.
180
181A mesh generator, called pmesh, allows the user to set up the geometry
182of the problem interactively and to identify boundary segments and
183regions using symbolic tags.  These tags may then be used to set the
184actual boundary conditions and attributes for different regions
185(e.g. the Manning friction coefficient) for each simulation.
186
187Most \anuga components are written in the object-oriented programming
188language Python.  Software written in Python can be produced quickly
189and can be readily adapted to changing requirements throughout its
190lifetime.  Computationally intensive components are written for
191efficiency in C routines working directly with the Numerical Python
192structures.  The animation tool developed for \anuga is based on
193OpenSceneGraph, an Open Source Software (OSS) component allowing high
194level interaction with sophisticated graphics primitives.
195See \cite{nielsen2005} for more background on \anuga.
196
197\chapter{Restrictions and limitations on \anuga}
198
199Although a powerful and flexible tool for hydrodynamic modelling, \anuga has a
200number of limitations that any potential user need to be aware of. They are
201
202\begin{itemize}
203  \item The mathematical model is the 2D shallow water wave equation.
204  As such it cannot resolve vertical convection and consequently not breaking
205  waves or 3D turbulence (e.g.\ vorticity).
206  \item The finite volume is a very robust and flexible numerical technique,
207  but it is not the fastest method around. If the geometry is sufficiently
208  simple and if there is no need for wetting or drying, a finite-difference
209  method may be able to solve the problem faster than \anuga.
210  %\item Mesh resolutions near coastlines with steep gradients need to be...   
211  \item Frictional resistance is implemented using Manning's formula, but
212  \anuga has not yet been validated in regard to bottom roughness
213\end{itemize}
214
215
216
217\chapter{Getting Started}
218\label{ch:getstarted}
219
220This section is designed to assist the reader to get started with
221\anuga by working through some examples. Two examples are discussed;
222the first is a simple example to illustrate many of the ideas, and
223the second is a more realistic example.
224
225\section{A Simple Example}
226\label{sec:simpleexample}
227
228\subsection{Overview}
229
230What follows is a discussion of the structure and operation of a
231script called \file{runup.py}.
232
233This example carries out the solution of the shallow-water wave
234equation in the simple case of a configuration comprising a flat
235bed, sloping at a fixed angle in one direction and having a
236constant depth across each line in the perpendicular direction.
237
238The example demonstrates the basic ideas involved in setting up a
239complex scenario. In general the user specifies the geometry
240(bathymetry and topography), the initial water level, boundary
241conditions such as tide, and any forcing terms that may drive the
242system such as wind stress or atmospheric pressure gradients.
243Frictional resistance from the different terrains in the model is
244represented by predefined forcing terms. In this example, the
245boundary is reflective on three sides and a time dependent wave on
246one side.
247
248The present example represents a simple scenario and does not
249include any forcing terms, nor is the data taken from a file as it
250would typically be.
251
252The conserved quantities involved in the
253problem are stage (absolute height of water surface),
254$x$-momentum and $y$-momentum. Other quantities
255involved in the computation are the friction and elevation.
256
257Water depth can be obtained through the equation
258
259\begin{tabular}{rcrcl}
260  \code{depth} &=& \code{stage} &$-$& \code{elevation}
261\end{tabular}
262
263
264\subsection{Outline of the Program}
265
266In outline, \file{runup.py} performs the following steps:
267
268\begin{enumerate}
269
270   \item Sets up a triangular mesh.
271
272   \item Sets certain parameters governing the mode of
273operation of the model-specifying, for instance, where to store the model output.
274
275   \item Inputs various quantities describing physical measurements, such
276as the elevation, to be specified at each mesh point (vertex).
277
278   \item Sets up the boundary conditions.
279
280   \item Carries out the evolution of the model through a series of time
281steps and outputs the results, providing a results file that can
282be visualised.
283
284\end{enumerate}
285
286\subsection{The Code}
287
288%FIXME: we are using the \code function here.
289%This should be used wherever possible
290For reference we include below the complete code listing for
291\file{runup.py}. Subsequent paragraphs provide a
292`commentary' that describes each step of the program and explains it
293significance.
294
295\verbatiminput{examples/runup.py}
296%\verbatiminput{examples/bedslope.py}
297
298\subsection{Establishing the Mesh}\index{mesh, establishing}
299
300The first task is to set up the triangular mesh to be used for the
301scenario. This is carried out through the statement:
302
303{\small \begin{verbatim}
304    points, vertices, boundary = rectangular(10, 10)
305\end{verbatim}}
306
307The function \function{rectangular} is imported from a module
308\module{mesh\_factory} defined elsewhere. (\anuga also contains
309several other schemes that can be used for setting up meshes, but we
310shall not discuss these.) The above assignment sets up a $10 \times
31110$ rectangular mesh, triangulated in a regular way. The assignment
312
313{\small \begin{verbatim}
314    points, vertices, boundary = rectangular(m, n)
315\end{verbatim}}
316
317returns:
318
319\begin{itemize}
320
321   \item a list \code{points} giving the coordinates of each mesh point,
322
323   \item a list \code{vertices} specifying the three vertices of each triangle, and
324
325   \item a dictionary \code{boundary} that stores the edges on
326   the boundary and associates each with one of the symbolic tags \code{`left'}, \code{`right'},
327   \code{`top'} or \code{`bottom'}.
328
329\end{itemize}
330
331(For more details on symbolic tags, see page
332\pageref{ref:tagdescription}.)
333
334An example of a general unstructured mesh and the associated data
335structures \code{points}, \code{vertices} and \code{boundary} is
336given in Section \ref{sec:meshexample}.
337
338
339
340
341\subsection{Initialising the Domain}
342
343These variables are then used to set up a data structure
344\code{domain}, through the assignment:
345
346{\small \begin{verbatim}
347    domain = Domain(points, vertices, boundary)
348\end{verbatim}}
349
350This creates an instance of the \class{Domain} class, which
351represents the domain of the simulation. Specific options are set at
352this point, including the basename for the output file and the
353directory to be used for data:
354
355{\small \begin{verbatim}
356    domain.set_name('bedslope')
357\end{verbatim}}
358
359{\small \begin{verbatim}
360    domain.set_datadir('.')
361\end{verbatim}}
362
363In addition, the following statement now specifies that the
364quantities \code{stage}, \code{xmomentum} and \code{ymomentum} are
365to be stored:
366
367{\small \begin{verbatim}
368    domain.set_quantities_to_be_stored(['stage', 'xmomentum',
369    'ymomentum'])
370\end{verbatim}}
371
372
373\subsection{Initial Conditions}
374
375The next task is to specify a number of quantities that we wish to
376set for each mesh point. The class \class{Domain} has a method
377\method{set\_quantity}, used to specify these quantities. It is a
378flexible method that allows the user to set quantities in a variety
379of ways---using constants, functions, numeric arrays, expressions
380involving other quantities, or arbitrary data points with associated
381values, all of which can be passed as arguments. All quantities can
382be initialised using \method{set\_quantity}. For a conserved
383quantity (such as \code{stage, xmomentum, ymomentum}) this is called
384an \emph{initial condition}. However, other quantities that aren't
385updated by the equation are also assigned values using the same
386interface. The code in the present example demonstrates a number of
387forms in which we can invoke \method{set\_quantity}.
388
389
390\subsubsection{Elevation}
391
392The elevation, or height of the bed, is set using a function,
393defined through the statements below, which is specific to this
394example and specifies a particularly simple initial configuration
395for demonstration purposes:
396
397{\small \begin{verbatim}
398    def f(x,y):
399        return -x/2
400\end{verbatim}}
401
402This simply associates an elevation with each point \code{(x, y)} of
403the plane.  It specifies that the bed slopes linearly in the
404\code{x} direction, with slope $-\frac{1}{2}$,  and is constant in
405the \code{y} direction.
406
407Once the function \function{f} is specified, the quantity
408\code{elevation} is assigned through the simple statement:
409
410{\small \begin{verbatim}
411    domain.set_quantity('elevation', f)
412\end{verbatim}}
413
414
415\subsubsection{Friction}
416
417The assignment of the friction quantity (a forcing term)
418demonstrates another way we can use \method{set\_quantity} to set
419quantities---namely, assign them to a constant numerical value:
420
421{\small \begin{verbatim}
422    domain.set_quantity('friction', 0.1)
423\end{verbatim}}
424
425This specifies that the Manning friction coefficient is set to 0.1
426at every mesh point.
427
428\subsubsection{Stage}
429
430The stage (the height of the water surface) is related to the
431elevation and the depth at any time by the equation
432
433{\small \begin{verbatim}
434    stage = elevation + depth
435\end{verbatim}}
436
437
438For this example, we simply assign a constant value to \code{stage},
439using the statement
440
441{\small \begin{verbatim}
442    domain.set_quantity('stage', -.4)
443\end{verbatim}}
444
445which specifies that the surface level is set to a height of $-0.4$,
446i.e. 0.4 units (m) below the zero level.
447
448Although it is not necessary for this example, it may be useful to
449digress here and mention a variant to this requirement, which allows
450us to illustrate another way to use \method{set\_quantity}---namely,
451incorporating an expression involving other quantities. Suppose,
452instead of setting a constant value for the stage, we wished to
453specify a constant value for the \emph{depth}. For such a case we
454need to specify that \code{stage} is everywhere obtained by adding
455that value to the value already specified for \code{elevation}. We
456would do this by means of the statements:
457
458{\small \begin{verbatim}
459    h = 0.05 # Constant depth
460    domain.set_quantity('stage', expression = 'elevation + %f' %h)
461\end{verbatim}}
462
463That is, the value of \code{stage} is set to $\code{h} = 0.05$ plus
464the value of \code{elevation} already defined.
465
466The reader will probably appreciate that this capability to
467incorporate expressions into statements using \method{set\_quantity}
468greatly expands its power.) See Section \ref{sec:Initial Conditions} for more
469details.
470
471\subsection{Boundary Conditions}\index{boundary conditions}
472
473The boundary conditions are specified as follows:
474
475{\small \begin{verbatim}
476    Br = Reflective_boundary(domain)
477
478    Bt = Transmissive_boundary(domain)
479
480    Bd = Dirichlet_boundary([0.2,0.,0.])
481
482    Bw = Time_boundary(domain=domain,
483                f=lambda t: [(0.1*sin(t*2*pi)-0.3), 0.0, 0.0])
484\end{verbatim}}
485
486The effect of these statements is to set up a selection of different
487alternative boundary conditions and store them in variables that can be
488assigned as needed. Each boundary condition specifies the
489behaviour at a boundary in terms of the behaviour in neighbouring
490elements. The boundary conditions introduced here may be briefly described as
491follows:
492
493\begin{itemize}
494    \item \textbf{Reflective boundary}\label{def:reflective boundary} Returns same \code{stage} as
495      as present in its neighbour volume but momentum vector
496      reversed 180 degrees (reflected).
497      Specific to the shallow water equation as it works with the
498      momentum quantities assumed to be the second and third conserved
499      quantities. A reflective boundary condition models a solid wall.
500    \item \textbf{Transmissive boundary}\label{def:transmissive boundary} Returns same conserved quantities as
501      those present in its neighbour volume. This is one way of modelling
502      outflow from a domain, but it should be used with caution if flow is
503      not steady state as replication of momentum at the boundary
504      may cause occasional spurious effects. If this occurs,
505      consider using e.g. a Dirichlet boundary condition.
506    \item \textbf{Dirichlet boundary}\label{def:dirichlet boundary} Specifies
507      constant values for stage, $x$-momentum and $y$-momentum at the boundary.
508    \item \textbf{Time boundary}\label{def:time boundary} Like a Dirichlet
509      boundary but with behaviour varying with time.
510\end{itemize}
511
512\label{ref:tagdescription}Before describing how these boundary
513conditions are assigned, we recall that a mesh is specified using
514three variables \code{points}, \code{vertices} and \code{boundary}.
515In the code we are discussing, these three variables are returned by
516the function \code{rectangular}; however, the example given in
517Section \ref{sec:realdataexample} illustrates another way of
518assigning the values, by means of the function
519\code{create\_mesh\_from\_regions}.
520
521These variables store the data determining the mesh as follows. (You
522may find that the example given in Section \ref{sec:meshexample}
523helps to clarify the following discussion, even though that example
524is a \emph{non-rectangular} mesh.)
525
526\begin{itemize}
527\item The variable \code{points} stores a list of 2-tuples giving the
528coordinates of the mesh points.
529
530\item The variable \code{vertices} stores a list of 3-tuples of
531numbers, representing vertices of triangles in the mesh. In this
532list, the triangle whose vertices are \code{points[i]},
533\code{points[j]}, \code{points[k]} is represented by the 3-tuple
534\code{(i, j, k)}.
535
536\item The variable \code{boundary} is a Python dictionary that
537not only stores the edges that make up the boundary but also assigns
538symbolic tags to these edges to distinguish different parts of the
539boundary. An edge with endpoints \code{points[i]} and
540\code{points[j]} is represented by the 2-tuple \code{(i, j)}. The
541keys for the dictionary are the 2-tuples \code{(i, j)} corresponding
542to boundary edges in the mesh, and the values are the tags are used
543to label them. In the present example, the value \code{boundary[(i,
544j)]} assigned to \code{(i, j)]} is one of the four tags
545\code{`left'}, \code{`right'}, \code{`top'} or \code{`bottom'},
546depending on whether the boundary edge represented by \code{(i, j)}
547occurs at the left, right, top or bottom of the rectangle bounding
548the mesh. The function \code{rectangular} automatically assigns
549these tags to the boundary edges when it generates the mesh.
550\end{itemize}
551
552The tags provide the means to assign different boundary conditions
553to an edge depending on which part of the boundary it belongs to.
554(In Section \ref{sec:realdataexample} we describe an example that
555uses different boundary tags---in general, the possible tags are not
556limited to `left', `right', `top' and `bottom', but can be specified
557by the user.)
558
559Using the boundary objects described above, we assign a boundary
560condition to each part of the boundary by means of a statement like
561
562{\small \begin{verbatim}
563    domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br})
564\end{verbatim}}
565
566This statement stipulates that, in the current example, the right
567boundary varies with time, as defined by the lambda function, while the other
568boundaries are all reflective.
569
570The reader may wish to experiment by varying the choice of boundary
571types for one or more of the boundaries. (In the case of \code{Bd}
572and \code{Bw}, the three arguments in each case represent the
573\code{stage}, $x$-momentum and $y$-momentum, respectively.)
574
575{\small \begin{verbatim}
576    Bw = Time_boundary(domain=domain,
577                       f=lambda t: [(0.1*sin(t*2*pi)-0.3), 0.0, 0.0])
578\end{verbatim}}
579
580
581
582\subsection{Evolution}\index{evolution}
583
584The final statement \nopagebreak[3]
585{\small \begin{verbatim}
586    for t in domain.evolve(yieldstep = 0.1, duration = 4.0):
587        print domain.timestepping_statistics()
588\end{verbatim}}
589
590causes the configuration of the domain to `evolve', over a series of
591steps indicated by the values of \code{yieldstep} and
592\code{duration}, which can be altered as required.  The value of
593\code{yieldstep} controls the time interval between successive model
594outputs.  Behind the scenes more time steps are generally taken.
595
596
597\subsection{Output}
598
599The output is a NetCDF file with the extension \code{.sww}. It
600contains stage and momentum information and can be used with the
601\code{swollen} (see Section \ref{sec:swollen}) visualisation package
602to generate a visual display. See Section \ref{sec:file formats}
603(page \pageref{sec:file formats}) for more on NetCDF and other file
604formats.
605
606The following is a listing of the screen output seen by the user
607when this example is run:
608
609\verbatiminput{examples/runupoutput.txt}
610
611
612\section{How to Run the Code}
613
614The code can be run in various ways:
615
616\begin{itemize}
617  \item{from a Windows or Unix command line} as in\ \code{python runup.py}
618  \item{within the Python IDLE environment}
619  \item{within emacs}
620  \item{within Windows, by double-clicking the \code{runup.py}
621  file.}
622\end{itemize}
623
624
625\section{Exploring the Model Output}
626
627The following figures are screenshots from the \anuga visualisation
628tool \code{swollen}. Figure \ref{fig:runupstart} shows the domain
629with water surface as specified by the initial condition, $t=0$.
630Figure \ref{fig:bedslope2} shows later snapshots for $t=2.3$ and
631$t=4$ where the system has been evolved and the wave is encroaching
632on the previously dry bed.  All figures are screenshots from an
633interactive animation tool called Swollen which is part of \anuga.
634Swollen is described in more detail is Section \ref{sec:swollen}.
635
636\begin{figure}[hbt]
637
638  \centerline{\includegraphics[width=75mm, height=75mm]
639    {examples/runupstart.eps}}
640
641  \caption{Bedslope example viewed with Swollen}
642  \label{fig:runupstart}
643\end{figure}
644
645
646\begin{figure}[hbt]
647
648  \centerline{
649    \includegraphics[width=75mm, height=75mm]{examples/runupduring.eps}
650    \includegraphics[width=75mm, height=75mm]{examples/runupend.eps}
651   }
652
653  \caption{Bedslope example viewed with Swollen}
654  \label{fig:bedslope2}
655\end{figure}
656
657
658
659
660\clearpage
661
662%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663
664\section{An Example with Real Data}
665\label{sec:realdataexample} The following discussion builds on the
666concepts introduced through the \file{runup.py} example and
667introduces a second example, \file{run\_sydney.py}.  This refers to
668a real-life scenario, in which the domain of interest surrounds the
669Sydney region, and predominantly covers Sydney Harbour. A
670hypothetical tsunami wave is generated by a submarine mass failure
671situated on the edge of the continental shelf.
672
673\subsection{Overview}
674As in the case of \file{runup.py}, the actions carried
675out by the program can be organised according to this outline:
676
677\begin{enumerate}
678
679   \item Set up a triangular mesh.
680
681   \item Set certain parameters governing the mode of
682operation of the model---specifying, for instance, where to store the
683model output.
684
685   \item Input various quantities describing physical measurements, such
686as the elevation, to be specified at each mesh point (vertex).
687
688   \item Set up the boundary conditions.
689
690   \item Carry out the evolution of the model through a series of time
691steps and output the results, providing a results file that can be
692visualised.
693
694\end{enumerate}
695
696
697
698\subsection{The Code}
699
700Here is the code for \file{run\_sydney\_smf.py}:
701
702\verbatiminput{examples/runsydney.py}
703
704In discussing the details of this example, we follow the outline
705given above, discussing each major step of the code in turn.
706
707\subsection{Establishing the Mesh}\index{mesh, establishing}
708
709One obvious way that the present example differs from
710\file{runup.py} is in the use of a more complex method to
711create the mesh. Instead of imposing a mesh structure on a
712rectangular grid, the technique used for this example involves
713building mesh structures inside polygons specified by the user,
714using a mesh-generator referred to as \code{pmesh}.
715
716In its simplest form, \code{pmesh} creates the mesh within a single
717polygon whose vertices are at geographical locations specified by
718the user. The user specifies the \emph{resolution}---that is, the
719maximal area of a triangle used for triangulation---and a triangular
720mesh is created inside the polygon using a mesh generation engine.
721On any given platform, the same mesh will be returned. Figure
722\ref{fig:pentagon} shows a simple example of this, in which the
723triangulation is carried out within a pentagon.
724
725
726\begin{figure}[hbt]
727
728  \caption{Mesh points are created inside the polygon}
729  \label{fig:pentagon}
730\end{figure}
731
732Boundary tags are not restricted to \code{`left'}, \code{`right'},
733\code{`bottom'} and \code{`top'}, as in the case of
734\file{runup.py}. Instead the user specifies a list of
735tags appropriate to the configuration being modelled.
736
737In addition, \code{pmesh} provides a way to adapt to geographic or
738other features in the landscape, whose presence may require an
739increase in resolution. This is done by allowing the user to specify
740a number of \emph{interior polygons}, each with a specified
741resolution, see Figure \ref{fig:interior meshes}. It is also
742possible to specify one or more `holes'---that is, areas bounded by
743polygons in which no triangulation is required.
744
745\begin{figure}[hbt]
746
747
748
749  \caption{Interior meshes with individual resolution}
750  \label{fig:interior meshes}
751\end{figure}
752
753In its general form, \code{pmesh} takes for its input a bounding
754polygon and (optionally) a list of interior polygons. The user
755specifies resolutions, both for the bounding polygon and for each of
756the interior polygons. Given this data, \code{pmesh} first creates a
757triangular mesh with varying resolution.
758
759The function used to implement this process is
760\function{create\_mesh\_from\_regions}. Its arguments include the
761bounding polygon and its resolution, a list of boundary tags, and a
762list of pairs \code{[polygon, resolution]}, specifying the interior
763polygons and their resolutions.
764
765In practice, the details of the polygons used are read from a
766separate file \file{project.py}. Here is a complete listing of
767\file{project.py}:
768
769\verbatiminput{examples/project.py}
770
771The resulting mesh is output to a \emph{mesh file}\index{mesh
772file}\label{def:mesh file}. This term is used to describe a file of
773a specific format used to store the data specifying a mesh. (There
774are in fact two possible formats for such a file: it can either be a
775binary file, with extension \code{.msh}, or an ASCII file, with
776extension \code{.tsh}. In the present case, the binary file format
777\code{.msh} is used. See Section \ref{sec:file formats} (page
778\pageref{sec:file formats}) for more on file formats.)
779
780The statements
781
782{\small \begin{verbatim}
783    interior_res = 5000%
784    interior_regions = [[project.harbour_polygon_2, interior_res],
785                    [project.botanybay_polygon_2, interior_res]]
786\end{verbatim}}
787
788are used to read in the specific polygons \code{project.harbour\_polygon\_2} and
789\code{botanybay\_polygon\_2} from \file{project.py} and assign a
790common resolution of 5000 to each. The statement
791
792{\small \begin{verbatim}
793    create_mesh_from_regions(project.diffpolygonall,
794                         boundary_tags= {'bottom': [0],
795                                         'right1': [1],
796                                         'right0': [2],
797                                         'right2': [3],
798                                         'top': [4],
799                                         'left1': [5],
800                                         'left2': [6],
801                                         'left3': [7]},
802                         maximum_triangle_area=100000,
803                         filename=meshname,
804                         interior_regions=interior_regions)
805\end{verbatim}}
806
807is then used to create the mesh, taking the bounding polygon to be
808the polygon \code{diffpolygonall} specified in \file{project.py}.
809The argument \code{boundary\_tags} assigns a dictionary, whose keys
810are the names of the boundary tags used for the bounding
811polygon---\code{`bottom'}, \code{`right0'}, \code{`right1'},
812\code{`right2'}, \code{`top'}, \code{`left1'}, \code{`left2'} and
813\code{`left3'}--- and whose values identify the indices of the
814segments associated with each of these tags. (The value associated
815with each boundary tag is a one-element list.)
816
817
818\subsection{Initialising the Domain}
819
820As with \file{runup.py}, once we have created the mesh, the next
821step is to create the data structure \code{domain}. We did this for
822\file{runup.py} by inputting lists of points and triangles and
823specifying the boundary tags directly. However, in the present case,
824we use a method that works directly with the mesh file
825\code{meshname}, as follows:
826
827
828{\small \begin{verbatim}
829    domain = Domain(meshname, use_cache=True, verbose=True)
830\end{verbatim}}
831
832Providing a filename instead of the lists used in \file{runup.py}
833above causes \code{Domain} to convert a mesh file \code{meshname}
834into an instance of \code{Domain}, allowing us to use methods like
835\method{set\_quantity} to set quantities and to apply other
836operations.
837
838%(In principle, the
839%second argument of \function{pmesh\_to\_domain\_instance} can be any
840%subclass of \class{Domain}, but for applications involving the
841%shallow-water wave equation, the second argument of
842%\function{pmesh\_to\_domain\_instance} can always be set simply to
843%\class{Domain}.)
844
845The following statements specify a basename and data directory, and
846identify quantities to be stored. For the first two, values are
847taken from \file{project.py}.
848
849{\small \begin{verbatim}
850    domain.set_name(project.basename)
851    domain.set_datadir(project.outputdir)
852    domain.set_quantities_to_be_stored(['stage', 'xmomentum',
853        'ymomentum'])
854\end{verbatim}}
855
856
857\subsection{Initial Conditions}
858Quantities for \file{runsydney.py} are set
859using similar methods to those in \file{runup.py}. However,
860in this case, many of the values are read from the auxiliary file
861\file{project.py} or, in the case of \code{elevation}, from an
862ancillary points file.
863
864
865
866\subsubsection{Stage}
867
868For the scenario we are modelling in this case, we use a callable
869object \code{tsunami\_source}, assigned by means of a function
870\function{slump\_tsunami}. This is similar to how we set elevation in
871\file{runup.py} using a function---however, in this case the
872function is both more complex and more interesting.
873
874The function returns the water displacement for all \code{x} and
875\code{y} in the domain. The water displacement is a double Gaussian
876function that depends on the characteristics of the slump (length,
877thickness, slope, etc), its location (origin) and the depth at that
878location.
879
880
881\subsubsection{Friction}
882
883We assign the friction exactly as we did for \file{runup.py}:
884
885{\small \begin{verbatim}
886    domain.set_quantity('friction', 0.0)
887\end{verbatim}}
888
889
890\subsubsection{Elevation}
891
892The elevation is specified by reading data from a file:
893
894{\small \begin{verbatim}
895    domain.set_quantity('elevation',
896                        filename = project.combineddemname + '.pts',
897                        use_cache = True,
898                        verbose = True)
899\end{verbatim}}
900
901However, before this step can be executed, some preliminary steps
902are needed to prepare the file from which the data is taken. Two
903source files are used for this data---their names are specified in
904the file \file{project.py}, in the variables \code{coarsedemname}
905and \code{finedemname}. They contain `coarse' and `fine' data,
906respectively---that is, data sampled at widely spaced points over a
907large region and data sampled at closely spaced points over a
908smaller subregion. The data in these files is combined through the
909statement
910
911{\small \begin{verbatim}
912combine_rectangular_points_files(project.finedemname + '.pts',
913                                 project.coarsedemname + '.pts',
914                                 project.combineddemname + '.pts')
915\end{verbatim}}
916
917The effect of this is simply to combine the datasets by eliminating
918any coarse data associated with points inside the smaller region
919common to both datasets. The name to be assigned to the resulting
920dataset is also derived from the name stored in the variable
921\code{combinedname} in the file \file{project.py}.
922
923\subsection{Boundary Conditions}\index{boundary conditions}
924
925Setting boundaries follows a similar pattern to the one used for
926\file{runup.py}, except that in this case we need to associate a
927boundary type with each of the
928boundary tag names introduced when we established the mesh. In place of the four
929boundary types introduced for \file{runup.py}, we use the reflective
930boundary for each of the
931eight tagged segments defined by \code{create_mesh_from_regions}:
932
933{\small \begin{verbatim}
934    Br = Reflective_boundary(domain)
935    domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br,
936                          'right2': Br, 'top': Br, 'left1': Br,
937                          'left2': Br, 'left3': Br} )
938\end{verbatim}}
939
940\subsection{Evolution}
941
942With the basics established, the running of the `evolve' step is
943very similar to the corresponding step in \file{runup.py}. Here,
944the simulation is run for five hours (18000 seconds) with
945the output stored every two minutes (120 seconds).
946
947{\small \begin{verbatim}
948    import time t0 = time.time()
949
950    for t in domain.evolve(yieldstep = 120, duration = 18000):
951        print domain.timestepping_statistics()
952        print domain.boundary_statistics(tags = 'bottom')
953
954    print 'That took %.2f seconds' %(time.time()
955\end{verbatim}}
956
957%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959
960\chapter{\anuga Public Interface}
961\label{ch:interface}
962
963This chapter gives an overview of the features of \anuga available
964to the user at the public interface. These are grouped under the
965following headings, which correspond to the outline of the examples
966described in Chapter \ref{ch:getstarted}:
967
968\begin{itemize}
969    \item Establishing the Mesh
970    \item Initialising the Domain
971    \item Specifying the Quantities
972    \item Initial Conditions
973    \item Boundary Conditions
974    \item Forcing Functions
975    \item Evolution
976\end{itemize}
977
978The listings are intended merely to give the reader an idea of what
979each feature is, where to find it and how it can be used---they do
980not give full specifications; for these the reader
981may consult the code. The code for every function or class contains
982a documentation string, or `docstring', that specifies the precise
983syntax for its use. This appears immediately after the line
984introducing the code, between two sets of triple quotes.
985
986Each listing also describes the location of the module in which
987the code for the feature being described can be found. All modules
988are in the folder \file{inundation} or one of its subfolders, and the
989location of each module is described relative to \file{inundation}. Rather
990than using pathnames, whose syntax depends on the operating system,
991we use the format adopted for importing the function or class for
992use in Python code. For example, suppose we wish to specify that the
993function \function{create\_mesh\_from\_regions} is in a module called
994\module{mesh\_interface} in a subfolder of \module{inundation} called
995\code{pmesh}. In Linux or Unix syntax, the pathname of the file
996containing the function, relative to \file{inundation}, would be
997
998\begin{center}
999%    \code{pmesh/mesh\_interface.py}
1000    \code{pmesh}$\slash$\code{mesh\_interface.py}
1001\end{center}
1002
1003while in Windows syntax it would be
1004
1005\begin{center}
1006    \code{pmesh}$\backslash$\code{mesh\_interface.py}
1007\end{center}
1008
1009Rather than using either of these forms, in this chapter we specify
1010the location simply as \code{pmesh.mesh\_interface}, in keeping with
1011the usage in the Python statement for importing the function,
1012namely:
1013\begin{center}
1014    \code{from pmesh.mesh\_interface import create\_mesh\_from\_regions}
1015\end{center}
1016
1017Each listing details the full set of parameters for the class or
1018function; however, the description is generally limited to the most
1019important parameters and the reader is again referred to the code
1020for more details.
1021
1022The following parameters are common to many functions and classes
1023and are omitted from the descriptions given below:
1024
1025%\begin{center}
1026\begin{tabular}{ll}  %\hline
1027%\textbf{Name } & \textbf{Description}\\
1028%\hline
1029\emph{use\_cache} & Specifies whether caching is to be used for improved performance. See Section \ref{sec:caching} for details on the underlying caching functionality\\
1030\emph{verbose} & If \code{True}, provides detailed terminal output
1031to the user\\  % \hline
1032\end{tabular}
1033%\end{center}
1034
1035\section{Mesh Generation}
1036
1037Before discussing the part of the interface relating to mesh
1038generation, we begin with a description of a simple example of a
1039mesh and use it to describe how mesh data is stored.
1040
1041\label{sec:meshexample} Figure \ref{fig:simplemesh} represents a
1042very simple mesh comprising just 11 points and 10 triangles.
1043
1044
1045\begin{figure}[h]
1046  \begin{center}
1047    \includegraphics[width=90mm, height=90mm]{triangularmesh.eps}
1048  \end{center}
1049
1050  \caption{A simple mesh}
1051  \label{fig:simplemesh}
1052\end{figure}
1053
1054
1055The variables \code{points}, \code{vertices} and \code{boundary}
1056represent the data displayed in Figure \ref{fig:simplemesh} as
1057follows. The list \code{points} stores the coordinates of the
1058points, and may be displayed schematically as in Table
1059\ref{tab:points}.
1060
1061
1062\begin{table}
1063  \begin{center}
1064    \begin{tabular}[t]{|c|cc|} \hline
1065      index & \code{x} & \code{y}\\  \hline
1066      0 & 1 & 1\\
1067      1 & 4 & 2\\
1068      2 & 8 & 1\\
1069      3 & 1 & 3\\
1070      4 & 5 & 5\\
1071      5 & 8 & 6\\
1072      6 & 11 & 5\\
1073      7 & 3 & 6\\
1074      8 & 1 & 8\\
1075      9 & 4 & 9\\
1076      10 & 10 & 7\\  \hline
1077    \end{tabular}
1078  \end{center}
1079
1080  \caption{Point coordinates for mesh in
1081    Figure \protect \ref{fig:simplemesh}}
1082  \label{tab:points}
1083\end{table}
1084
1085The list \code{vertices} specifies the triangles that make up the
1086mesh. It does this by specifying, for each triangle, the indices
1087(the numbers shown in the first column above) that correspond to the
1088three points at its vertices, taken in an anti-clockwise order
1089around the triangle. Thus, in the example shown in Figure
1090\ref{fig:simplemesh}, the variable \code{vertices} contains the
1091entries shown in Table \ref{tab:vertices}. The starting point is
1092arbitrary so triangle $(0,1,3)$ is considered the same as $(1,3,0)$
1093and $(3,0,1)$.
1094
1095
1096\begin{table}
1097  \begin{center}
1098    \begin{tabular}{|c|ccc|} \hline
1099      index & \multicolumn{3}{c|}{\code{vertices}}\\ \hline
1100      0 & 0 & 1 & 3\\
1101      1 & 1 & 2 & 4\\
1102      2 & 2 & 5 & 4\\
1103      3 & 2 & 6 & 5\\
1104      4 & 4 & 5 & 9\\
1105      5 & 4 & 9 & 7\\
1106      6 & 3 & 4 & 7\\
1107      7 & 7 & 9 & 8\\
1108      8 & 1 & 4 & 3\\
1109      9 & 5 & 10 & 9\\  \hline
1110    \end{tabular}
1111  \end{center}
1112
1113  \caption{Vertices for mesh in Figure \protect \ref{fig:simplemesh}}
1114  \label{tab:vertices}
1115\end{table}
1116
1117Finally, the variable \code{boundary} identifies the boundary
1118triangles and associates a tag with each.
1119
1120\refmodindex[pmesh.meshinterface]{pmesh.mesh\_interface}\label{sec:meshgeneration}
1121
1122\begin{funcdesc}  {create\_mesh\_from\_regions}{bounding_polygon,
1123                             boundary_tags,
1124                             maximum_triangle_area,
1125                             filename=None,
1126                             interior_regions=None,
1127                             poly_geo_reference=None,
1128                             mesh_geo_reference=None,
1129                             minimum_triangle_angle=28.0}
1130Module: \module{pmesh.mesh\_interface}
1131
1132This function allows a user to initiate the automatic creation of a
1133mesh inside a specified polygon (input \code{bounding_polygon}).
1134Among the parameters that can be set are the \emph{resolution}
1135(maximal area for any triangle in the mesh) and the minimal angle
1136allowable in any triangle. The user can specify a number of internal
1137polygons within each of which a separate mesh is to be created,
1138generally with a smaller resolution. \code{interior_regions} is a
1139paired list containing the interior polygon and its resolution.
1140Additionally, the user specifies a list of boundary tags, one for
1141each edge of the bounding polygon.
1142
1143\textbf{WARNING}. Note that the dictionary structure used for the
1144parameter \code{boundary\_tags} is different from that used for the
1145variable \code{boundary} that occurs in the specification of a mesh.
1146In the case of \code{boundary}, the tags are the \emph{values} of
1147the dictionary, whereas in the case of \code{boundary_tags}, the
1148tags are the \emph{keys} and the \emph{value} corresponding to a
1149particular tag is a list of numbers identifying boundary edges
1150labelled with that tag. Because of this, it is theoretically
1151possible to assign the same edge to more than one tag. However, an
1152attempt to do this will cause an error.
1153\end{funcdesc}
1154
1155
1156
1157
1158\begin{classdesc}  {Mesh}{userSegments=None,
1159                 userVertices=None,
1160                 holes=None,
1161                 regions=None,
1162                 geo_reference=None}
1163Module: \module{pmesh.mesh}
1164
1165A class used to build a mesh outline and generate a two-dimensional
1166triangular mesh. The mesh outline is used to describe features on the
1167mesh, such as the mesh boundary. Many of this classes methods are used
1168to build a mesh outline, such as \code{add\_vertices} and
1169\code{add\_region\_from\_polygon}.
1170
1171\end{classdesc}
1172
1173
1174\subsection{Key Methods of Class Mesh}
1175
1176
1177\begin{methoddesc} {add\_hole}{x,y, geo_reference=None}
1178Module: \module{pmesh.mesh},  Class: \class{Mesh}
1179
1180This method is used to build the mesh outline.  It defines a hole,
1181when the boundary of the hole has already been defined, by selecting a
1182point within the boundary.
1183
1184\end{methoddesc}
1185
1186
1187\begin{methoddesc}  {add\_hole\_from\_polygon}{self, polygon, tags=None,
1188    geo_reference=None}
1189Module: \module{pmesh.mesh},  Class: \class{Mesh}
1190
1191This method is used to add a `hole' within a region ---that is, to
1192define a interior region where the triangular mesh will not be
1193generated---to a \class{Mesh} instance. The region boundary is described by
1194the polygon passed in.  Additionally, the user specifies a list of
1195boundary tags, one for each edge of the bounding polygon.
1196\end{methoddesc}
1197
1198
1199\begin{methoddesc} {add\_region}{x,y, geo_reference=None}
1200Module: \module{pmesh.mesh},  Class: \class{Mesh}
1201
1202This method is used to build the mesh outline.  It defines a region,
1203when the boundary of the region has already been defined, by selecting
1204a point within the boundary.  A region instance is returned.  This can
1205be used to set the resolution.
1206
1207\end{methoddesc}
1208
1209\begin{methoddesc}  {add\_region\_from\_polygon}{self, polygon, tags=None,
1210                                max_triangle_area=None, geo_reference=None}
1211Module: \module{pmesh.mesh},  Class: \class{Mesh}
1212
1213This method is used to build the mesh outline.  It adds a region to a
1214\class{Mesh} instance.  Regions are commonly used to describe an area
1215with an increased density of triangles, by setting
1216\code{max_triangle_area}.  The
1217region boundary is described by the input \code{polygon}.  Additionally, the
1218user specifies a list of boundary tags, one for each edge of the
1219bounding polygon.
1220
1221\end{methoddesc}
1222
1223
1224
1225
1226
1227\begin{methoddesc} {add\_vertices}{point_data}
1228
1229Add user vertices. The point_data can be a list of (x,y) values, a numeric
1230array or a geospatial_data instance.
1231       
1232\end{methoddesc}
1233
1234\begin{methoddesc}  {export\_mesh_file}{self,ofile}
1235Module: \module{pmesh.mesh},  Class: \class{Mesh}
1236
1237This method is used to save the mesh to a file. \code{ofile} is the
1238name of the mesh file to be written, including the extension.  Use
1239the extension \code{.msh} for the file to be in NetCDF format and
1240\code{.tsh} for the file to be ASCII format.
1241\end{methoddesc}
1242
1243\begin{methoddesc}  {generate\_mesh}{self,
1244                      maximum_triangle_area=None,
1245                      minimum_triangle_angle=28.0,
1246                      verbose=False}
1247Module: \module{pmesh.mesh},  Class: \class{Mesh}
1248
1249This method is used to generate the triangular mesh.  The  maximal
1250area of any triangle in the mesh can be specified, which is used to
1251control the triangle density, along with the
1252minimum angle in any triangle.
1253\end{methoddesc}
1254
1255
1256
1257\begin{methoddesc}  {import_ungenerate_file}{self,ofile, tag=None}
1258Module: \module{pmesh.mesh},  Class: \class{Mesh}
1259
1260This method is used to import a polygon file in the ungenerate
1261format, which is used by arcGIS. The polygons from the file are converted to
1262vertices and segments. \code{ofile} is the name of the polygon file.
1263\code{tag} is the tag given to all the polygon's segments.
1264
1265This function can be used to import building footprints.
1266\end{methoddesc}
1267
1268%%%%%%
1269\section{Initialising the Domain}
1270
1271%Include description of the class Domain and the module domain.
1272
1273%FIXME (Ole): This is also defined in a later chapter
1274%\declaremodule{standard}{pyvolution.domain}
1275
1276\begin{classdesc} {Domain} {source=None,
1277                 triangles=None,
1278                 boundary=None,
1279                 conserved_quantities=None,
1280                 other_quantities=None,
1281                 tagged_elements=None,
1282                 geo_reference=None,
1283                 use_inscribed_circle=False,
1284                 mesh_filename=None,
1285                 use_cache=False,
1286                 verbose=False,
1287                 full_send_dict=None,
1288                 ghost_recv_dict=None,
1289                 processor=0,
1290                 numproc=1}
1291Module: \refmodule{pyvolution.domain}
1292
1293This class is used to create an instance of a data structure used to
1294store and manipulate data associated with a mesh. The mesh is
1295specified either by assigning the name of a mesh file to
1296\code{source} or by
1297\end{classdesc}
1298
1299\begin{funcdesc}  {pmesh\_to\_domain\_instance}{file_name, DomainClass, use_cache = False, verbose = False}
1300Module: \module{pyvolution.pmesh2domain}
1301
1302Once the initial mesh file has been created, this function is
1303applied to convert it to a domain object---that is, to a member of
1304the special Python class \class{Domain} (or a subclass of
1305\class{Domain}), which provides access to properties and methods
1306that allow quantities to be set and other operations to be carried
1307out.
1308
1309\code{file\_name} is the name of the mesh file to be converted,
1310including the extension. \code{DomainClass} is the class to be
1311returned, which must be a subclass of \class{Domain} having the same
1312interface as \class{Domain}---in practice, it can usually be set
1313simply to \class{Domain}.
1314
1315This is now superseded by Domain(mesh_filename).
1316\end{funcdesc}
1317
1318
1319\subsection{Key Methods of Domain}
1320
1321\begin{methoddesc} {set\_name}{name}
1322    Module: \refmodule{pyvolution.domain}, page \pageref{mod:pyvolution.domain}  %\code{pyvolution.domain}
1323
1324    Assigns the name \code{name} to the domain.
1325\end{methoddesc}
1326
1327\begin{methoddesc} {get\_name}{}
1328    Module: \module{pyvolution.domain}
1329
1330    Returns the name assigned to the domain by \code{set\_name}. If no name has been
1331    assigned, returns \code{`domain'}.
1332\end{methoddesc}
1333
1334\begin{methoddesc} {set\_datadir}{name}
1335    Module: \module{pyvolution.domain}
1336
1337    Specifies the directory used for SWW files, assigning it to the pathname \code{name}. The default value, before
1338    \code{set\_datadir} has been run, is the value \code{default\_datadir}
1339    specified in \code{config.py}.
1340
1341    Since different operating systems use different formats for specifying pathnames,
1342    it is necessary to specify path separators using the Python code \code{os.sep}, rather than
1343    the operating-specific ones such as `$\slash$' or `$\backslash$'.
1344    For this to work you will need to include the statement \code{import os}
1345    in your code, before the first appearance of \code{set\_datadir}.
1346
1347    For example, to set the data directory to a subdirectory
1348    \code{data} of the directory \code{project}, you could use
1349    the statements:
1350
1351    {\small \begin{verbatim}
1352        import os
1353        domain.set_datadir{'project' + os.sep + 'data'}
1354    \end{verbatim}}
1355\end{methoddesc}
1356
1357\begin{methoddesc} {get\_datadir}{}
1358    Module: \module{pyvolution.domain}
1359
1360    Returns the data directory set by \code{set\_datadir} or,
1361    if \code{set\_datadir} has not
1362    been run, returns the value \code{default\_datadir} specified in
1363    \code{config.py}.
1364\end{methoddesc}
1365
1366\begin{methoddesc} {set\_time}{time=0.0}
1367    Module: \module{pyvolution.domain}
1368
1369    Sets the initial time, in seconds, for the simulation. The
1370    default is 0.0.
1371\end{methoddesc}
1372
1373\begin{methoddesc} {set\_default\_order}{n}
1374    Sets the default (spatial) order to the value specified by
1375    \code{n}, which must be either 1 or 2. (Assigning any other value
1376    to \code{n} will cause an error.)
1377\end{methoddesc}
1378
1379
1380%%%%%%
1381\section{Initial Conditions}
1382\label{sec:Initial Conditions}
1383In standard usage of partial differential equations, initial conditions
1384refers to the values associated to the system variables (the conserved
1385quantities here) for \code{time = 0}. In setting up a scenario script
1386as described in Sections \ref{sec:simpleexample} and \ref{sec:realdataexample},
1387\code{set_quantity} is used to define the initial conditions of variables
1388other than the conserved quantities, such as friction. Here, we use the terminology
1389of initial conditions to refer to initial values for variables which need
1390prescription to solve the shallow water wave equation. Further, it must be noted
1391that \code{set_quantity} does not necessarily have to be used in the initial
1392condition setting; it can be used at any time throughout the simulation.
1393
1394\begin{methoddesc}{set\_quantity}{name,
1395    numeric = None,
1396    quantity = None,
1397    function = None,
1398    geospatial_data = None,
1399    filename = None,
1400    attribute_name = None,
1401    alpha = None,
1402    location = 'vertices',
1403    indices = None,
1404    verbose = False,
1405    use_cache = False}
1406  Module: \module{pyvolution.domain}
1407  (see also \module{pyvolution.quantity.set\_values})
1408
1409This function is used to assign values to individual quantities for a
1410domain. It is very flexible and can be used with many data types: a
1411statement of the form \code{domain.set\_quantity(name, x)} can be used
1412to define a quantity having the name \code{name}, where the other
1413argument \code{x} can be any of the following:
1414
1415\begin{itemize}
1416\item a number, in which case all vertices in the mesh gets that for
1417the quantity in question.
1418\item a list of numbers or a Numeric array ordered the same way as the mesh vertices.
1419\item a function (e.g.\ see the samples introduced in Chapter 2)
1420\item an expression composed of other quantities and numbers, arrays, lists (for
1421example, a linear combination of quantities, such as
1422\code{domain.set\_quantity('stage','elevation'+x))}
1423\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.
1424\item a geospatial dataset (See ?????). Optional argument attribute\_name applies here as with files.
1425\end{itemize}
1426
1427
1428Exactly one of the arguments
1429  numeric, quantity, function, points, filename
1430must be present.
1431
1432
1433Set quantity will look at the type of the second argument (\code{numeric}) and
1434determine what action to take.
1435
1436Values can also be set using the appropriate keyword arguments.
1437If 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)}
1438are all equivalent.
1439
1440
1441Other optional arguments are
1442\begin{itemize}
1443\item \code{indices} which is a list of ids of triangles to which set\_quantity should apply its assignment of values.
1444\item \code{location} determines which part of the triangles to assign to. Options are 'vertices' (default), 'edges', and 'centroids'.
1445\end{itemize}
1446
1447
1448\end{methoddesc}
1449
1450
1451
1452
1453
1454
1455
1456%%%
1457\anuga provides a number of predefined initial conditions to be used
1458with \code{set\_quantity}.
1459
1460\begin{funcdesc}{slump_tsunami}{length, depth, slope, width=None, thickness=None,
1461                x0=0.0, y0=0.0, alpha=0.0,
1462                gravity=9.8, gamma=1.85,
1463                massco=1, dragco=1, frictionco=0, psi=0,
1464                dx=None, kappa=3.0, kappad=0.8, zsmall=0.01,
1465                domain=None,
1466                verbose=False}
1467Module: \module{pyvolution.smf}
1468
1469This function returns a callable object representing an initial water
1470displacement generated by a submarine sediment failure. These failures can take the form of
1471a submarine slump or slide. In the case of a slide, use \code{slide_tsunami} instead.
1472
1473The arguments include as a minimum, the slump or slide length, the water depth to the centre of sediment
1474mass, and the bathymetric slope. Other slump or slide parameters can be included if they are known.
1475\end{funcdesc}
1476
1477
1478%%%
1479\begin{funcdesc}{file\_function}{filename,
1480    domain = None,
1481    quantities = None,
1482    interpolation_points = None,
1483    verbose = False,
1484    use_cache = False}
1485Module: \module{pyvolution.util}
1486
1487Reads the time history of spatial data for
1488specified interpolation points from a NetCDF file (\code{filename})
1489and returns
1490a callable object. \code{filename} could be a \code{sww} file.
1491Returns interpolated values based on the input
1492file using the underlying \code{interpolation\_function}.
1493
1494\code{quantities} is either the name of a single quantity to be
1495interpolated or a list of such quantity names. In the second case, the resulting
1496function will return a tuple of values---one for each quantity.
1497
1498\code{interpolation\_points} is a list of absolute UTM coordinates
1499for points at which values are sought.
1500
1501The model time stored within the file function can be accessed using
1502the method \code{f.get\_time()}
1503\end{funcdesc}
1504
1505%%%
1506\begin{classdesc}{Interpolation\_function}{self,
1507    time,
1508    quantities,
1509    quantity_names = None,
1510    vertex_coordinates = None,
1511    triangles = None,
1512    interpolation_points = None,
1513    verbose = False}
1514Module: \module{pyvolution.least\_squares}
1515
1516Given a time series (i.e. a series of values associated with
1517different times), whose values are either just numbers or a set of
1518numbers defined at the vertices of a triangular mesh (such as those
1519stored in SWW files), \code{Interpolation\_function} is used to
1520create a callable object that interpolates a value for an arbitrary
1521time \code{t} within the model limits and possibly a point \code{(x,
1522y)} within a mesh region.
1523
1524The actual time series at which data is available is specified by
1525means of an array \code{time} of monotonically increasing times. The
1526quantities containing the values to be interpolated are specified in
1527an array---or dictionary of arrays (used in conjunction with the
1528optional argument \code{quantity\_names}) --- called
1529\code{quantities}. The optional arguments \code{vertex\_coordinates}
1530and \code{triangles} represent the spatial mesh associated with the
1531quantity arrays. If omitted the function created by
1532\code{Interpolation\_function} will be a function of \code{t} only.
1533
1534Since, in practice, values need to be computed at specified points,
1535the syntax allows the user to specify, once and for all, a list
1536\code{interpolation\_points} of points at which values are required.
1537In this case, the function may be called using the form \code{f(t,
1538id)}, where \code{id} is an index for the list
1539\code{interpolation\_points}.
1540
1541\end{classdesc}
1542
1543%%%
1544%\begin{funcdesc}{set\_region}{functions}
1545%[Low priority. Will be merged into set\_quantity]
1546
1547%Module:\module{pyvolution.domain}
1548%\end{funcdesc}
1549
1550
1551
1552%%%%%%
1553\section{Boundary Conditions}\index{boundary conditions}
1554
1555\anuga provides a large number of predefined boundary conditions,
1556represented by objects such as \code{Reflective\_boundary(domain)} and
1557\code{Dirichlet\_boundary([0.2, 0.0, 0.0])}, described in the examples
1558in Chapter 2. Alternatively, you may prefer to ``roll your own'',
1559following the method explained in Section \ref{sec:roll your own}.
1560
1561These boundary objects may be used with the function \code{set\_boundary} described below
1562to assign boundary conditions according to the tags used to label boundary segments.
1563
1564\begin{methoddesc}{set\_boundary}{boundary_map}
1565Module: \module{pyvolution.domain}
1566
1567This function allows you to assign a boundary object (corresponding to a
1568pre-defined or user-specified boundary condition) to every boundary segment that
1569has been assigned a particular tag.
1570
1571This is done by specifying a dictionary \code{boundary\_map}, whose values are the boundary objects
1572and whose keys are the symbolic tags.
1573
1574\end{methoddesc}
1575
1576\begin{methoddesc} {get\_boundary\_tags}{}
1577Module: \module{pyvolution.mesh}
1578
1579Returns a list of the available boundary tags.
1580\end{methoddesc}
1581
1582%%%
1583\subsection{Predefined boundary conditions}
1584
1585\begin{classdesc}{Reflective\_boundary}{Boundary}
1586Module: \module{pyvolution.shallow\_water}
1587
1588Reflective boundary returns same conserved quantities as those present in
1589the neighbouring volume but reflected.
1590
1591This class is specific to the shallow water equation as it works with the
1592momentum quantities assumed to be the second and third conserved quantities.
1593\end{classdesc}
1594
1595%%%
1596\begin{classdesc}{Transmissive\_boundary}{domain = None}
1597Module: \module{pyvolution.generic\_boundary\_conditions}
1598
1599A transmissive boundary returns the same conserved quantities as
1600those present in the neighbouring volume.
1601
1602The underlying domain must be specified when the boundary is instantiated.
1603\end{classdesc}
1604
1605%%%
1606\begin{classdesc}{Dirichlet\_boundary}{conserved_quantities=None}
1607Module: \module{pyvolution.generic\_boundary\_conditions}
1608
1609A Dirichlet boundary returns constant values for each of conserved
1610quantities. In the example of \code{Dirichlet\_boundary([0.2, 0.0, 0.0])},
1611the \code{stage} value at the boundary is 0.2 and the \code{xmomentum} and
1612\code{ymomentum} at the boundary are set to 0.0. The list must contain
1613a value for each conserved quantity.
1614\end{classdesc}
1615
1616%%%
1617\begin{classdesc}{Time\_boundary}{domain = None, f = None}
1618Module: \module{pyvolution.generic\_boundary\_conditions}
1619
1620A time-dependent boundary returns values for the conserved
1621quantities as a function \code{f(t)} of time. The user must specify
1622the domain to get access to the model time.
1623\end{classdesc}
1624
1625%%%
1626\begin{classdesc}{File\_boundary}{Boundary}
1627Module: \module{pyvolution.generic\_boundary\_conditions}
1628
1629This method may be used if the user wishes to apply a SWW file or
1630a time series file to a boundary segment or segments.
1631The boundary values are obtained from a file and interpolated to the
1632appropriate segments for each conserved quantity.
1633\end{classdesc}
1634
1635
1636
1637%%%
1638\begin{classdesc}{Transmissive\_Momentum\_Set\_Stage\_boundary}{Boundary}
1639Module: \module{pyvolution.shallow\_water}
1640
1641This boundary returns same momentum conserved quantities as
1642those present in its neighbour volume but sets stage as in a Time\_boundary.
1643The underlying domain must be specified when boundary is instantiated
1644
1645This type of boundary is useful when stage is known at the boundary as a
1646function of time, but momenta (or speeds) aren't.
1647
1648This class is specific to the shallow water equation as it works with the
1649momentum quantities assumed to be the second and third conserved quantities.
1650\end{classdesc}
1651
1652
1653
1654\subsection{User-defined boundary conditions}
1655\label{sec:roll your own}
1656[How to roll your own] TBA
1657
1658
1659
1660
1661
1662\section{Forcing Functions}
1663
1664\anuga provides a number of predefined forcing functions to be used with .....
1665
1666%\begin{itemize}
1667
1668
1669%  \item \indexedcode{}
1670%  [function, arguments]
1671
1672%  \item \indexedcode{}
1673
1674%\end{itemize}
1675
1676
1677
1678\section{Evolution}\index{evolution}
1679
1680  \begin{methoddesc}{evolve}{yieldstep = None, finaltime = None, duration = None, skip_initial_step = False}
1681
1682  Module: \module{pyvolution.domain}
1683
1684  This function (a method of \class{domain}) is invoked once all the
1685  preliminaries have been completed, and causes the model to progress
1686  through successive steps in its evolution, storing results and
1687  outputting statistics whenever a user-specified period
1688  \code{yieldstep} is completed (generally during this period the
1689  model will evolve through several steps internally
1690  as the method forces the water speed to be calculated
1691  on successive new cells). The user
1692  specifies the total time period over which the evolution is to take
1693  place, by specifying values (in seconds) for either \code{duration}
1694  or \code{finaltime}, as well as the interval in seconds after which
1695  results are to be stored and statistics output.
1696
1697  You can include \method{evolve} in a statement of the type:
1698
1699  {\small \begin{verbatim}
1700      for t in domain.evolve(yieldstep, finaltime):
1701          <Do something with domain and t>
1702  \end{verbatim}}
1703
1704  \end{methoddesc}
1705
1706
1707
1708\subsection{Diagnostics}
1709
1710
1711  \begin{funcdesc}{statistics}{}
1712  Module: \module{pyvolution.domain}
1713
1714  \end{funcdesc}
1715
1716  \begin{funcdesc}{timestepping\_statistics}{}
1717  Module: \module{pyvolution.domain}
1718
1719  Returns a string of the following type for each
1720  timestep:
1721
1722  \code{Time = 0.9000, delta t in [0.00598964, 0.01177388], steps=12
1723  (12)}
1724
1725  Here the numbers in \code{steps=12 (12)} indicate the number of steps taken and
1726  the number of first-order steps, respectively.
1727  \end{funcdesc}
1728
1729
1730  \begin{funcdesc}{boundary\_statistics}{quantities = None, tags = None}
1731  Module: \module{pyvolution.domain}
1732
1733  Returns a string of the following type when \code{quantities = 'stage'} and \code{tags = ['top', 'bottom']}:
1734
1735  {\small \begin{verbatim}
1736 Boundary values at time 0.5000:
1737    top:
1738        stage in [ -0.25821218,  -0.02499998]
1739    bottom:
1740        stage in [ -0.27098821,  -0.02499974]
1741  \end{verbatim}}
1742
1743  \end{funcdesc}
1744
1745
1746  \begin{funcdesc}{get\_quantity}{name, location='vertices', indices = None}
1747  Module: \module{pyvolution.domain}
1748  Allow access to individual quantities and their methods
1749
1750  \end{funcdesc}
1751
1752
1753  \begin{funcdesc}{get\_values}{location='vertices', indices = None}
1754  Module: \module{pyvolution.quantity}
1755
1756  Extract values for quantity as an array
1757
1758  \end{funcdesc}
1759
1760
1761  \begin{funcdesc}{get\_integral}{}
1762  Module: \module{pyvolution.quantity}
1763
1764  Return computed integral over entire domain for this quantity
1765
1766  \end{funcdesc}
1767
1768
1769\section{Other}
1770
1771  \begin{funcdesc}{domain.create\_quantity\_from\_expression}{???}
1772
1773  Handy for creating derived quantities on-the-fly.
1774  See \file{Analytical\_solution\_circular\_hydraulic\_jump.py} for an example of use.
1775  \end{funcdesc}
1776
1777
1778
1779
1780
1781%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1782%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1783
1784\chapter{\anuga System Architecture}
1785
1786From pyvolution/documentation
1787
1788\section{File Formats}
1789\label{sec:file formats}
1790
1791\anuga makes use of a number of different file formats. The
1792following table lists all these formats, which are described in more
1793detail in the paragraphs below.
1794
1795\bigskip
1796
1797\begin{center}
1798
1799\begin{tabular}{|ll|}  \hline
1800
1801\textbf{Extension} & \textbf{Description} \\
1802\hline\hline
1803
1804\code{.sww} & NetCDF format for storing model output
1805\code{f(t,x,y)}\\
1806
1807\code{.tms} & NetCDF format for storing time series \code{f(t)}\\
1808
1809\code{.xya} & ASCII format for storing arbitrary points and
1810associated attributes\\
1811
1812\code{.pts} & NetCDF format for storing arbitrary points and
1813associated attributes\\
1814
1815\code{.asc} & ASCII format of regular DEMs as output from ArcView\\
1816
1817\code{.prj} & Associated ArcView file giving more metadata for
1818\code{.asc} format\\
1819
1820\code{.ers} & ERMapper header format of regular DEMs for ArcView\\
1821
1822\code{.dem} & NetCDF representation of regular DEM data\\
1823
1824\code{.tsh} & ASCII format for storing meshes and associated
1825boundary and region info\\
1826
1827\code{.msh} & NetCDF format for storing meshes and associated
1828boundary and region info\\
1829
1830\code{.nc} & Native ferret NetCDF format\\
1831
1832\code{.geo} & Houdinis ASCII geometry format (?) \\  \par \hline
1833%\caption{File formats used by \anuga}
1834\end{tabular}
1835
1836
1837\end{center}
1838
1839The above table shows the file extensions used to identify the
1840formats of files. However, typically, in referring to a format we
1841capitalise the extension and omit the initial full stop---thus, we
1842refer, for example, to `SWW files' or `PRJ files'.
1843
1844\bigskip
1845
1846A typical dataflow can be described as follows:
1847
1848\subsection{Manually Created Files}
1849
1850\begin{tabular}{ll}
1851ASC, PRJ & Digital elevation models (gridded)\\
1852NC & Model outputs for use as boundary conditions (e.g. from MOST)
1853\end{tabular}
1854
1855\subsection{Automatically Created Files}
1856
1857\begin{tabular}{ll}
1858ASC, PRJ  $\rightarrow$  DEM  $\rightarrow$  PTS & Convert
1859DEMs to native \code{.pts} file\\
1860
1861NC $\rightarrow$ SWW & Convert MOST boundary files to
1862boundary \code{.sww}\\
1863
1864PTS + TSH $\rightarrow$ TSH with elevation & Least squares fit\\
1865
1866TSH $\rightarrow$ SWW & Convert TSH to \code{.sww}-viewable using
1867Swollen\\
1868
1869TSH + Boundary SWW $\rightarrow$ SWW & Simulation using
1870\code{pyvolution}\\
1871
1872Polygonal mesh outline $\rightarrow$ & TSH or MSH
1873\end{tabular}
1874
1875
1876
1877
1878\bigskip
1879
1880\subsection{SWW and TMS Formats}
1881
1882The SWW and TMS formats are both NetCDF formats, and are of key
1883importance for \anuga.
1884
1885An SWW file is used for storing \anuga output and therefore pertains
1886to a set of points and a set of times at which a model is evaluated.
1887It contains, in addition to dimension information, the following
1888variables:
1889
1890\begin{itemize}
1891    \item \code{x} and \code{y}: coordinates of the points, represented as Numeric arrays
1892    \item \code{elevation}, a Numeric array storing bed-elevations
1893    \item \code{volumes}, a list specifying the points at the vertices of each of the
1894    triangles
1895    % Refer here to the example to be provided in describing the simple example
1896    \item \code{time}, a Numeric array containing times for model
1897    evaluation
1898\end{itemize}
1899
1900
1901The contents of an SWW file may be viewed using the visualisation
1902tool \code{swollen}, which creates an on-screen geometric
1903representation. See section \ref{sec:swollen} (page
1904\pageref{sec:swollen}) in Appendix \ref{ch:supportingtools} for more
1905on \code{swollen}.
1906
1907Alternatively, there are tools, such as \code{ncdump}, that allow
1908you to convert an NetCDF file into a readable format such as the
1909Class Definition Language (CDL). The following is an excerpt from a
1910CDL representation of the output file \file{bedslope.sww} generated
1911from running the simple example \file{runup.py} of
1912Chapter \ref{ch:getstarted}:
1913
1914\verbatiminput{examples/bedslopeexcerpt.cdl}
1915
1916The SWW format is used not only for output but also serves as input
1917for functions such as \function{file\_boundary} and
1918\function{file\_function}, described in Chapter \ref{ch:interface}.
1919
1920A TMS file is used to store time series data that is independent of
1921position.
1922
1923
1924\subsection{Mesh File Formats}
1925
1926A mesh file is a file that has a specific format suited to
1927triangular meshes and their outlines. A mesh file can have one of
1928two formats: it can be either a TSH file, which is an ASCII file, or
1929an MSH file, which is a NetCDF file. A mesh file can be generated
1930from the function \function{create\_mesh\_from\_regions} (see
1931Section \ref{sec:meshgeneration}) and used to initialise a domain.
1932
1933A mesh file can define the outline of the mesh---the vertices and
1934line segments that enclose the region in which the mesh is
1935created---and the triangular mesh itself, which is specified by
1936listing the triangles and their vertices, and the segments, which
1937are those sides of the triangles that are associated with boundary
1938conditions.
1939
1940In addition, a mesh file may contain `holes' and/or `regions'. A
1941hole represents an area where no mesh is to be created, while a
1942region is a labelled area used for defining properties of a mesh,
1943such as friction values.  A hole or region is specified by a point
1944and bounded by a number of segments that enclose that point.
1945
1946A mesh file can also contain a georeference, which describes an
1947offset to be applied to $x$ and $y$ values---eg to the vertices.
1948
1949
1950\subsection{Formats for Storing Arbitrary Points and Attributes}
1951
1952An XYA file is used to store data representing arbitrary numerical
1953attributes associated with a set of points.
1954
1955The format for an XYA file is:\\
1956%\begin{verbatim}
1957
1958            first line:     \code{[attribute names]}\\
1959            other lines:  \code{x y [attributes]}\\
1960
1961            for example:\\
1962            \code{elevation, friction}\\
1963            \code{0.6, 0.7, 4.9, 0.3}\\
1964            \code{1.9, 2.8, 5, 0.3}\\
1965            \code{2.7, 2.4, 5.2, 0.3}
1966
1967        The first two columns are always implicitly assumed to be $x$, $y$ coordinates.
1968        Use the same delimiter for the attribute names and the data.
1969
1970        An XYA file can optionally end with a description of the georeference:
1971
1972            \code{\#geo reference}\\
1973            \code{56}\\
1974            \code{466600.0}\\
1975            \code{8644444.0}
1976
1977        Here the first number specifies the UTM zone (in this case zone 56)  and other numbers specify the
1978        easting and northing
1979        coordinates (in this case (466600.0, 8644444.0)) of the lower left corner.
1980
1981A PTS file is a NetCDF representation of the data held in an XYA
1982file. If the data is associated with a set of $N$ points, then the
1983data is stored using an $N \times 2$ Numeric array of float
1984variables for the points and an $N \times 1$ Numeric array for each
1985attribute.
1986
1987%\end{verbatim}
1988
1989\subsection{ArcView Formats}
1990
1991Files of the three formats ASC, PRJ and ERS are all associated with
1992data from ArcView.
1993
1994An ASC file is an ASCII representation of DEM output from ArcView.
1995It contains a header with the following format:
1996
1997\begin{tabular}{l l}
1998\code{ncols}      &   \code{753}\\
1999\code{nrows}      &   \code{766}\\
2000\code{xllcorner}  &   \code{314036.58727982}\\
2001\code{yllcorner}  & \code{6224951.2960092}\\
2002\code{cellsize}   & \code{100}\\
2003\code{NODATA_value} & \code{-9999}
2004\end{tabular}
2005
2006The remainder of the file contains the elevation data for each grid point
2007in the grid defined by the above information.
2008
2009A PRJ file is an ArcView file used in conjunction with an ASC file
2010to represent metadata for a DEM.
2011
2012
2013\subsection{DEM Format}
2014
2015A DEM file is a NetCDF representation of regular DEM data.
2016
2017
2018\subsection{Other Formats}
2019
2020
2021
2022
2023\subsection{Basic File Conversions}
2024
2025  \begin{funcdesc}{sww2dem}{basename_in, basename_out = None,
2026            quantity = None,
2027            timestep = None,
2028            reduction = None,
2029            cellsize = 10,
2030            NODATA_value = -9999,
2031            easting_min = None,
2032            easting_max = None,
2033            northing_min = None,
2034            northing_max = None,
2035            expand_search = False,
2036            verbose = False,
2037            origin = None,
2038            datum = 'WGS84',
2039            format = 'ers'}
2040  Module: \module{pyvolution.data\_manager}
2041
2042  Takes data from an SWW file \code{basename_in} and converts it to DEM format (ASC or
2043  ERS) of a desired grid size \code{cellsize} in metres.
2044  The easting and northing values are used if the user wished to clip the output
2045  file to a specified rectangular area. The \code{reduction} input refers to a function
2046  to reduce the quantities over all time step of the SWW file, example, maximum.
2047  \end{funcdesc}
2048
2049
2050  \begin{funcdesc}{dem2pts}{basename_in, basename_out=None,
2051            easting_min=None, easting_max=None,
2052            northing_min=None, northing_max=None,
2053            use_cache=False, verbose=False}
2054  Module: \module{pyvolution.data\_manager}
2055
2056  Takes DEM data (a NetCDF file representation of data from a regular Digital
2057  Elevation Model) and converts it to PTS format.
2058  \end{funcdesc}
2059
2060
2061
2062%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2064
2065\chapter{Basic \anuga Assumptions}
2066
2067(From pyvolution/documentation)
2068
2069
2070Physical model time cannot be earlier than 1 Jan 1970 00:00:00.
2071If one wished to recreate scenarios prior to that date it must be done
2072using some relative time (e.g. 0).
2073
2074
2075All spatial data relates to the WGS84 datum (or GDA94) and has been
2076projected into UTM with false easting of 500000 and false northing of
20771000000 on the southern hemisphere (0 on the northern).
2078
2079It is assumed that all computations take place within one UTM zone.
2080
2081DEMs, meshes and boundary conditions can have different origins within
2082one UTM zone. However, the computation will use that of the mesh for
2083numerical stability.
2084
2085
2086%OLD
2087%The dataflow is: (See data_manager.py and from scenarios)
2088%
2089%
2090%Simulation scenarios
2091%--------------------%
2092%%
2093%
2094%Sub directories contain scrips and derived files for each simulation.
2095%The directory ../source_data contains large source files such as
2096%DEMs provided externally as well as MOST tsunami simulations to be used
2097%as boundary conditions.
2098%
2099%Manual steps are:
2100%  Creation of DEMs from argcview (.asc + .prj)
2101%  Creation of mesh from pmesh (.tsh)
2102%  Creation of tsunami simulations from MOST (.nc)
2103%%
2104%
2105%Typical scripted steps are%
2106%
2107%  prepare_dem.py:  Convert asc and prj files supplied by arcview to
2108%                   native dem and pts formats%
2109%
2110%  prepare_pts.py: Convert netcdf output from MOST to an sww file suitable
2111%                  as boundary condition%
2112%
2113%  prepare_mesh.py: Merge DEM (pts) and mesh (tsh) using least squares
2114%                   smoothing. The outputs are tsh files with elevation data.%
2115%
2116%  run_simulation.py: Use the above together with various parameters to
2117%                     run inundation simulation.
2118
2119
2120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2122
2123\appendix
2124
2125\chapter{Supporting Tools}
2126\label{ch:supportingtools}
2127
2128This section describes a number of supporting tools, supplied with \anuga, that offer a
2129variety of types of functionality and enhance the basic capabilities of \anuga.
2130
2131\section{caching}
2132\label{sec:caching}
2133
2134The \code{cache} function is used to provide supervised caching of function
2135results. A Python function call of the form
2136
2137      {\small \begin{verbatim}
2138      result = func(arg1,...,argn)
2139      \end{verbatim}}
2140
2141  can be replaced by
2142
2143      {\small \begin{verbatim}
2144      from caching import cache
2145      result = cache(func,(arg1,...,argn))
2146      \end{verbatim}}
2147
2148  which returns the same output but reuses cached
2149  results if the function has been computed previously in the same context.
2150  \code{result} and the arguments can be simple types, tuples, list, dictionaries or
2151  objects, but not unhashable types such as functions or open file objects.
2152  The function \code{func} may be a member function of an object or a module.
2153
2154  This type of caching is particularly useful for computationally intensive
2155  functions with few frequently used combinations of input arguments. Note that
2156  if the inputs or output are very large caching may not save time because
2157  disc access may dominate the execution time.
2158
2159  If the function definition changes after a result has been cached, this will be
2160  detected by examining the functions \code{bytecode (co\_code, co\_consts,
2161  func\_defaults, co\_argcount)} and the function will be recomputed.
2162  However, caching will not detect changes in modules used by \code{func}.
2163  In this case cache must be cleared manually.
2164
2165  Options are set by means of the function \code{set\_option(key, value)},
2166  where \code{key} is a key associated with a
2167  Python dictionary \code{options}. This dictionary stores settings such as the name of
2168  the directory used, the maximum
2169  number of cached files allowed, and so on.
2170
2171  The \code{cache} function allows the user also to specify a list of dependent files. If any of these
2172  have been changed, the function is recomputed and the results stored again.
2173
2174  %Other features include support for compression and a capability to \ldots
2175
2176
2177   \textbf{USAGE:} \nopagebreak
2178
2179    {\small \begin{verbatim}
2180    result = cache(func, args, kwargs, dependencies, cachedir, verbose,
2181                   compression, evaluate, test, return_filename)
2182    \end{verbatim}}
2183
2184
2185\section{swollen}
2186\label{sec:swollen}
2187 The output generated by \anuga may be viewed by
2188means of the visualisation tool \code{swollen}, which takes the
2189\code{SWW} file output by \anuga and creates a visual representation
2190of the data. Examples may be seen in Figures \ref{fig:runupstart}
2191and \ref{fig:bedslope2}. To view an \code{SWW} file with
2192\code{swollen} in the Windows environment, you can simply drag the
2193icon representing the file over an icon on the desktop for the
2194\code{swollen} executable file (or a shortcut to it), or set up a
2195file association to make files with the extension \code{.sww} open
2196with \code{swollen}. Alternatively, you can operate \code{swollen}
2197from the command line, in both Windows and Linux environments.
2198
2199On successful operation, you will see an interactive moving-picture
2200display. You can use keys and the mouse to slow down, speed up or
2201stop the display, change the viewing position or carry out a number
2202of other simple operations. Help is also displayed when you press
2203the \code{h} key.
2204
2205The main keys operating the interactive screen are:\\
2206
2207\begin{center}
2208\begin{tabular}{|ll|}   \hline
2209
2210\code{w} & toggle wireframe \\
2211
2212space bar & start/stop\\
2213
2214up/down arrows & increase/decrease speed\\
2215
2216left/right arrows & direction in time \emph{(when running)}\\
2217& step through simulation \emph{(when stopped)}\\
2218
2219left mouse button & rotate\\
2220
2221middle mouse button & pan\\
2222
2223right mouse button & zoom\\  \hline
2224
2225\end{tabular}
2226\end{center}
2227
2228\vfill
2229
2230The following table describes how to operate swollen from the command line:
2231
2232Usage: \code{swollen [options] swwfile \ldots}\\  \nopagebreak
2233Options:\\  \nopagebreak
2234\begin{tabular}{ll}
2235  \code{--display <type>} & \code{MONITOR | POWERWALL | REALITY\_CENTER |}\\
2236                                    & \code{HEAD\_MOUNTED\_DISPLAY}\\
2237  \code{--rgba} & Request a RGBA colour buffer visual\\
2238  \code{--stencil} & Request a stencil buffer visual\\
2239  \code{--stereo} & Use default stereo mode which is \code{ANAGLYPHIC} if not \\
2240                                    & overridden by environmental variable\\
2241  \code{--stereo <mode>} & \code{ANAGLYPHIC | QUAD\_BUFFER | HORIZONTAL\_SPLIT |}\\
2242                                    & \code{VERTICAL\_SPLIT | LEFT\_EYE | RIGHT\_EYE |}\\
2243                                     & \code{ON | OFF} \\
2244  \code{-alphamax <float 0-1>} & Maximum transparency clamp value\\
2245  \code{-alphamin <float 0-1>} & Transparency value at \code{hmin}\\
2246\end{tabular}
2247
2248\begin{tabular}{ll}
2249  \code{-cullangle <float angle 0-90>} & Cull triangles steeper than this value\\
2250  \code{-help} & Display this information\\
2251  \code{-hmax <float>} & Height above which transparency is set to
2252                                     \code{alphamax}\\
2253\end{tabular}
2254
2255\begin{tabular}{ll}
2256
2257  \code{-hmin <float>} & Height below which transparency is set to
2258                                     zero\\
2259\end{tabular}
2260
2261\begin{tabular}{ll}
2262  \code{-lightpos <float>,<float>,<float>} & $x,y,z$ of bedslope directional light ($z$ is
2263                                     up, default is overhead)\\
2264\end{tabular}
2265
2266\begin{tabular}{ll}
2267  \code{-loop}  & Repeated (looped) playback of \code{.swm} files\\
2268
2269\end{tabular}
2270
2271\begin{tabular}{ll}
2272  \code{-movie <dirname>} & Save numbered images to named directory and
2273                                     quit\\
2274
2275  \code{-nosky} & Omit background sky\\
2276
2277
2278  \code{-scale <float>} & Vertical scale factor\\
2279  \code{-texture <file>} & Image to use for bedslope topography\\
2280  \code{-tps <rate>} & Timesteps per second\\
2281  \code{-version} & Revision number and creation (not compile)
2282                                     date\\
2283\end{tabular}
2284
2285\section{utilities/polygons}
2286
2287  \declaremodule{standard}{utilities.polygon}
2288  \refmodindex{utilities.polygon}
2289
2290  \begin{classdesc}{Polygon\_function}{regions, default = 0.0, geo_reference = None}
2291  Module: \code{utilities.polygon}
2292
2293  Creates a callable object that returns one of a specified list of values when
2294  evaluated at a point \code{x, y}, depending on which polygon, from a specified list of polygons, the
2295  point belongs to. The parameter \code{regions} is a list of pairs
2296  \code{(P, v)}, where each \code{P} is a polygon and each \code{v}
2297  is either a constant value or a function of coordinates \code{x}
2298  and \code{y}, specifying the return value for a point inside \code{P}. The
2299  optional parameter \code{default} may be used to specify a value
2300  for a point not lying inside any of the specified polygons. When a
2301  point lies in more than one polygon, the return value is taken to
2302  be the value for whichever of these polygon appears later in the
2303  list.
2304  %FIXME (Howard): CAN x, y BE VECTORS?
2305
2306  \end{classdesc}
2307
2308  \begin{funcdesc}{read\_polygon}{filename}
2309  Module: \code{utilities.polygon}
2310
2311  Reads the specified file and returns a polygon. Each
2312  line of the file must contain exactly two numbers, separated by a comma, which are interpreted
2313  as coordinates of one vertex of the polygon.
2314  \end{funcdesc}
2315
2316  \begin{funcdesc}{populate\_polygon}{polygon, number_of_points, seed = None, exclude = None}
2317  Module: \code{utilities.polygon}
2318
2319  Populates the interior of the specified polygon with the specified number of points,
2320  selected by means of a uniform distribution function.
2321  \end{funcdesc}
2322
2323  \begin{funcdesc}{point\_in\_polygon}{polygon, delta=1e-8}
2324  Module: \code{utilities.polygon}
2325
2326  Returns a point inside the specified polygon and close to the edge. The distance between
2327  the returned point and the nearest point of the polygon is less than $\sqrt{2}$ times the
2328  second argument \code{delta}, which is taken as $10^{-8}$ by default.
2329  \end{funcdesc}
2330
2331  \begin{funcdesc}{inside\_polygon}{points, polygon, closed = True, verbose = False}
2332  Module: \code{utilities.polygon}
2333
2334  Used to test whether the members of a list of points
2335  are inside the specified polygon. Returns a Numeric
2336  array comprising the indices of the points in the list that lie inside the polygon.
2337  (If none of the points are inside, returns \code{zeros((0,), 'l')}.)
2338  Points on the edges of the polygon are regarded as inside if
2339  \code{closed} is set to \code{True} or omitted; otherwise they are regarded as outside.
2340  \end{funcdesc}
2341
2342  \begin{funcdesc}{outside\_polygon}{points, polygon, closed = True, verbose = False}
2343  Module: \code{utilities.polygon}
2344
2345  Exactly like \code{inside\_polygon}, but with the words `inside' and `outside' interchanged.
2346  \end{funcdesc}
2347
2348  \begin{funcdesc}{is\_inside\_polygon}{point, polygon, closed=True, verbose=False}
2349  Module: \code{utilities.polygon}
2350
2351  Returns \code{True} if \code{point} is inside \code{polygon} or
2352  \code{False} otherwise. Points on the edges of the polygon are regarded as inside if
2353  \code{closed} is set to \code{True} or omitted; otherwise they are regarded as outside.
2354  \end{funcdesc}
2355
2356  \begin{funcdesc}{is\_outside\_polygon}{point, polygon, closed=True, verbose=False}
2357  Module: \code{utilities.polygon}
2358
2359  Exactly like \code{is\_outside\_polygon}, but with the words `inside' and `outside' interchanged.
2360  \end{funcdesc}
2361
2362  \begin{funcdesc}{point\_on\_line}{x, y, x0, y0, x1, y1}
2363  Module: \code{utilities.polygon}
2364
2365  Returns \code{True} or \code{False}, depending on whether the point with coordinates
2366  \code{x, y} is on the line passing through the points with coordinates \code{x0, y0}
2367  and \code{x1, y1} (extended if necessary at either end).
2368  \end{funcdesc}
2369
2370  \begin{funcdesc}{separate\_points\_by\_polygon}{points, polygon, closed = True, verbose = False}
2371    \indexedcode{separate\_points\_by\_polygon}
2372  Module: \code{utilities.polygon}
2373
2374  \end{funcdesc}
2375
2376  \begin{funcdesc}{polygon\_area}{polygon}
2377  Module: \code{utilities.polygon}
2378
2379  Returns area of arbitrary polygon (reference http://mathworld.wolfram.com/PolygonArea.html)
2380  \end{funcdesc}
2381
2382  \begin{funcdesc}{plot\_polygons}{polygons, figname, verbose = False}
2383  Module: \code{utilities.polygon}
2384
2385  Plots each polygon contained in input polygon list, e.g.
2386 \code{polygons = [poly1, poly2, poly3]} where \code{poly1 = [[x11,y11],[x12,y12],[x13,y13]]}
2387 etc.  Each polygon is closed for plotting purposes and subsequent plot saved to \code{figname}.
2388  Returns list containing the minimum and maximum of \code{x} and \code{y},
2389  i.e. \code{[x_{min}, x_{max}, y_{min}, y_{max}]}.
2390  \end{funcdesc}
2391
2392\section{coordinate\_transforms}
2393
2394\section{geospatial\_data}
2395
2396This describes a class that represents arbitrary point data in UTM
2397coordinates along with named attribute values.
2398
2399%FIXME (Ole): This gives a LaTeX error
2400%\declaremodule{standard}{geospatial_data}
2401%\refmodindex{geospatial_data}
2402
2403
2404
2405\begin{classdesc}{Geospatial\_data}
2406  {data_points = None,
2407    attributes = None,
2408    geo_reference = None,
2409    default_attribute_name = None,
2410    file_name = None}
2411Module: \code{geospatial\_data}
2412
2413This class is used to store a set of data points and associated
2414attributes, allowing these to be manipulated by methods defined for
2415the class.
2416
2417The data points are specified either by reading them from a NetCDF
2418or XYA file, identified through the parameter \code{file\_name}, or
2419by providing their \code{x}- and \code{y}-coordinates in metres,
2420either as a sequence of 2-tuples of floats or as an $M \times 2$
2421Numeric array of floats, where $M$ is the number of points.
2422Coordinates are interpreted relative to the origin specified by the
2423object \code{geo\_reference}, which contains data indicating the UTM
2424zone, easting and northing. If \code{geo\_reference} is not
2425specified, a default is used.
2426
2427Attributes are specified through the parameter \code{attributes},
2428set either to a list or array of length $M$ or to a dictionary whose
2429keys are the attribute names and whose values are lists or arrays of
2430length $M$. One of the attributes may be specified as the default
2431attribute, by assigning its name to \code{default\_attribute\_name}.
2432If no value is specified, the default attribute is taken to be the
2433first one.
2434\end{classdesc}
2435
2436
2437\begin{methoddesc}{import\_points\_file}{delimiter = None, verbose = False}
2438
2439\end{methoddesc}
2440
2441
2442\begin{methoddesc}{export\_points\_file}{ofile, absolute=False}
2443
2444\end{methoddesc}
2445
2446
2447\begin{methoddesc}{get\_data\_points}{absolute = True}
2448
2449\end{methoddesc}
2450
2451
2452\begin{methoddesc}{set\_attributes}{attributes}
2453
2454\end{methoddesc}
2455
2456
2457\begin{methoddesc}{get\_attributes}{attribute_name = None}
2458
2459\end{methoddesc}
2460
2461
2462\begin{methoddesc}{get\_all\_attributes}{}
2463
2464\end{methoddesc}
2465
2466
2467\begin{methoddesc}{set\_default\_attribute\_name}{default_attribute_name}
2468
2469\end{methoddesc}
2470
2471
2472\begin{methoddesc}{set\_geo\_reference}{geo_reference}
2473
2474\end{methoddesc}
2475
2476
2477\begin{methoddesc}{add}{}
2478
2479\end{methoddesc}
2480
2481
2482\section{pmesh GUI}
2483
2484\section{alpha\_shape}
2485\emph{Alpha shapes} are used to generate close-fitting boundaries
2486around sets of points. The alpha shape algorithm produces a shape
2487that approximates to the `shape formed by the points'---or the shape
2488that would be seen by viewing the points from a coarse enough
2489resolution. For the simplest types of point sets, the alpha shape
2490reduces to the more precise notion of the convex hull. However, for
2491many sets of points the convex hull does not provide a close fit and
2492the alpha shape usually fits more closely to the original point set,
2493offering a better approximation to the shape being sought.
2494
2495In \anuga, an alpha shape is used to generate a polygonal boundary
2496around a set of points before mesh generation. The algorithm uses a
2497parameter $\alpha$ that can be adjusted to make the resultant shape
2498resemble the shape suggested by intuition more closely. An alpha
2499shape can serve as an initial boundary approximation that the user
2500can adjust as needed.
2501
2502The following paragraphs describe the class used to model an alpha
2503shape and some of the important methods and attributes associated
2504with instances of this class.
2505
2506\begin{classdesc}{Alpha\_Shape}{points, alpha = None}
2507Module: \code{alpha\_shape}
2508
2509To instantiate this class the user supplies the points from which
2510the alpha shape is to be created (in the form of a list of 2-tuples
2511\code{[[x1, y1],[x2, y2]}\ldots\code{]}, assigned to the parameter
2512\code{points}) and, optionally, a value for the parameter
2513\code{alpha}. The alpha shape is then computed and the user can then
2514retrieve details of the boundary through the attributes defined for
2515the class.
2516\end{classdesc}
2517
2518
2519\begin{funcdesc}{alpha\_shape\_via\_files}{point_file, boundary_file, alpha= None}
2520Module: \code{alpha\_shape}
2521
2522This function reads points from the specified point file
2523\code{point\_file}, computes the associated alpha shape (either
2524using the specified value for \code{alpha} or, if no value is
2525specified, automatically setting it to an optimal value) and outputs
2526the boundary to a file named \code{boundary\_file}. This output file
2527lists the coordinates \code{x, y} of each point in the boundary,
2528using one line per point.
2529\end{funcdesc}
2530
2531
2532\begin{methoddesc}{set\_boundary\_type}{self,raw_boundary=True,
2533                          remove_holes=False,
2534                          smooth_indents=False,
2535                          expand_pinch=False,
2536                          boundary_points_fraction=0.2}
2537Module: \code{alpha\_shape},  Class: \class{Alpha\_Shape}
2538
2539This function sets flags that govern the operation of the algorithm
2540that computes the boundary, as follows:
2541
2542\code{raw\_boundary = True} returns raw boundary, i.e. the regular edges of the
2543                alpha shape.\\
2544\code{remove\_holes = True} removes small holes (`small' is defined by
2545\code{boundary\_points\_fraction})\\
2546\code{smooth\_indents = True} removes sharp triangular indents in
2547boundary\\
2548\code{expand\_pinch = True} tests for pinch-off and
2549corrects---preventing a boundary vertex from having more than two edges.
2550\end{methoddesc}
2551
2552
2553\begin{methoddesc}{get\_boundary}{}
2554Module: \code{alpha\_shape},  Class: \class{Alpha\_Shape}
2555
2556Returns a list of tuples representing the boundary of the alpha
2557shape. Each tuple represents a segment in the boundary by providing
2558the indices of its two endpoints.
2559\end{methoddesc}
2560
2561
2562\begin{methoddesc}{write\_boundary}{file_name}
2563Module: \code{alpha\_shape},  Class: \class{Alpha\_Shape}
2564
2565Writes the list of 2-tuples returned by \code{get\_boundary} to the
2566file \code{file\_name}, using one line per tuple.
2567\end{methoddesc}
2568
2569\section{Numerical Tools}
2570
2571The following table describes some useful numerical functions that
2572may be found in the module \module{utilities.numerical\_tools}:
2573
2574\begin{tabular}{|p{8cm} p{8cm}|}  \hline
2575\code{angle(v1, v2=None)} & Angle between two-dimensional vectors
2576\code{v1} and \code{v2}, or between \code{v1} and the $x$-axis if
2577\code{v2} is \code{None}. Value is in range $0$ to $2\pi$. \\
2578
2579\code{normal\_vector(v)} & Normal vector to \code{v}.\\
2580
2581\code{mean(x)} & Mean value of a vector \code{x}.\\
2582
2583\code{cov(x, y=None)} & Covariance of vectors \code{x} and \code{y}.
2584If \code{y} is \code{None}, returns \code{cov(x, x)}.\\
2585
2586\code{err(x, y=0, n=2, relative=True)} & Relative error of
2587$\parallel$\code{x}$-$\code{y}$\parallel$ to
2588$\parallel$\code{y}$\parallel$ (2-norm if \code{n} = 2 or Max norm
2589if \code{n} = \code{None}). If denominator evaluates to zero or if
2590\code{y}
2591is omitted or if \code{relative = False}, absolute error is returned.\\
2592
2593\code{norm(x)} & 2-norm of \code{x}.\\
2594
2595\code{corr(x, y=None)} & Correlation of \code{x} and \code{y}. If
2596\code{y} is \code{None} returns autocorrelation of \code{x}.\\
2597
2598\code{ensure\_numeric(A, typecode = None)} & Returns a Numeric array
2599for any sequence \code{A}. If \code{A} is already a Numeric array it
2600will be returned unaltered. Otherwise, an attempt is made to convert
2601it to a Numeric array. (Needed because \code{array(A)} can
2602cause memory overflow.)\\
2603
2604\code{histogram(a, bins, relative=False)} & Standard histogram. If
2605\code{relative} is \code{True}, values will be normalised against
2606the total and thus represent frequencies rather than counts.\\
2607
2608\code{create\_bins(data, number\_of\_bins = None)} & Safely create
2609bins for use with histogram. If \code{data} contains only one point
2610or is constant, one bin will be created. If \code{number\_of\_bins}
2611is omitted, 10 bins will be created.\\  \hline
2612
2613\end{tabular}
2614
2615
2616\chapter{Modules available in \anuga}
2617
2618
2619\section{\module{pyvolution.general\_mesh} }
2620\declaremodule[pyvolution.generalmesh]{}{pyvolution.general\_mesh}
2621\label{mod:pyvolution.generalmesh}
2622
2623\section{\module{pyvolution.neighbour\_mesh} }
2624\declaremodule[pyvolution.neighbourmesh]{}{pyvolution.neighbour\_mesh}
2625\label{mod:pyvolution.neighbourmesh}
2626
2627\section{\module{pyvolution.domain} --- Generic module for 2D triangular domains for finite-volume computations of conservation laws}
2628\declaremodule{}{pyvolution.domain}
2629\label{mod:pyvolution.domain}
2630
2631
2632\section{\module{pyvolution.quantity}}
2633\declaremodule{}{pyvolution.quantity}
2634\label{mod:pyvolution.quantity}
2635
2636
2637Class Quantity - Implements values at each triangular element
2638
2639To create:
2640
2641   Quantity(domain, vertex_values)
2642
2643   domain: Associated domain structure. Required.
2644
2645   vertex_values: N x 3 array of values at each vertex for each element.
2646                  Default None
2647
2648   If vertex_values are None Create array of zeros compatible with domain.
2649   Otherwise check that it is compatible with dimenions of domain.
2650   Otherwise raise an exception
2651
2652
2653
2654\section{\module{pyvolution.shallow\_water} --- 2D triangular domains for finite-volume
2655computations of the shallow water wave equation. This module contains a specialisation
2656of class Domain from module domain.py consisting of methods specific to the Shallow Water
2657Wave Equation
2658}
2659\declaremodule[pyvolution.shallowwater]{}{pyvolution.shallow\_water}
2660\label{mod:pyvolution.shallowwater}
2661
2662
2663
2664
2665%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2666
2667\chapter{Frequently Asked Questions}
2668
2669
2670\section{General Questions}
2671
2672\subsubsection{What is \anuga?}
2673
2674\subsubsection{Why is it called \anuga?}
2675
2676\subsubsection{How do I obtain a copy of \anuga?}
2677
2678\subsubsection{What developments are expected for \anuga in the future?}
2679
2680\subsubsection{Are there any published articles about \anuga that I can reference?}
2681
2682\section{Modelling Questions}
2683
2684\subsubsection{Which type of problems are \anuga good for?}
2685
2686\subsubsection{Which type of problems are beyond the scope of \anuga?}
2687
2688\subsubsection{Can I start the simulation at an arbitrary time?}
2689Yes, using \code{domain.set\_time()} you can specify an arbitrary
2690starting time. This is for example useful in conjunction with a
2691file\_boundary, which may start hours before anything hits the model
2692boundary. By assigning a later time for the model to start,
2693computational resources aren't wasted.
2694
2695\subsubsection{Can I change values for any quantity during the simulation?}
2696Yes, using \code{domain.set\_quantity()} inside the domain.evolve
2697loop you can change values of any quantity. This is for example
2698useful if you wish to let the system settle for a while before
2699assigning an initial condition. Another example would be changing
2700the values for elevation to model e.g. erosion.
2701
2702\subsubsection{Can I change boundary conditions during the simulation?}
2703Not sure, but it would be nice :-)
2704
2705\subsubsection{Why does a file\_function return a list of numbers when evaluated?}
2706Currently, file\_function works by returning values for the conserved
2707quantities \code{stage}, \code{xmomentum} and \code{ymomentum} at a given point in time
2708and space as a triplet. To access e.g.\ \code{stage} one must specify element 0 of the
2709triplet returned by file\_function.
2710
2711\subsubsection{Which diagnostics are available to troubleshoot a simulation?}
2712
2713\subsubsection{How do I use a DEM in my simulation?}
2714You use \code{dem2pts} to convert your DEM to the required .pts format. This .pts file is then called
2715when setting the elevation data to the mesh in \code{domain.set_quantity}
2716
2717\subsubsection{What sort of DEM resolution should I use?}
2718Try and work with the \emph{best} you have available. Onshore DEMs
2719are typically available in 25m, 100m and 250m grids. Note, offshore
2720data is often sparse, or non-existent.
2721
2722\subsubsection{What sort of mesh resolution should I use?}
2723The 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,
2724if 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,
2725you need a fine mesh over regions where the DEM changes rapidly, and other areas of significant interest, such as the coast.
2726
2727
2728\subsubsection{How do I tag interior polygons?}
2729At the moment create_mesh_from_regions does not allow interior
2730polygons with symbolic tags. If tags are needed, the interior
2731polygons must be created subsequently. For example, given a filename
2732of polygons representing solid walls (in Arc Ungenerate format) can
2733be tagged as such using the code snippet:
2734\begin{verbatim}
2735  # Create mesh outline with tags
2736  mesh = create_mesh_from_regions(bounding_polygon,
2737                                  boundary_tags=boundary_tags)
2738  # Add buildings outlines with tags set to 'wall'. This would typically
2739  # bind to a Reflective boundary
2740  mesh.import_ungenerate_file(buildings_filename, tag='wall')
2741
2742  # Generate and write mesh to file
2743  mesh.generate_mesh(maximum_triangle_area=max_area)
2744  mesh.export_mesh_file(mesh_filename)
2745\end{verbatim}
2746
2747Note that a mesh object is returned from \code{create_mesh_from_regions}
2748when file name is omitted.
2749
2750\subsubsection{How often should I store the output?}
2751This 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
2752to look in detail at the evolution, then you will need to balance your storage requirements and the duration of the simulation.
2753If 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
2754quantities on a mesh with approximately 300000 triangles on a 2 min interval for 5 hours will result in approximately 350Mb SWW file
2755(as for the \file{run\_sydney\_smf.py} example).
2756
2757\subsection{Boundary Conditions}
2758
2759\subsubsection{How do I create a Dirichlet boundary condition?}
2760
2761A Dirichlet boundary condition sets a constant value for the
2762conserved quantities at the boundaries. A list containing
2763the constant values for stage, xmomentum and ymomentum is constructed
2764and used in the function call, e.g. \code{Dirichlet_boundary([0.2,0.,0.])}
2765
2766\subsubsection{How do I know which boundary tags are available?}
2767The method \code{domain.get\_boundary\_tags()} will return a list of
2768available tags for use with
2769\code{domain.set\_boundary\_condition()}.
2770
2771
2772
2773
2774
2775\chapter{Glossary}
2776
2777\begin{tabular}{|lp{10cm}|c|}  \hline
2778%\begin{tabular}{|llll|}  \hline
2779    \emph{Term} & \emph{Definition} & \emph{Page}\\  \hline
2780
2781    \indexedbold{\anuga} & Name of software (joint development between ANU and
2782    GA) & \pageref{def:anuga}\\
2783
2784    \indexedbold{bathymetry} & offshore elevation &\\
2785
2786    \indexedbold{conserved quantity} & conserved (stage, x and y
2787    momentum) & \\
2788
2789%    \indexedbold{domain} & The domain of a function is the set of all input values to the
2790%    function.&\\
2791
2792    \indexedbold{Digital Elevation Model (DEM)} & DEMs are digital files consisting of points of elevations,
2793sampled systematically at equally spaced intervals.& \\
2794
2795    \indexedbold{Dirichlet boundary} & A boundary condition imposed on a differential equation
2796 that specifies the values the solution is to take on the boundary of the
2797 domain. & \pageref{def:dirichlet boundary}\\
2798
2799    \indexedbold{edge} & A triangular cell within the computational mesh can be depicted
2800    as a set of vertices joined by lines (the edges). & \\
2801
2802    \indexedbold{elevation} & refers to bathymetry and topography &\\
2803
2804    \indexedbold{evolution} & integration of the shallow water wave equations
2805    over time &\\
2806
2807    \indexedbold{finite volume method} & The method evaluates the terms in the shallow water
2808    wave equation as fluxes at the surfaces of each finite volume. Because the
2809    flux entering a given volume is identical to that leaving the adjacent volume,
2810    these methods are conservative. Another advantage of the finite volume method is
2811    that it is easily formulated to allow for unstructured meshes. The method is used
2812    in many computational fluid dynamics packages. & \\
2813
2814    \indexedbold{forcing term} & &\\
2815
2816    \indexedbold{flux} & the amount of flow through the volume per unit
2817    time & \\
2818
2819    \indexedbold{grid} & Evenly spaced mesh & \\
2820
2821    \indexedbold{latitude} & The angular distance on a mericlear north and south of the
2822    equator, expressed in degrees and minutes. & \\
2823
2824    \indexedbold{longitude} & The angular distance east or west, between the meridian
2825    of a particular place on Earth and that of the Prime Meridian (located in Greenwich,
2826    England) expressed in degrees or time.& \\
2827
2828    \indexedbold{Manning friction coefficient} & &\\
2829
2830    \indexedbold{mesh} & Triangulation of domain &\\
2831
2832    \indexedbold{mesh file} & A TSH or MSH file & \pageref{def:mesh file}\\
2833
2834    \indexedbold{NetCDF} & &\\
2835
2836    \indexedbold{northing} & A rectangular (x,y) coordinate measurement of distance
2837    north from a north-south reference line, usually a meridian used as the axis of
2838    origin within a map zone or projection. Northing is a UTM (Universal Transverse
2839    Mercator) coordinate. & \\
2840
2841    \indexedbold{points file} & A PTS or XYA file & \\  \hline
2842
2843    \end{tabular}
2844
2845    \begin{tabular}{|lp{10cm}|c|}  \hline
2846
2847    \indexedbold{polygon} & A sequence of points in the plane. \anuga represents a polygon
2848    either as a list consisting of Python tuples or lists of length 2 or as an $N \times 2$
2849    Numeric array, where $N$ is the number of points.
2850
2851    The unit square, for example, would be represented either as
2852    \code{[ [0,0], [1,0], [1,1], [0,1] ]} or as \code{array( [0,0], [1,0], [1,1],
2853    [0,1] )}.
2854
2855    NOTE: For details refer to the module \module{utilities/polygon.py}. &
2856    \\     \indexedbold{resolution} &  The maximal area of a triangular cell in a
2857    mesh & \\
2858
2859
2860    \indexedbold{reflective boundary} & Models a solid wall. Returns same conserved
2861    quantities as those present in the neighbouring volume but reflected. Specific to the
2862    shallow water equation as it works with the momentum quantities assumed to be the
2863    second and third conserved quantities. & \pageref{def:reflective boundary}\\
2864
2865    \indexedbold{stage} & &\\
2866
2867%    \indexedbold{try this}
2868
2869    \indexedbold{swollen} & visualisation tool used with \anuga & \pageref{sec:swollen}\\
2870
2871    \indexedbold{time boundary} & Returns values for the conserved
2872quantities as a function of time. The user must specify
2873the domain to get access to the model time. & \pageref{def:time boundary}\\
2874
2875    \indexedbold{topography} & onshore elevation &\\
2876
2877    \indexedbold{transmissive boundary} & & \pageref{def:transmissive boundary}\\
2878
2879    \indexedbold{vertex} & A point at which edges meet. & \\
2880
2881    \indexedbold{xmomentum} & conserved quantity (note, two-dimensional SWW equations say
2882    only \code{x} and \code{y} and NOT \code{z}) &\\
2883
2884    \indexedbold{ymomentum}  & conserved quantity & \\  \hline
2885
2886    \end{tabular}
2887
2888
2889%The \code{\e appendix} markup need not be repeated for additional
2890%appendices.
2891
2892
2893%
2894%  The ugly "%begin{latexonly}" pseudo-environments are really just to
2895%  keep LaTeX2HTML quiet during the \renewcommand{} macros; they're
2896%  not really valuable.
2897%
2898%  If you don't want the Module Index, you can remove all of this up
2899%  until the second \input line.
2900%
2901
2902%begin{latexonly}
2903%\renewcommand{\indexname}{Module Index}
2904%end{latexonly}
2905\input{mod\jobname.ind}        % Module Index
2906%
2907%begin{latexonly}
2908%\renewcommand{\indexname}{Index}
2909%end{latexonly}
2910\input{\jobname.ind}            % Index
2911
2912
2913
2914\begin{thebibliography}{99}
2915\bibitem[nielsen2005]{nielsen2005} 
2916{\it Hydrodynamic modelling of coastal inundation}.
2917Nielsen, O., S. Roberts, D. Gray, A. McPherson and A. Hitchman.
2918In Zerger, A. and Argent, R.M. (eds) MODSIM 2005 International Congress on
2919Modelling and Simulation. Modelling and Simulation Society of Australia and
2920New Zealand, December 2005, pp. 518-523. ISBN: 0-9758400-2-9.\\
2921http://www.mssanz.org.au/modsim05/papers/nielsen.pdf
2922
2923
2924
2925
2926\end{thebibliography}{99}
2927
2928\end{document}
Note: See TracBrowser for help on using the repository browser.