1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | Specific methods pertaining to the 2D shallow water equation |
---|
4 | are imported from shallow_water |
---|
5 | for use with the generic finite volume framework |
---|
6 | |
---|
7 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
8 | numerical vector named conserved_quantities. |
---|
9 | |
---|
10 | |
---|
11 | """ |
---|
12 | |
---|
13 | ###################### |
---|
14 | # Module imports |
---|
15 | # |
---|
16 | |
---|
17 | #Were these used? |
---|
18 | #import visualise2_chris as visualise |
---|
19 | #import Image, ImageGrab |
---|
20 | |
---|
21 | import sys |
---|
22 | from os import sep |
---|
23 | sys.path.append('..'+sep+'pyvolution') |
---|
24 | |
---|
25 | |
---|
26 | from shallow_water import Domain, Constant_height |
---|
27 | from shallow_water import Transmissive_boundary, Reflective_boundary,\ |
---|
28 | Dirichlet_boundary |
---|
29 | |
---|
30 | from math import sqrt, cos, sin, pi |
---|
31 | from mesh_factory import oblique |
---|
32 | |
---|
33 | |
---|
34 | ###################### |
---|
35 | # Domain |
---|
36 | # |
---|
37 | n = 60 |
---|
38 | m = 80 |
---|
39 | leny = 30. |
---|
40 | lenx = 40. |
---|
41 | n = 50 |
---|
42 | m = 60 |
---|
43 | |
---|
44 | points, elements, boundary = oblique(m, n, lenx, leny) |
---|
45 | domain = Domain(points, elements, boundary) |
---|
46 | |
---|
47 | # Order of solver |
---|
48 | domain.default_order=2 |
---|
49 | |
---|
50 | # Store output |
---|
51 | domain.store=True |
---|
52 | |
---|
53 | # Output format |
---|
54 | domain.format="sww" #NET.CDF binary format |
---|
55 | # "dat" for ASCII |
---|
56 | |
---|
57 | # Provide file name for storing output |
---|
58 | domain.filename="oblique" |
---|
59 | |
---|
60 | # Visualization smoothing |
---|
61 | domain.smooth=True |
---|
62 | |
---|
63 | ####################### |
---|
64 | #Bed-slope and friction |
---|
65 | def x_slope(x, y): |
---|
66 | return 0*x |
---|
67 | |
---|
68 | domain.set_quantity('elevation', x_slope) |
---|
69 | domain.set_quantity('friction', 0.0) |
---|
70 | |
---|
71 | ###################### |
---|
72 | # Boundary conditions |
---|
73 | # |
---|
74 | R = Reflective_boundary(domain) |
---|
75 | T = Transmissive_boundary(domain) |
---|
76 | D = Dirichlet_boundary([1.0, 8.57, 0.0]) |
---|
77 | |
---|
78 | domain.set_boundary({'left': D, 'right': T, 'top': R, 'bottom': R}) |
---|
79 | |
---|
80 | ###################### |
---|
81 | #Initial condition |
---|
82 | h = 0.5 |
---|
83 | domain.set_quantity('level', Constant_height(x_slope, h) ) |
---|
84 | |
---|
85 | |
---|
86 | ###################### |
---|
87 | #Evolution |
---|
88 | import time |
---|
89 | t0 = time.time() |
---|
90 | for t in domain.evolve(yieldstep = 0.5, finaltime = 50): |
---|
91 | domain.write_time() |
---|
92 | |
---|
93 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
94 | |
---|
95 | #FIXME: Compute average water depth on either side of shock and compare |
---|
96 | #to expected values. And also Froude numbers. |
---|
97 | |
---|
98 | |
---|
99 | #print "saving file?" |
---|
100 | #im = ImageGrab.grab() |
---|
101 | #im.save("ccube.eps") |
---|
102 | |
---|
103 | |
---|
104 | |
---|