source: documentation/user_manual/anuga_user_manual.tex @ 2693

Last change on this file since 2693 was 2693, checked in by duncan, 18 years ago

added mesh stuff to the user interface

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