Changeset 2434


Ignore:
Timestamp:
Feb 22, 2006, 2:12:54 PM (19 years ago)
Author:
howard
Message:

New material added for Ch 3 and Appendix. A number of other minor changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentation/user_manual/anuga_user_manual.tex

    r2422 r2434  
    8282
    8383Most \anuga components are written in the object-oriented programming
    84 language Python and most users will interact with Anuga by writing
     84language Python and most users will interact with \anuga by writing
    8585small Python programs based on the \anuga library
    8686functions. Computationally intensive components are written for
     
    125125  \item Background (What \anuga does)
    126126  \item A \emph{Getting Started} section
    127   \item Anuga's overall architecture, components and file formats
    128   \item Detailed descriptions of the user interface
     127  \item A detailed description of the public interface
     128  \item \anuga 's overall architecture, components and file formats
     129  \item Assumptions
    129130\end{itemize}
    130131
     
    134135
    135136This section is designed to assist the reader to get started with
    136 \anuga by working through a simple example. What follows
     137\anuga by working through simple examples. Two examples are discussed;
     138the first is a simple but artificial example that is useful to illustrate
     139many of the ideas, and the second is a real-life example.
     140
     141\section{First Example: Overview}
     142
     143What follows
    137144is a discussion of the structure and operation of the file
    138145\code{bedslope.py}, with just enough detail to allow the reader
    139146to appreciate what's involved in setting up a scenario like the
    140147one it depicts.
    141 
    142 \section{Overview}
    143148
    144149This example carries out the solution of the shallow-water wave
     
    180185operation of the model-specifying, for instance, where to store the model output.
    181186
    182 
    183187   \item Inputs various quantities describing physical measurements, such
    184188as the elevation, to be specified at each mesh point (vertex).
     
    195199
    196200%FIXME: we are using the \code function here.
    197 %This should be used whereever possible
     201%This should be used wherever possible
    198202For reference we include below the complete code listing for
    199203\code{bedslope.py}. Subsequent paragraphs provide a `commentary'
     
    291295
    292296
    293 \section{Initialising the domain}
     297\section{Initialising the Domain}
    294298
    295299These variables are then used to set up a data structure
     
    305309some methods from the generic class but has others specific to the
    306310shallow-water scenarios in which it is used. Specific options for domain
    307 are set at this point. One of them are to set the basename for the output file
     311are set at this point. One of them is to set the basename for the output file:
    308312
    309313{\scriptsize \begin{verbatim}
     
    412416    momentum quantities assumed to be the second and third conserved
    413417    quantities.
     418   
    414419    \item[Transmissive boundary]Returns same conserved quantities as
    415420    those present in its neighbour volume.
     421   
    416422    \item[Dirichlet boundary]Specifies a fixed value at the
    417423boundary.
     424
    418425    \item[Time boundary.]A Dirichlet boundary whose behaviour varies with time.
    419426\end{description}
     
    444451series of steps indicated by the values of \code{yieldstep} and
    445452\code{finaltime}, which can be altered as required.
    446 The yieldstep control the time interval between model output. Behind the scenes more timesteps are generally taken.
    447 
    448 
     453The value of \code{yieldstep} controls the time interval between successive model outputs.
     454Behind the scenes more time steps are generally taken.
    449455
    450456
     
    474480
    475481
    476 \section{Example with real data}
     482\section{An Example with Real Data}
    477483
    478484The following discussion builds on the \code{bedslope.py} example and
     
    505511
    506512
    507 \chapter{ANUGA Public Interface}
    508 
    509 thoaedut
    510 
    511 
    512 
    513 \begin{itemize}
    514 
    515   \item \indexedcode{create_mesh_from_region}: Create mesh based on a bounding polygon and a number of internal polygons. Each polygon has a maximal area of triangles associated with it - the resolution. The bounding polygon also has symbolic \code{tags} associated with it.
    516   Arguments are:
    517   \item \indexedcode{pmesh_to_domain_instance}: Convert generated mesh file to domain object. Arguments are: Mesh file name and class specifying which domain class to instantiate. (Simpler)
    518 
    519   \item \indexedcode{file_function} %in util.py "High priority"
    520   \item \indexedcode{Interpolation_function} %In least_squares.py ("High priority")
    521 
    522   \item \indexedcode{set_region} ``Low priority. Will be merged into set\_quantity''
     513\chapter{\anuga Public Interface}
     514
     515This chapter lists the functions and classes available at the public interface.
     516
     517\section{Functions and Classes}
     518
     519\begin{itemize}
     520
     521  \item \indexedcode{create_mesh_from_region}: Creates a triangular mesh based on a bounding polygon and
     522  a number of internal polygons. For each polygon the user specifies a resolution---that is, the maximal area
     523  of triangles in the mesh. The bounding polygon also has symbolic \code{tags} associated with it.   
     524 
     525  \textbf{Arguments:}
     526 
     527  \begin{itemize}
     528 
     529  \item the bounding polygon, %do we need to spell out how a polygon is specified?
     530 
     531  \item a dictionary of boundary tags, for all segments of the bounding polygon,
     532  \emph{[not clear what the keys and values of this dictionary are]}
     533 
     534  \item the resolution for the bounding polygon,
     535 
     536  \item (optional) a filename,  \emph{[what is the file for?]}
     537 
     538  \item a list of 2-tuples \code{(polygon, resolution)}, specifying the interior polygons and their associated
     539  resolutions.
     540 
     541  \end{itemize}
     542 
     543 
     544 
     545  \item \indexedcode{pmesh_to_domain_instance}: Converts a generated mesh file to a domain object.
     546 
     547  \textbf{Arguments:}
     548 
     549  \begin{itemize}
     550 
     551  \item \code{file_name} is the name of the mesh file to convert, including the extension
     552
     553  \item \code{DomainClass} is the Class that will be returned.
     554    It must be a subclass of \code{Domain}, with the same interface as domain.
     555
     556  \item \code{use_cache}: \code{True} means that caching is attempted for the computed domain.
     557   
     558  \end{itemize}
     559 
     560 
     561  \begin{itemize}
     562  \item Mesh file name
     563 
     564  \item Class name, specifying the domain class to be instantiated.
     565  \end{itemize}
     566 
     567  \item \indexedcode{file_function}: %in util.py "High priority"
     568  Reads the time history of spatial data from NetCDF file and returns a callable object.
     569
     570  \textbf{Input variables:}
     571   
     572    \code{filename} - Name of \code{sww} or \code{tms} file
     573       
     574       \begin{quote}
     575       If the file has extension \code{sww} then it is assumed to be spatio-temporal
     576       or temporal and the callable object will have the form \code{f(t,x,y)} or \code{f(t)}
     577       depending on whether the file contains spatial data.
     578
     579       If the file has extension \code{tms} then it is assumed to be temporal only
     580       and the callable object will have the form \code{f(t)}.
     581
     582       Either form will return interpolated values based on the input file
     583       using the underlying \code{interpolation_function}.
     584       \end{quote}
     585
     586    \code{domain} - Associated domain object   
     587       If domain is specified, model time (\code{domain.starttime})
     588       will be checked and possibly modified.
     589   
     590       \begin{quote}
     591       All times are assumed to be in UTC.
     592       
     593       All spatial information is assumed to be in absolute UTM coordinates.
     594       \end{quote}
     595
     596    \code{quantities} - the name of the quantity to be interpolated or a
     597                 list of quantity names. The resulting function will return
     598                 a tuple of values -- one for each quantity. 
     599
     600    \code{interpolation_points} - list of absolute UTM coordinates for points at
     601    which values are sought
     602   
     603    \code{use_cache}: \code{True} means that caching of intermediate result of
     604               \code{Interpolation_function} is attempted
     605
     606   
     607  %  See Interpolation function for further documentation
     608 
     609  \item \indexedcode{Interpolation_function} - creates a callable object \code{f(t, id)} or \code{f(t,x,y)}
     610    which is interpolated from time series defined at vertices of
     611    triangular mesh (such as those stored in \code{sww} files).
     612
     613    Let $m$ be the number of vertices, $n$ the number of triangles
     614    and $p$ the number of time steps.
     615
     616    \textbf{Mandatory input:}
     617   
     618        \begin{tabular}{ll}
     619        \code{time}: & $p \times 1$ array of monotonously increasing times (Float)\\
     620       
     621        \code{quantities}: & Dictionary of arrays or one array (Float). The arrays must  \\
     622        & have dimensions either $p \times m$ or $m \times 1$. The resulting function \\
     623        & will be time dependent in the former case and constant with respect to time \\
     624        & in the latter case.\\
     625        \end{tabular}
     626       
     627       
     628    \textbf{Optional input:}
     629   
     630        \begin{tabular}{ll}
     631        \code{quantity_names}: & List of keys into the quantities dictionary\\
     632       
     633        \code{vertex_coordinates}: & $m \times 2$ array of coordinates (Float)\\
     634       
     635        \code{triangles}: & $n \times 3$ array of indices into \code{vertex_coordinates} (Int)\\
     636       
     637        \code{interpolation_points}: & $N \times 2$ array of coordinates to be interpolated to \\
     638       
     639        \code{verbose}: & Level of reporting\\
     640        \end{tabular}
     641   
     642    The quantities returned by the callable object are specified by
     643    the list quantities which must contain the names of the
     644    quantities to be returned and also reflect the order, e.g. for
     645    the shallow water wave equation, one would have
     646    \code{quantities = ['stage', 'xmomentum', 'ymomentum']}.
     647
     648    The parameter \code{interpolation_points} decides at which points interpolated
     649    quantities are to be computed whenever the object is called.
     650    If \code{None}, returns average value.
     651   
     652
     653  \item \indexedcode{set_region} ``Low priority. Will be merged into set\_quantity''
     654   
    523655  \item \indexedcode{set_quantity} ``Pretty mature''
     656 
    524657  \item \indexedcode{set_boundary} ``Pretty mature''
    525 
    526 \end{itemize}
    527 
    528 
    529 Diagnostics
     658 
     659
     660\end{itemize}
     661
     662\section{Diagnostics}
    530663\begin{itemize}
    531664  \item \indexedcode{write_time}
     
    536669
    537670
    538 \subsection{Boundary conditions}
    539 
    540 ANUGA provides a large number of predefined boundary conditions to be used with
     671\section{Boundary Conditions}
     672
     673\anuga provides a large number of predefined boundary conditions to be used with
    541674\code{set_boundary}
    542675
     
    572705
    573706
    574 \subsection{Initial conditions}
    575 
    576 ANUGA provides a number of predefined initial conditions to be used with
     707\section{Initial Conditions}
     708
     709\anuga provides a number of predefined initial conditions to be used with
    577710\code{set_quantity}.
    578711
     
    588721
    589722
    590 \subsection{Initial conditions}
    591 
    592 ANUGA provides a number of predefined forcing functions to be used with .....
     723\section{Forcing Functions}
     724
     725\anuga provides a number of predefined forcing functions to be used with .....
    593726
    594727\begin{itemize}
     
    605738
    606739
    607 \chapter{ANUGA system architecture}
     740\chapter{\anuga System Architecture}
    608741
    609742From pyvolution/documentation
    610743
    611 
    612 
    613 \chapter{Basic ANUGA assumptions}
     744\section{File Formats}
     745
     746\chapter{Basic \anuga Assumptions}
    614747
    615748(From pyvolution/documentation)
     
    663796%
    664797%  run_simulation.py: Use the above together with various parameters to
    665 %                     run inundation simluation.
     798%                     run inundation simulation.
    666799
    667800
     
    670803\appendix
    671804
    672 \chapter{Supporting tools}
    673 
    674 
    675 \section{caching} Could do now.
    676 
    677 
    678 
    679 \section{swollen} Could do now.
    680 
     805\chapter{Supporting Tools}
     806
     807
     808\section{caching}
     809
     810  The \code{cache} function is used to provide supervised caching of function results. A Python
     811  function call of the form
     812
     813      {\scriptsize \begin{verbatim}
     814      result = func(arg1,...,argn)
     815      \end{verbatim}}
     816
     817  can be replaced by
     818
     819      {\scriptsize \begin{verbatim}
     820      from caching import cache
     821      result = cache(func,(arg1,...,argn))
     822      \end{verbatim}}
     823 
     824  which returns the same output but reuses cached
     825  results if the function has been computed previously in the same context.
     826  \code{result} and the arguments can be simple types, tuples, list, dictionaries or
     827  objects, but not unhashable types such as functions or open file objects.
     828  The function \code{func} may be a member function of an object or a module.
     829
     830  This type of caching is particularly useful for computationally intensive
     831  functions with few frequently used combinations of input arguments. Note that
     832  if the inputs or output are very large caching might not save time because
     833  disc access may dominate the execution time.
     834
     835  If the function definition changes after a result has been cached it will be
     836  detected by examining the functions \code{bytecode (co_code, co_consts,
     837  func_defualts, co_argcount)} and it will be recomputed.
     838 
     839  Options are set
     840  by means of the function \code{set_option(key, value)}, where \code{key} is a key associated with a
     841  Python dictionary \code{options} that stores settings such as the name of the directory used, the maximum
     842  number of cached files allowed, and so on.
     843 
     844  The \code{cache} function allows the user also to specify a list of dependent files. If any of these
     845  have been changed, the function is recomputed and the results stored again.
     846 
     847  Other features include support for compression and a capability to \ldots
     848
     849 
     850   \textbf{USAGE:}
     851 
     852    {\scriptsize \begin{verbatim}
     853    result = cache(func, args, kwargs, dependencies, cachedir, verbose,
     854                   compression, evaluate, test, return_filename)}
     855    \end{verbatim}}
     856
     857  \textbf{ARGUMENTS:}
     858 
     859  \begin{tabular}{ll}
     860    \code{func} & Function object (Required)\\
     861    \code{args} & Arguments to func (Default: ())\\
     862    \code{kwargs} & Keyword arguments to func (Default: {})  \\ 
     863    \code{dependencies} & Filenames that func depends on (Default: \code{None})\\
     864    \code{cachedir} & Directory for cache files (Default: \code{options['cachedir']})\\
     865    \code{verbose} & Flag verbose output to stdout
     866                       (Default: \code{options['verbose']})\\
     867    \code{compression} & Flag zlib compression (Default: \code{options['compression']})\\
     868    \code{evaluate} & Flag forced evaluation of func (Default: 0)\\
     869    \code{test} & Flag test for cached results (Default: 0)\\
     870    \code{clear} & Flag delete cached results (Default: 0)\\   
     871    \code{return_filename} & Flag return of cache filename (Default: 0)\\   
     872  \end{tabular}
     873 
     874
     875  \textbf{LIMITATIONS:}
     876 
     877  \begin{itemize}
     878   \item Caching uses the apply function and will work with anything that can be
     879      pickled, so any limitation in apply or pickle extends to caching.
     880     
     881   \item A function to be cached should not depend on global variables
     882      as wrong results may occur if globals are changed after a result has
     883      been cached.
     884   \end{itemize}
     885
     886 
     887
     888
     889\section{swollen}
     890
     891
     892The main keys operating the interactive screen are:\\
     893
     894\begin{tabular}{|ll|}   \hline
     895
     896\code{w} & toggle wireframe\\
     897
     898space bar & start/stop\\
     899
     900up/down arrows & increase/decrease speed\\
     901
     902left/right arrows & direction in time \emph{(when running)}\\ & step through simulation \emph{(when stopped)}\\
     903
     904left mouse button & rotate\\
     905
     906middle mouse button & pan\\
     907
     908right mouse button & zoom\\  \hline
     909
     910\end{tabular}
     911
     912\vfill
     913
     914The following table describes how to operate swollen from the command line:
     915
     916Usage: \code{swollen [options] swwfile \ldots}\\  \nopagebreak
     917Options:\\  \nopagebreak
     918\begin{tabular}{ll}
     919  \code{--display <type>} & \code{MONITOR | POWERWALL | REALITY_CENTER |}\\
     920                                    & \code{HEAD_MOUNTED_DISPLAY}\\
     921  \code{--rgba} & Request a RGBA colour buffer visual\\
     922  \code{--stencil} & Request a stencil buffer visual\\
     923  \code{--stereo} & Use default stereo mode which is \code{ANAGLYPHIC} if not \\
     924                                    & overridden by environmental variable\\
     925  \code{--stereo <mode>} & \code{ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT |}\\
     926                                    & \code{VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE |}\\
     927                                     & \code{ON | OFF} \\
     928  \code{-alphamax <float 0-1>} & Maximum transparency clamp value\\
     929  \code{-alphamin <float 0-1>} & Transparency value at \code{hmin}\\
     930  \code{-cullangle <float angle 0-90>} & Cull triangles steeper than this value\\
     931  \code{-help} & Display this information\\
     932  \code{-hmax <float>} & Height above which transparency is set to
     933                                     \code{alphamax}\\
     934  \code{-hmin <float>} & Height below which transparency is set to
     935                                     zero\\
     936  \code{-lightpos <float>,<float>,<float>} & $x,y,z$ of bedslope directional light ($z$ is
     937                                     up, default is overhead)\\
     938  \code{-loop}  & Repeated (looped) playback of \code{.swm} files\\
     939  \code{-movie <dirname>} & Save numbered images to named directory and
     940                                     quit\\
     941  \code{-nosky} & Omit background sky\\
     942  \code{-scale <float>} & Vertical scale factor\\
     943  \code{-texture <file>} & Image to use for bedslope topography\\
     944  \code{-tps <rate>} & Timesteps per second\\
     945  \code{-version} & Revision number and creation (not compile)
     946                                     date\\
     947\end{tabular}
    681948
    682949\section{utilities/polygons} Could do now.
     
    717984
    718985\begin{itemize}
    719     \item \indexedbold{ANUGA} name of software (joint development between ANU and GA)
     986    \item \indexedbold{\anuga} name of software (joint development between ANU and GA)
    720987
    721988    \item \indexedbold{Conserved quantity}
     
    7711038    \item \indexedbold{resolution}   refers to the maximal area of each triangular cell in the mesh
    7721039
    773     \item \indexedbold{polygon} A sequence of points in the plane. (Arbitrary polygons can be created in this way )
    774     ANUGA represents polygons as either a list of 2-tuples, where the latter are either Python tuples or Python lists of length 2. The unit square, for example, would be represented by the polygon [ [0,0], [1,0], [1,1], [0,1] ]. Alternatively, polygons can be represented as $N \times 2$ Numeric arrays, where $N$ is the number of points.
     1040    \item \indexedbold{polygon} A sequence of points in the plane. (Arbitrary polygons can be created
     1041    in this way )
     1042    ANUGA represents polygons as either a list of 2-tuples, where the latter are either Python tuples
     1043    or Python lists of length 2. The unit square, for example, would be represented by the polygon
     1044    [ [0,0], [1,0], [1,1], [0,1] ]. Alternatively, polygons can be represented as $N \times 2$ Numeric
     1045    arrays, where $N$ is the number of points.
    7751046
    7761047    NOTE: More can be read in the module utilities/polygon.py ....
Note: See TracChangeset for help on using the changeset viewer.