[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 | import anuga_parallel |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | #------------------------------------------------------------------------------ |
---|
| 15 | # Setup some initial info |
---|
| 16 | #------------------------------------------------------------------------------ |
---|
| 17 | def topography(x,y): |
---|
| 18 | """Complex topography defined by a function of vectors x and y.""" |
---|
| 19 | |
---|
| 20 | z = -x/10 |
---|
| 21 | |
---|
| 22 | N = len(x) |
---|
| 23 | for i in range(N): |
---|
| 24 | # Step |
---|
| 25 | if 10 < x[i] < 12: |
---|
| 26 | z[i] += 0.4 - 0.05*y[i] |
---|
| 27 | |
---|
| 28 | # Constriction |
---|
| 29 | if 27 < x[i] < 29 and y[i] > 3: |
---|
| 30 | z[i] += 2 |
---|
| 31 | |
---|
| 32 | # Pole |
---|
| 33 | if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
| 34 | z[i] += 2 |
---|
| 35 | |
---|
| 36 | return z |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #------------------------------------------------------------------------------ |
---|
| 41 | # Setup computational domain on one processor |
---|
| 42 | #------------------------------------------------------------------------------ |
---|
| 43 | length = 40. |
---|
| 44 | width = 5. |
---|
| 45 | dx = dy = .1 # Resolution: Length of subdivisions on both axes |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | if anuga_parallel.myid == 0: |
---|
| 49 | points, vertices, boundary = anuga.rectangular_cross(int(length/dx), |
---|
| 50 | int(width/dy), len1=length, len2=width) |
---|
| 51 | domain = anuga.Domain(points, vertices, boundary) |
---|
| 52 | domain.set_name('channel3') # Output name |
---|
| 53 | print domain.statistics() |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | domain.set_quantity('elevation', topography) # elevation is a function |
---|
| 58 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
| 59 | domain.set_quantity('stage', expression='elevation') # Dry initial condition |
---|
| 60 | else: |
---|
| 61 | domain = None |
---|
| 62 | |
---|
| 63 | #------------------------------------------------------------------------------ |
---|
| 64 | # Distribute domain on processor 0 to to other processors |
---|
| 65 | #------------------------------------------------------------------------------ |
---|
| 66 | parameters = dict(ghost_layer_width=3) |
---|
| 67 | domain = anuga_parallel.distribute(domain, verbose= True, parameters=parameters) |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | #------------------------------------------------------------------------------ |
---|
| 71 | # Setup boundary conditions |
---|
| 72 | #------------------------------------------------------------------------------ |
---|
| 73 | Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
| 74 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
| 75 | Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
| 76 | |
---|
| 77 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
| 78 | |
---|
| 79 | #------------------------------------------------------------------------------ |
---|
| 80 | # Evolve system through time |
---|
| 81 | #------------------------------------------------------------------------------ |
---|
| 82 | for t in domain.evolve(yieldstep=0.1, finaltime=16.0): |
---|
| 83 | if anuga_parallel.myid == 0: |
---|
| 84 | print domain.timestepping_statistics() |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | ## if domain.get_quantity('stage').\ |
---|
| 88 | ## get_values(interpolation_points=[[10, 2.5]]) > 0: |
---|
| 89 | ## print 'Stage > 0: Changing to outflow boundary' |
---|
| 90 | ## domain.set_boundary({'right': Bo}) |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | domain.sww_merge(verbose=True) |
---|
| 94 | |
---|
| 95 | anuga_parallel.finalize() |
---|
| 96 | |
---|