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 | |
---|
22 | This is a discussion of the structure and operation of the file |
---|
23 | \texttt{bedslope.py}, with just enough detail to allow the reader |
---|
24 | to appreciate what's involved in setting up a scenario like the |
---|
25 | one it depicts. |
---|
26 | |
---|
27 | |
---|
28 | \subsection*{Overview} |
---|
29 | |
---|
30 | This example carries out the solution of the shallow-water wave |
---|
31 | equation in the simple case of a configuration comprising a flat |
---|
32 | bed, sloping at a fixed angle in one direction and having a |
---|
33 | constant depth across each line in the perpendicular direction. |
---|
34 | |
---|
35 | The 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 | |
---|
47 | In outline, \texttt{bedslope.py} performs the following steps: |
---|
48 | |
---|
49 | \begin{enumerate} |
---|
50 | |
---|
51 | \item Sets up a |
---|
52 | triangular mesh. |
---|
53 | |
---|
54 | \item Sets certain parameters governing the mode of |
---|
55 | operation of the model-specifying, for instance, whether the |
---|
56 | output is to be `smoothed'. |
---|
57 | |
---|
58 | \item Inputs various quantities describing physical measurements, such |
---|
59 | as 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 |
---|
64 | steps and outputs the results, providing a results file that can |
---|
65 | be visualised. |
---|
66 | |
---|
67 | \end{enumerate} |
---|
68 | |
---|
69 | |
---|
70 | \subsection*{Establishing the Mesh} |
---|
71 | |
---|
72 | The first task is to set up the triangular mesh to be used for the |
---|
73 | scenario. This is carried out through the statement: |
---|
74 | |
---|
75 | \begin{verbatim} |
---|
76 | points, vertices, boundary = rectangular(10, 10) . |
---|
77 | \end{verbatim} |
---|
78 | |
---|
79 | The function \texttt{rectangular} is imported from a module |
---|
80 | \texttt{mesh\_factory} defined elsewhere. (AnuGA also contains |
---|
81 | several other schemes that can be used for setting up meshes, but |
---|
82 | we shall not discuss these now.) The above assignment sets up a |
---|
83 | $10 \times 10$ rectangular mesh, triangulated in a specific way. |
---|
84 | In general, the assignment |
---|
85 | |
---|
86 | \begin{verbatim} |
---|
87 | points, vertices, boundary = rectangular(m, n) |
---|
88 | \end{verbatim} |
---|
89 | |
---|
90 | returns: |
---|
91 | |
---|
92 | \begin{itemize} |
---|
93 | |
---|
94 | \item a list \texttt{points} of length $N$, where $N = (m + 1)(n + 1)$, |
---|
95 | comprising the coordinates $(x, y)$ of each of the $N$ mesh |
---|
96 | points, |
---|
97 | |
---|
98 | \item a list \texttt{vertices} of length $2mn$ (each entry specifies the three |
---|
99 | vertices of one of the triangles used in the triangulation) , and |
---|
100 | |
---|
101 | \item a dictionary \texttt{boundary}, used to tag the triangle edges on |
---|
102 | the boundaries. Each key corresponds to a triangle edge on one of |
---|
103 | the four boundaries and its value is one of \texttt{`left'}, |
---|
104 | \texttt{`right'}, \texttt{`top'} and \texttt{`bottom'}, indicating |
---|
105 | which boundary the edge in question belongs to. |
---|
106 | |
---|
107 | \end{itemize} |
---|
108 | |
---|
109 | |
---|
110 | \subsection*{Initialising the domain} |
---|
111 | |
---|
112 | These variables are then used to set up a data structure domain, |
---|
113 | through the assignment: |
---|
114 | |
---|
115 | \begin{verbatim} |
---|
116 | domain = Domain(points, vertices, boundary) |
---|
117 | \end{verbatim} |
---|
118 | |
---|
119 | This uses a Python class \texttt{Domain}, imported from |
---|
120 | \texttt{shallow\_water}, which is an extension of a more generic |
---|
121 | class of the same name in the module \texttt{domain}, and inherits |
---|
122 | some methods from the generic class but has others specific to the |
---|
123 | shallow-water scenarios in which it is used. The following lines |
---|
124 | set certain key options governing the domain: \emph{[more details |
---|
125 | of 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 | |
---|
138 | The next task is to specify a number of quantities that we wish to |
---|
139 | set for each mesh point. The class \texttt{Domain} has a method |
---|
140 | \texttt{set\_quantity}, used to specify these quantities. It is a |
---|
141 | particularly flexible method that allows the user to set |
---|
142 | quantities in a variety of ways---using constants, functions, |
---|
143 | numeric arrays or expressions involving other quantities, all of |
---|
144 | which can be passed as arguments. The code in the present example |
---|
145 | demonstrates a number of forms in which we can invoke |
---|
146 | \texttt{set\_quantity}. |
---|
147 | |
---|
148 | |
---|
149 | \subsubsection*{Elevation} |
---|
150 | |
---|
151 | The elevation is set using a function, defined through the |
---|
152 | statements below, which is specific to this example and specifies |
---|
153 | a particularly simple initial configuration for demonstration |
---|
154 | purposes: |
---|
155 | |
---|
156 | \begin{verbatim} |
---|
157 | \# Initial conditions |
---|
158 | def f(x,y): |
---|
159 | return -x/2 |
---|
160 | \end{verbatim} |
---|
161 | |
---|
162 | This simply associates an elevation with each point $(x, y)$ of |
---|
163 | the plane. It specifies that the bed slopes linearly in the $x$ |
---|
164 | direction, with slope $-\frac{1}{2}$, and is constant in the $y$ |
---|
165 | direction. %[screen shot?]\\ |
---|
166 | \\ |
---|
167 | Once the function $f$ is specified, the quantity is assigned |
---|
168 | through the simple statement: |
---|
169 | |
---|
170 | \begin{verbatim} |
---|
171 | domain.set_quantity('elevation', f) |
---|
172 | \end{verbatim} |
---|
173 | |
---|
174 | |
---|
175 | \subsubsection*{Friction} |
---|
176 | |
---|
177 | The assignment of the friction quantity demonstrates another way |
---|
178 | we can use \texttt{set\_quantity} to set quantities---namely, |
---|
179 | assign them to a constant numerical value: |
---|
180 | |
---|
181 | \begin{verbatim} |
---|
182 | domain.set_quantity('friction', 0.1) |
---|
183 | \end{verbatim} |
---|
184 | |
---|
185 | This just specifies that the Manning friction coefficient is set |
---|
186 | to 0.1 at every mesh point. |
---|
187 | |
---|
188 | \subsubsection*{Depth} |
---|
189 | |
---|
190 | Assigning depth illustrates a more complex way to use |
---|
191 | \texttt{set\_quantity}, introducing an expression involving other |
---|
192 | quantities: |
---|
193 | |
---|
194 | \begin{verbatim} |
---|
195 | h = 0.05 \# Constant depth |
---|
196 | domain.set_quantity('stage', expression = 'elevation + %f' %h) |
---|
197 | \end{verbatim} |
---|
198 | |
---|
199 | Here the quantity \texttt{stage} is defined by taking the quantity |
---|
200 | elevation already defined and adding a constant value $h = 0.05$ |
---|
201 | to it everywhere. This expresses the fact that the water depth is |
---|
202 | everywhere constant, so the surface is a constant height above the |
---|
203 | elevation of the bed. |
---|
204 | |
---|
205 | \subsubsection*{Boundary Conditions} |
---|
206 | |
---|
207 | The 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 | |
---|
220 | The effect of these statements is to set up four alternative |
---|
221 | boundary conditions and store them in variables that can be |
---|
222 | assigned as needed. Each boundary condition specifies the |
---|
223 | behaviour at a boundary in terms of the behaviour in neighbouring |
---|
224 | elements. The boundary conditions may be briefly described as |
---|
225 | follows: |
---|
226 | |
---|
227 | \begin{description} |
---|
228 | \item[Reflective boundary]Returns same conserved |
---|
229 | quantities as those present in its neighbour volume but reflected. |
---|
230 | Specific to the shallow water equation as it works with the |
---|
231 | momentum quantities assumed to be the second and third conserved |
---|
232 | quantities. |
---|
233 | \item[Transmissive boundary]\emph{[Need to add some suitable text |
---|
234 | here]} |
---|
235 | \item[Dirichlet boundary]Specifies a fixed value at the |
---|
236 | boundary. |
---|
237 | \item[Time boundary.]A Dirichlet boundary whose behaviour varies with time. |
---|
238 | \end{description} |
---|
239 | |
---|
240 | Once the four boundary types have been specified through the |
---|
241 | statements above, they can be applied through a statement of the |
---|
242 | form |
---|
243 | |
---|
244 | \begin{verbatim} |
---|
245 | domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': |
---|
246 | Br}) |
---|
247 | \end{verbatim} |
---|
248 | |
---|
249 | This statement stipulates that, in the current example, the left |
---|
250 | boundary is fixed, with an elevation of 0.2, while the other |
---|
251 | boundaries are all reflective. |
---|
252 | |
---|
253 | |
---|
254 | \subsection*{Evolution} |
---|
255 | |
---|
256 | The 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 | |
---|
263 | is the key step that causes the configuration of the domain to |
---|
264 | `evolve' in accordance with the model embodied in the code, over a |
---|
265 | series 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 | |
---|
274 | The output is a NetCDF file with the extension \texttt{.sww}. It |
---|
275 | contains 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 | |
---|
281 | The 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} |
---|