1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water flowing down a channel with a topography that varies with time |
---|
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 | #------------------------------------------------------------------------------ |
---|
16 | # Setup computational domain |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | length = 40. |
---|
19 | width = 5. |
---|
20 | dx = dy = 1 #.1 # Resolution: Length of subdivisions on both axes |
---|
21 | |
---|
22 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
23 | len1=length, len2=width) |
---|
24 | domain = Domain(points, vertices, boundary) |
---|
25 | domain.set_name('channel_variable') # Output name |
---|
26 | print domain.statistics() |
---|
27 | domain.set_quantities_to_be_stored({'elevation': 1, #2, |
---|
28 | 'stage': 2}) |
---|
29 | |
---|
30 | #------------------------------------------------------------------------------ |
---|
31 | # Setup initial conditions |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | def topography(x,y): |
---|
34 | """Complex topography defined by a function of vectors x and y.""" |
---|
35 | |
---|
36 | z = -x/100 |
---|
37 | |
---|
38 | N = len(x) |
---|
39 | for i in range(N): |
---|
40 | # Step |
---|
41 | if 10 < x[i] < 12: |
---|
42 | z[i] += 0.4 - 0.05*y[i] |
---|
43 | |
---|
44 | # Constriction |
---|
45 | #if 27 < x[i] < 29 and y[i] > 3: |
---|
46 | # z[i] += 2 |
---|
47 | |
---|
48 | # Pole |
---|
49 | #if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
50 | # z[i] += 2 |
---|
51 | |
---|
52 | return z |
---|
53 | |
---|
54 | def pole_increment(x,y): |
---|
55 | """This provides a small increment to a pole located mid stream |
---|
56 | For use with variable elevation data |
---|
57 | """ |
---|
58 | |
---|
59 | z = 0.0*x |
---|
60 | |
---|
61 | N = len(x) |
---|
62 | for i in range(N): |
---|
63 | # Pole |
---|
64 | if (x[i] - 20)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
65 | z[i] += 0.05 |
---|
66 | return z |
---|
67 | |
---|
68 | |
---|
69 | domain.set_quantity('elevation', topography) # elevation is a function |
---|
70 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
71 | domain.set_quantity('stage', expression='elevation') # Dry initial condition |
---|
72 | |
---|
73 | #------------------------------------------------------------------------------ |
---|
74 | # Setup boundary conditions |
---|
75 | #------------------------------------------------------------------------------ |
---|
76 | Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
77 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
78 | Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
79 | |
---|
80 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
81 | |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | # Evolve system through time |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | |
---|
86 | growing = False |
---|
87 | shrinking = False |
---|
88 | done = False |
---|
89 | for t in domain.evolve(yieldstep=0.1, finaltime=30.0): |
---|
90 | print domain.timestepping_statistics() |
---|
91 | |
---|
92 | #w = domain.get_quantity('stage').\ |
---|
93 | # get_values(interpolation_points=[[18, 2.5]]) |
---|
94 | #print 'Level at gauge point = %.2fm' % w |
---|
95 | |
---|
96 | z = domain.get_quantity('elevation').\ |
---|
97 | get_values(interpolation_points=[[20, 2]]) |
---|
98 | print 'Elevation at pole location = %.2fm' % z |
---|
99 | |
---|
100 | # Start variable elevation after 10 seconds |
---|
101 | if t > 10 and not (shrinking or growing or done): |
---|
102 | growing = True |
---|
103 | |
---|
104 | # Turn around when pole has reached a height of 2 m |
---|
105 | if z >= 2 and growing: |
---|
106 | growing = False |
---|
107 | shrinking = True |
---|
108 | |
---|
109 | # Stop changing when pole has shrunk to 1 m |
---|
110 | if z <= 1 and shrinking: |
---|
111 | done = True |
---|
112 | shrinking = growing = False |
---|
113 | |
---|
114 | # Grow or shrink |
---|
115 | if growing: |
---|
116 | domain.add_quantity('elevation', pole_increment) |
---|
117 | |
---|
118 | if shrinking: |
---|
119 | domain.add_quantity('elevation', lambda x,y: -pole_increment(x,y)) |
---|
120 | |
---|