source: documentation/simple_example.tex @ 2264

Last change on this file since 2264 was 2264, checked in by howard, 18 years ago
File size: 8.9 KB
Line 
1\documentclass{article}
2
3\title{A Simple Example}
4%\author{Howard Silcock}
5
6% Can we get rid of indenting and put a blank line before each para?
7% Find out how to change date format
8% Relabel sections, subsections
9
10\setlength{\parindent}{0mm} %\setlength{\parskip}{3pt}
11\setlength{\oddsidemargin}{0.6in}\setlength{\evensidemargin}{0.6in}
12\addtolength{\textheight}{1in} \addtolength{\textwidth}{0.5in}
13\setlength{\marginparwidth}{0in}
14\setlength{\topmargin}{0mm}\setlength{\headheight}{0in}
15
16\begin{document}
17
18\maketitle
19
20%\section*{Discussion of a Simple Example}
21
22This is a discussion of the structure and operation of the file
23\texttt{bedslope.py}, with just enough detail to allow the reader
24to appreciate what's involved in setting up a scenario like the
25one it depicts.
26
27
28\subsection*{Overview}
29
30This example carries out the solution of the shallow-water wave
31equation in the simple case of a configuration comprising a flat
32bed, sloping at a fixed angle in one direction and having a
33constant depth across each line in the perpendicular direction.
34
35The quantities involved in the problem are:
36\begin{itemize}
37   \item elevation
38   \item friction
39   \item depth
40   \item stage
41\end{itemize}
42
43\emph{[More details of the problem background]}
44
45\subsection*{Outline of the Program}
46
47In outline, \texttt{bedslope.py} performs the following steps:
48
49\begin{enumerate}
50
51   \item Sets up a
52triangular mesh.
53
54   \item Sets certain parameters governing the mode of
55operation of the model-specifying, for instance, whether the
56output is to be `smoothed'.
57
58   \item Inputs various quantities describing physical measurements, such
59as the elevation, to be specified at each mesh point.
60
61   \item Sets up the boundary conditions.
62
63   \item Carries out the evolution of the model through a series of time
64steps and outputs the results, providing a results file that can
65be visualised.
66
67\end{enumerate}
68
69
70\subsection*{Establishing the Mesh}
71
72The first task is to set up the triangular mesh to be used for the
73scenario. This is carried out through the statement:
74
75\begin{verbatim}
76    points, vertices, boundary = rectangular(10, 10) .
77\end{verbatim}
78
79The function \texttt{rectangular} is imported from a module
80\texttt{mesh\_factory} defined elsewhere. (AnuGA also contains
81several other schemes that can be used for setting up meshes, but
82we shall not discuss these now.) The above assignment sets up a
83$10 \times 10$ rectangular mesh, triangulated in a specific way.
84In general, the assignment
85
86\begin{verbatim}
87    points, vertices, boundary = rectangular(m, n)
88\end{verbatim}
89
90returns:
91
92\begin{itemize}
93
94   \item a list \texttt{points} of length $N$, where $N = (m + 1)(n + 1)$,
95comprising the coordinates $(x, y)$ of each of the $N$ mesh
96points,
97
98   \item a list \texttt{vertices} of length $2mn$ (each entry specifies the three
99vertices of one of the triangles used in the triangulation) , and
100
101   \item a dictionary \texttt{boundary}, used to tag the triangle edges on
102the boundaries. Each key corresponds to a triangle edge on one of
103the four boundaries and its value is one of \texttt{`left'},
104\texttt{`right'}, \texttt{`top'} and \texttt{`bottom'}, indicating
105which boundary the edge in question belongs to.
106
107\end{itemize}
108
109
110\subsection*{Initialising the domain}
111
112These variables are then used to set up a data structure domain,
113through the assignment:
114
115\begin{verbatim}
116    domain = Domain(points, vertices, boundary)
117\end{verbatim}
118
119This uses a Python class \texttt{Domain}, imported from
120\texttt{shallow\_water}, which is an extension of a more generic
121class of the same name in the module \texttt{domain}, and inherits
122some methods from the generic class but has others specific to the
123shallow-water scenarios in which it is used. The following lines
124set certain key options governing the domain: \emph{[more details
125of what these do]}
126
127\begin{verbatim}
128    domain.smooth = False
129    domain.visualise = False
130    domain.store = True
131    domain.filename = 'bedslope'
132    domain.default_order = 2
133\end{verbatim}
134
135
136\subsection*{Specifying the Quantities}
137
138The next task is to specify a number of quantities that we wish to
139set for each mesh point. The class \texttt{Domain} has a method
140\texttt{set\_quantity}, used to specify these quantities. It is a
141particularly flexible method that allows the user to set
142quantities in a variety of ways---using constants, functions,
143numeric arrays or expressions involving other quantities, all of
144which can be passed as arguments. The code in the present example
145demonstrates a number of forms in which we can invoke
146\texttt{set\_quantity}.
147
148
149\subsubsection*{Elevation}
150
151The elevation is set using a function, defined through the
152statements below, which is specific to this example and specifies
153a particularly simple initial configuration for demonstration
154purposes:
155
156\begin{verbatim}
157    \# Initial conditions
158    def f(x,y):
159        return -x/2
160\end{verbatim}
161
162This simply associates an elevation with each point $(x, y)$ of
163the plane.  It specifies that the bed slopes linearly in the $x$
164direction, with slope $-\frac{1}{2}$,  and is constant in the $y$
165direction. %[screen shot?]\\
166\\
167Once the function $f$ is specified, the quantity is assigned
168through the simple statement:
169
170\begin{verbatim}
171    domain.set_quantity('elevation', f)
172\end{verbatim}
173
174
175\subsubsection*{Friction}
176
177The assignment of the friction quantity demonstrates another way
178we can use \texttt{set\_quantity} to set quantities---namely,
179assign them to a constant numerical value:
180
181\begin{verbatim}
182    domain.set_quantity('friction', 0.1)
183\end{verbatim}
184
185This just specifies that the Manning friction coefficient is set
186to 0.1 at every mesh point.
187
188\subsubsection*{Depth}
189
190Assigning depth illustrates a more complex way to use
191\texttt{set\_quantity}, introducing an expression involving other
192quantities:
193
194\begin{verbatim}
195    h = 0.05 \# Constant depth
196    domain.set_quantity('stage', expression = 'elevation + %f' %h)
197\end{verbatim}
198
199Here the quantity \texttt{stage} is defined by taking the quantity
200elevation already defined and adding a constant value $h = 0.05$
201to it everywhere. This expresses the fact that the water depth is
202everywhere constant, so the surface is a constant height above the
203elevation of the bed.
204
205\subsubsection*{Boundary Conditions}
206
207The boundary conditions are specified as follows:
208
209\begin{verbatim}
210    Br = Reflective_boundary(domain)
211
212    Bt = Transmissive_boundary(domain)
213
214    Bd = Dirichlet_boundary([0.2,0.,0.])
215
216    Bw = Time_boundary(domain=domain,
217                f=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0])
218\end{verbatim}
219
220The effect of these statements is to set up four alternative
221boundary conditions and store them in variables that can be
222assigned as needed. Each boundary condition specifies the
223behaviour at a boundary in terms of the behaviour in neighbouring
224elements. The boundary conditions may be briefly described as
225follows:
226
227\begin{description}
228    \item[Reflective boundary]Returns same conserved
229quantities as those present in its neighbour volume but reflected.
230Specific to the shallow water equation as it works with the
231momentum quantities assumed to be the second and third conserved
232quantities.
233    \item[Transmissive boundary]\emph{[Need to add some suitable text
234here]}
235    \item[Dirichlet boundary]Specifies a fixed value at the
236boundary.
237    \item[Time boundary.]A Dirichlet boundary whose behaviour varies with time.
238\end{description}
239
240Once the four boundary types have been specified through the
241statements above, they can be applied through a statement of the
242form
243
244\begin{verbatim}
245    domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom':
246Br})
247\end{verbatim}
248
249This statement stipulates that, in the current example, the left
250boundary is fixed, with an elevation of 0.2, while the other
251boundaries are all reflective.
252
253
254\subsection*{Evolution}
255
256The final statement
257\nopagebreak[3]
258\begin{verbatim}
259    for t in domain.evolve(yieldstep = 0.1, finaltime = 4.0):
260        domain.write_time()
261\end{verbatim}
262
263is the key step that causes the configuration of the domain to
264`evolve' in accordance with the model embodied in the code, over a
265series of steps indicated by the values of \texttt{yieldstep} and
266\texttt{finaltime}, which can be altered as required.
267
268
269\subsection*{Output}
270
271%Give details here of the form of the output and explain how it can
272%be used with swollen. Include screen shots.//
273
274The output is a NetCDF file with the extension \texttt{.sww}. It
275contains stage and momentum information and can be used with the
276\texttt{swollen} package to generate a visual display.
277
278
279\subsection*{How to Run the Code}
280
281The code can be run in various ways:
282
283\begin{itemize}
284\item{from a Windows command line}
285
286\item{within the Python IDLE environment}
287
288\item{within emacs}
289
290\item{from a Linux command line}
291\end{itemize}
292
293\end{document}
Note: See TracBrowser for help on using the repository browser.