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 | import anuga |
---|
10 | |
---|
11 | #------------------------------------------------------------------------------ |
---|
12 | # Setup computational domain |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | length = 40. |
---|
15 | width = 5. |
---|
16 | dx = dy = .1 # Resolution: Length of subdivisions on both axes |
---|
17 | |
---|
18 | points, vertices, boundary = anuga.rectangular_cross(int(length/dx), |
---|
19 | int(width/dy), len1=length, len2=width) |
---|
20 | domain = anuga.Domain(points, vertices, boundary) |
---|
21 | domain.set_name('channel3') # Output name |
---|
22 | print domain.statistics() |
---|
23 | |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | # Setup initial conditions |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | def topography(x,y): |
---|
28 | """Complex topography defined by a function of vectors x and y.""" |
---|
29 | |
---|
30 | z = -x/10 |
---|
31 | |
---|
32 | N = len(x) |
---|
33 | for i in range(N): |
---|
34 | # Step |
---|
35 | if 10 < x[i] < 12: |
---|
36 | z[i] += 0.4 - 0.05*y[i] |
---|
37 | |
---|
38 | # Constriction |
---|
39 | if 27 < x[i] < 29 and y[i] > 3: |
---|
40 | z[i] += 2 |
---|
41 | |
---|
42 | # Pole |
---|
43 | if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
44 | z[i] += 2 |
---|
45 | |
---|
46 | return z |
---|
47 | |
---|
48 | domain.set_quantity('elevation', topography) # elevation is a function |
---|
49 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
50 | domain.set_quantity('stage', expression='elevation') # Dry initial condition |
---|
51 | |
---|
52 | #------------------------------------------------------------------------------ |
---|
53 | # Setup boundary conditions |
---|
54 | #------------------------------------------------------------------------------ |
---|
55 | Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
56 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
57 | Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
58 | |
---|
59 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
60 | |
---|
61 | #------------------------------------------------------------------------------ |
---|
62 | # Evolve system through time |
---|
63 | #------------------------------------------------------------------------------ |
---|
64 | for t in domain.evolve(yieldstep=0.1, finaltime=16.0): |
---|
65 | print domain.timestepping_statistics() |
---|
66 | |
---|
67 | if domain.get_quantity('stage').\ |
---|
68 | get_values(interpolation_points=[[10, 2.5]]) > 0: |
---|
69 | print 'Stage > 0: Changing to outflow boundary' |
---|
70 | domain.set_boundary({'right': Bo}) |
---|
71 | |
---|