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 | # Import necessary modules |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular |
---|
15 | from anuga.shallow_water import Domain |
---|
16 | from anuga.shallow_water.shallow_water_domain import Reflective_boundary |
---|
17 | from anuga.shallow_water.shallow_water_domain import Dirichlet_boundary |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | #from Numeric import array |
---|
22 | #from math import sin, pi |
---|
23 | |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | # Setup computational domain |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | |
---|
28 | #N = 120 |
---|
29 | N = 40 |
---|
30 | points, vertices, boundary = rectangular(N, N) |
---|
31 | domain = Domain(points, vertices, boundary) |
---|
32 | domain.set_name('kitchen_sink') # Output name |
---|
33 | print 'Size', len(domain) |
---|
34 | |
---|
35 | |
---|
36 | #------------------------------------------------------------------------------ |
---|
37 | # Setup initial conditions |
---|
38 | #------------------------------------------------------------------------------ |
---|
39 | |
---|
40 | domain.set_quantity('elevation', 0.0) # Zero bed elevation |
---|
41 | domain.set_quantity('stage', 0.015) # Constant stage |
---|
42 | domain.set_quantity('friction', 0.005) # Constant friction |
---|
43 | |
---|
44 | |
---|
45 | #------------------------------------------------------------------------------ |
---|
46 | # Setup specialised forcing terms |
---|
47 | #------------------------------------------------------------------------------ |
---|
48 | |
---|
49 | def tap(domain): |
---|
50 | """Implement forcing function for "water tap" in the center |
---|
51 | """ |
---|
52 | |
---|
53 | flow = min(4*domain.get_time(), 5) # Turn tap up gradually |
---|
54 | stage_update = domain.quantities['stage'].explicit_update |
---|
55 | |
---|
56 | # Determine indices in tap area |
---|
57 | if not hasattr(domain,'tap_indices'): |
---|
58 | N = len(domain) |
---|
59 | domain.tap_indices = [] |
---|
60 | coordinates = domain.get_centroid_coordinates() |
---|
61 | for k in range(N): |
---|
62 | x, y = coordinates[k,:] # Centroid |
---|
63 | if ((x-0.5)**2+(y-0.5)**2) < 0.001: |
---|
64 | domain.tap_indices.append(k) |
---|
65 | |
---|
66 | # Update inflow |
---|
67 | for k in domain.tap_indices: |
---|
68 | stage_update[k] += flow |
---|
69 | |
---|
70 | |
---|
71 | def sink(domain): |
---|
72 | """ Implement forcing function for "water sink" |
---|
73 | """ |
---|
74 | |
---|
75 | flow = min(2*domain.get_time(), 0.2) # Turn drain up gradually |
---|
76 | stage_update = domain.quantities['stage'].explicit_update |
---|
77 | |
---|
78 | # Determine indices in sink area |
---|
79 | if not hasattr(domain,'sink_indices'): |
---|
80 | N = len(domain) |
---|
81 | domain.sink_indices = [] |
---|
82 | coordinates = domain.get_centroid_coordinates() |
---|
83 | for k in range(N): |
---|
84 | x, y = coordinates[k,:] # Centroid |
---|
85 | if ((x-0.7)**2+(y-0.4)**2) < 0.005: |
---|
86 | domain.sink_indices.append(k) |
---|
87 | |
---|
88 | # Update outflow |
---|
89 | for k in domain.sink_indices: |
---|
90 | stage_update[k] -= flow |
---|
91 | |
---|
92 | domain.forcing_terms.append(tap) |
---|
93 | domain.forcing_terms.append(sink) |
---|
94 | |
---|
95 | #------------------------------------------------------------------------------ |
---|
96 | # Setup boundary conditions |
---|
97 | #------------------------------------------------------------------------------ |
---|
98 | |
---|
99 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
100 | domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
101 | |
---|
102 | #------------------------------------------------------------------------------ |
---|
103 | # Evolve system through time |
---|
104 | #------------------------------------------------------------------------------ |
---|
105 | for t in domain.evolve(yieldstep = 0.01, finaltime = 14): |
---|
106 | domain.write_time() |
---|
107 | |
---|
108 | |
---|