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