1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water flowing down a channel with more complex topography |
---|
4 | """ |
---|
5 | |
---|
6 | #------------------------------------------------------------------------------ |
---|
7 | # Import necessary modules |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
10 | from anuga.shallow_water import Domain |
---|
11 | from anuga.shallow_water import Reflective_boundary |
---|
12 | from anuga.shallow_water import Dirichlet_boundary |
---|
13 | from anuga.shallow_water import Time_boundary |
---|
14 | |
---|
15 | from math import cos, sin, pi, sqrt |
---|
16 | |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | # Setup computational domain |
---|
19 | #------------------------------------------------------------------------------ |
---|
20 | length = 40. |
---|
21 | width = 5. |
---|
22 | #dx = dy = .05 # Resolution: Length of subdivisions on both axes |
---|
23 | dx = dy = .5 # Resolution: Length of subdivisions on both axes |
---|
24 | |
---|
25 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
26 | len1=length, len2=width) |
---|
27 | domain = Domain(points, vertices, boundary) |
---|
28 | domain.set_name('channel3') # Output name |
---|
29 | print domain.statistics() |
---|
30 | |
---|
31 | |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | # Setup initial conditions |
---|
34 | #------------------------------------------------------------------------------ |
---|
35 | def topography(x,y): |
---|
36 | """Complex topography defined by a function of vectors x and y |
---|
37 | """ |
---|
38 | |
---|
39 | # Geometric parameters |
---|
40 | gradient = 0.02 |
---|
41 | weir_height = 0.5 |
---|
42 | obstruction_height = 0.0 |
---|
43 | pole_height = 0.0 |
---|
44 | |
---|
45 | # Upward slope |
---|
46 | z = gradient*x |
---|
47 | |
---|
48 | N = len(x) |
---|
49 | for i in range(N): |
---|
50 | |
---|
51 | # Weir |
---|
52 | if 10 < x[i] < 12: |
---|
53 | z[i] += weir_height |
---|
54 | |
---|
55 | # Obstruction |
---|
56 | if 27 < x[i] < 29 and y[i] > 3: |
---|
57 | z[i] += obstruction_height |
---|
58 | |
---|
59 | # Pole |
---|
60 | if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
61 | z[i] += pole_height |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | return z |
---|
68 | |
---|
69 | |
---|
70 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
71 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
72 | domain.set_quantity('stage', |
---|
73 | expression='elevation') # Dry initial condition |
---|
74 | |
---|
75 | |
---|
76 | #------------------------------------------------------------------------------ |
---|
77 | # Setup boundary conditions |
---|
78 | #------------------------------------------------------------------------------ |
---|
79 | Bi = Dirichlet_boundary([1.0, 0, 0]) # Inflow |
---|
80 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
81 | Bo = Dirichlet_boundary([-1, 0, 0]) # Outflow |
---|
82 | |
---|
83 | def wave(t): |
---|
84 | |
---|
85 | A = 1.5 # Amplitude [m] (Wave height) |
---|
86 | T = 30 # Wave period [s] |
---|
87 | |
---|
88 | if t < 120: |
---|
89 | return [A*sin(2*pi*t/T) + 1, 0, 0] |
---|
90 | else: |
---|
91 | return [0.0, 0, 0] |
---|
92 | |
---|
93 | Bt = Time_boundary(domain, f=wave) |
---|
94 | |
---|
95 | domain.set_boundary({'left': Bt, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | #------------------------------------------------------------------------------ |
---|
100 | # Evolve system through time |
---|
101 | #------------------------------------------------------------------------------ |
---|
102 | |
---|
103 | washed_away = False |
---|
104 | |
---|
105 | for t in domain.evolve(yieldstep = 0.1, finaltime = 120.0): |
---|
106 | print domain.timestepping_statistics() |
---|
107 | |
---|
108 | S = domain.get_quantity('stage').get_values(interpolation_points=[[40, 2.5]]) |
---|
109 | E = domain.get_quantity('elevation').get_values(interpolation_points=[[40, 2.5]]) |
---|
110 | |
---|
111 | depth = S-E |
---|
112 | |
---|
113 | print '-------------' |
---|
114 | print 'depth', depth |
---|
115 | print '-------------' |
---|
116 | |
---|
117 | #print 'elevation', E |
---|
118 | |
---|
119 | if depth > 1.63/3: |
---|
120 | |
---|
121 | print 'Water level will sweep Fiona away', |
---|
122 | if washed_away is True: |
---|
123 | print ' - AGAIN!' |
---|
124 | else: |
---|
125 | print |
---|
126 | |
---|
127 | if washed_away is False: |
---|
128 | |
---|
129 | washaway_time = t |
---|
130 | print 'Getting momentum' |
---|
131 | uh = domain.get_quantity('xmomentum').get_values(interpolation_points=[[40, 2.5]]) |
---|
132 | vh = domain.get_quantity('ymomentum').get_values(interpolation_points=[[40, 2.5]]) |
---|
133 | |
---|
134 | print 'Computing velocity' |
---|
135 | u = uh/depth |
---|
136 | v = vh/depth |
---|
137 | print 'velocity: (%f, %f' %(u,v) |
---|
138 | washaway_velocity = sqrt(u*u + v*v) |
---|
139 | print 'done' |
---|
140 | |
---|
141 | washed_away = True |
---|
142 | #raw_input('press key') |
---|
143 | |
---|
144 | if washed_away is True: |
---|
145 | print 'Fiona got swept away at time = %.1f sec with a velocity of %.2f m/s'\ |
---|
146 | %(washaway_time, washaway_velocity) |
---|
147 | |
---|