[3740] | 1 | """Simple water flow example using ANUGA |
---|
| 2 | |
---|
[3753] | 3 | Water flowing down a channel with changing boundary conditions |
---|
[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 = 10. |
---|
| 20 | width = 5. |
---|
| 21 | dx = dy = 1 # Resolution: Length of subdivisions on both axes |
---|
| 22 | |
---|
[3753] | 23 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
| 24 | len1=length, len2=width) |
---|
[3740] | 25 | domain = Domain(points, vertices, boundary) |
---|
[3863] | 26 | domain.set_name('channel2') # Output name |
---|
[3740] | 27 | |
---|
| 28 | |
---|
| 29 | #------------------------------------------------------------------------------ |
---|
| 30 | # Setup initial conditions |
---|
| 31 | #------------------------------------------------------------------------------ |
---|
| 32 | def topography(x,y): |
---|
| 33 | return -x/10 # linear bed slope |
---|
| 34 | |
---|
[3753] | 35 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 36 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
| 37 | domain.set_quantity('stage', |
---|
| 38 | expression='elevation') # Dry initial condition |
---|
[3740] | 39 | |
---|
| 40 | |
---|
| 41 | #------------------------------------------------------------------------------ |
---|
| 42 | # Setup boundary conditions |
---|
| 43 | #------------------------------------------------------------------------------ |
---|
[3753] | 44 | Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
| 45 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
| 46 | Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
[3740] | 47 | |
---|
| 48 | domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | #------------------------------------------------------------------------------ |
---|
| 52 | # Evolve system through time |
---|
| 53 | #------------------------------------------------------------------------------ |
---|
| 54 | for t in domain.evolve(yieldstep = 0.2, finaltime = 40.0): |
---|
[6889] | 55 | print domain.timestepping_statistics() |
---|
[3740] | 56 | |
---|
[3753] | 57 | if domain.get_quantity('stage').\ |
---|
| 58 | get_values(interpolation_points=[[10, 2.5]]) > 0: |
---|
| 59 | print 'Stage > 0: Changing to outflow boundary' |
---|
[3829] | 60 | domain.set_boundary({'right': Bo}) |
---|
[3740] | 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|