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