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.abstract_2d_finite_volumes.util import file_function |
---|
11 | from anuga.shallow_water import Domain |
---|
12 | from anuga.shallow_water import Reflective_boundary |
---|
13 | from anuga.shallow_water import Dirichlet_boundary |
---|
14 | from anuga.shallow_water import Time_boundary |
---|
15 | from anuga.shallow_water import Field_boundary |
---|
16 | from anuga.shallow_water.shallow_water_domain import Inflow |
---|
17 | |
---|
18 | |
---|
19 | #------------------------------------------------------------------------------ |
---|
20 | # Setup computational domain |
---|
21 | #------------------------------------------------------------------------------ |
---|
22 | length = 40. |
---|
23 | width = 5. |
---|
24 | dx = dy = .1 # Resolution: Length of subdivisions on both axes |
---|
25 | #dx = dy = .1 # Resolution: Length of subdivisions on both axes |
---|
26 | |
---|
27 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
28 | len1=length, len2=width) |
---|
29 | domain = Domain(points, vertices, boundary) |
---|
30 | domain.set_name('hydro_example') # Output name |
---|
31 | domain.set_minimum_storable_height(0.0001) |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | #------------------------------------------------------------------------------ |
---|
36 | # Setup initial conditions |
---|
37 | #------------------------------------------------------------------------------ |
---|
38 | def topography(x,y): |
---|
39 | """Complex topography defined by a function of vectors x and y |
---|
40 | """ |
---|
41 | |
---|
42 | z = -x/10 |
---|
43 | #z = x*0.0 |
---|
44 | |
---|
45 | N = len(x) |
---|
46 | for i in range(N): |
---|
47 | |
---|
48 | #Step |
---|
49 | if 10 < x[i] < 12: |
---|
50 | z[i] += 0.4 - 0.05*y[i] |
---|
51 | |
---|
52 | #Constriction |
---|
53 | if 27 < x[i] < 29 and y[i] > 3: |
---|
54 | z[i] += 2 |
---|
55 | |
---|
56 | # Pole |
---|
57 | if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
58 | z[i] += 2 |
---|
59 | |
---|
60 | return z |
---|
61 | |
---|
62 | |
---|
63 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
64 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
65 | domain.set_quantity('stage', |
---|
66 | expression='elevation') # Dry initial condition |
---|
67 | |
---|
68 | |
---|
69 | #------------------------------------------------------------------------------ |
---|
70 | # Setup specialised forcing terms |
---|
71 | #------------------------------------------------------------------------------ |
---|
72 | |
---|
73 | #hydrograph = Inflow(center=(1.0, 0.5*width), radius=1.0, |
---|
74 | # flow=lambda t: min(0.01*t, 0.0142)) # Tap turning up |
---|
75 | |
---|
76 | hydrograph = Inflow(center=(1.0, 0.5*width), radius=1.0, |
---|
77 | flow=file_function('Island_Pt_Rd_Meta.tms')) |
---|
78 | |
---|
79 | domain.forcing_terms.append(hydrograph) |
---|
80 | |
---|
81 | |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | # Setup boundary conditions |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | |
---|
86 | #Hydrograph = Field_boundary('Island_Pt_Rd_Meta.tms', domain, |
---|
87 | # mean_stage=0.01) |
---|
88 | |
---|
89 | Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
90 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
91 | Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
92 | |
---|
93 | domain.set_boundary({'left': Br, |
---|
94 | 'right': Br, |
---|
95 | 'top': Br, |
---|
96 | 'bottom': Br}) |
---|
97 | |
---|
98 | |
---|
99 | #------------------------------------------------------------------------------ |
---|
100 | # Evolve system through time |
---|
101 | #------------------------------------------------------------------------------ |
---|
102 | domain.start_time = 2800 |
---|
103 | for t in domain.evolve(yieldstep = 1, finaltime = 32700): |
---|
104 | domain.write_time() |
---|
105 | |
---|
106 | |
---|
107 | #if domain.get_quantity('stage').\ |
---|
108 | # get_values(interpolation_points=[[10, 2.5]]) > 0: |
---|
109 | # print 'Stage > 0: Changing to outflow boundary' |
---|
110 | # domain.set_boundary({'right': Bo}) |
---|