1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | This is called Netherlands because it shows a dam with a gap in it and |
---|
4 | stylised housed behind it and below the water surface. |
---|
5 | |
---|
6 | """ |
---|
7 | |
---|
8 | ###################### |
---|
9 | # Module imports |
---|
10 | # |
---|
11 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
12 | Transmissive_boundary, Time_boundary, Constant_height |
---|
13 | |
---|
14 | from mesh_factory import from_polyfile |
---|
15 | from Numeric import array |
---|
16 | |
---|
17 | |
---|
18 | print 'Creating domain' |
---|
19 | #points, triangles, values = from_polyfile('cornell_room_medres') |
---|
20 | points, triangles, values = from_polyfile('hires2') |
---|
21 | |
---|
22 | |
---|
23 | #Create shallow water domain |
---|
24 | domain = Domain(points, triangles) |
---|
25 | |
---|
26 | domain.check_integrity() |
---|
27 | domain.default_order = 2 |
---|
28 | domain.smooth = True |
---|
29 | domain.reduction = min #Looks a lot better on top of steep slopes |
---|
30 | |
---|
31 | print "Number of triangles = ", len(domain) |
---|
32 | |
---|
33 | domain.visualise = False |
---|
34 | domain.checkpoint = False |
---|
35 | domain.store = True #Store for visualisation purposes |
---|
36 | domain.format = 'sww' #Native netcdf visualisation format |
---|
37 | import sys, os |
---|
38 | root, ext = os.path.splitext(sys.argv[0]) |
---|
39 | if domain.smooth is True: |
---|
40 | s = 'smooth' |
---|
41 | else: |
---|
42 | s = 'nonsmooth' |
---|
43 | domain.filename = root + '_' + s |
---|
44 | |
---|
45 | #Set bed-slope and friction |
---|
46 | manning = 0.0 |
---|
47 | |
---|
48 | print 'Field values' |
---|
49 | domain.set_quantity('elevation', values) |
---|
50 | domain.set_quantity('friction', manning) |
---|
51 | |
---|
52 | |
---|
53 | ###################### |
---|
54 | # Boundary conditions |
---|
55 | # |
---|
56 | print 'Boundaries' |
---|
57 | Br = Reflective_boundary(domain) |
---|
58 | domain.set_boundary({'exterior': Br}) |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | ###################### |
---|
63 | #Initial condition |
---|
64 | # |
---|
65 | print 'Initial condition' |
---|
66 | |
---|
67 | #Define water height as a lump in one corner |
---|
68 | def height(x, y): |
---|
69 | from Numeric import zeros, Float |
---|
70 | |
---|
71 | N = len(x) |
---|
72 | assert N == len(y) |
---|
73 | |
---|
74 | xmin = min(x); xmax = max(x) |
---|
75 | ymin = min(y); ymax = max(y) |
---|
76 | |
---|
77 | xrange = xmax - xmin |
---|
78 | yrange = ymax - ymin |
---|
79 | |
---|
80 | z = zeros(N, Float) |
---|
81 | for i in range(N): |
---|
82 | if x[i] <= xmin + 0.25*xrange and y[i] <= ymin + 0.25*yrange: |
---|
83 | z[i] = 300 |
---|
84 | |
---|
85 | return z |
---|
86 | |
---|
87 | domain.set_quantity('level', height) |
---|
88 | |
---|
89 | E = domain.quantities['elevation'].vertex_values |
---|
90 | L = domain.quantities['level'].vertex_values |
---|
91 | domain.set_quantity('level', E+L) |
---|
92 | |
---|
93 | #Evolve |
---|
94 | for t in domain.evolve(yieldstep = 0.05, finaltime = 5.0): |
---|
95 | domain.write_time() |
---|
96 | |
---|
97 | |
---|
98 | |
---|