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