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