1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water flowing down a channel with changing boundary conditions |
---|
4 | """ |
---|
5 | |
---|
6 | #------------------------------------------------------------------------------ |
---|
7 | # Import necessary modules |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | import anuga |
---|
10 | |
---|
11 | #------------------------------------------------------------------------------ |
---|
12 | # Setup computational domain |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | length = 10. |
---|
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 | |
---|
21 | domain = anuga.Domain(points, vertices, boundary) |
---|
22 | domain.set_name('channel2') # Output name |
---|
23 | |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | # Setup initial conditions |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | def topography(x,y): |
---|
28 | return -x/10 # linear bed slope |
---|
29 | |
---|
30 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
31 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
32 | domain.set_quantity('stage', |
---|
33 | expression='elevation') # Dry initial condition |
---|
34 | |
---|
35 | #------------------------------------------------------------------------------ |
---|
36 | # Setup boundary conditions |
---|
37 | #------------------------------------------------------------------------------ |
---|
38 | Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
39 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
40 | Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
41 | |
---|
42 | domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
43 | |
---|
44 | #------------------------------------------------------------------------------ |
---|
45 | # Evolve system through time |
---|
46 | #------------------------------------------------------------------------------ |
---|
47 | for t in domain.evolve(yieldstep=0.2, finaltime=40.0): |
---|
48 | print domain.timestepping_statistics() |
---|
49 | |
---|
50 | if domain.get_quantity('stage').\ |
---|
51 | get_values(interpolation_points=[[10, 2.5]]) > 0: |
---|
52 | print 'Stage > 0: Changing to outflow boundary' |
---|
53 | domain.set_boundary({'right': Bo}) |
---|
54 | |
---|