[8728] | 1 | """Simple water flow example using ANUGA |
---|
| 2 | |
---|
| 3 | Water flowing down a channel with a topography that varies with time |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | #------------------------------------------------------------------------------ |
---|
| 7 | # Import necessary modules |
---|
| 8 | #------------------------------------------------------------------------------ |
---|
| 9 | from anuga import rectangular_cross |
---|
| 10 | from anuga import Domain |
---|
| 11 | from anuga import Reflective_boundary |
---|
| 12 | from anuga import Dirichlet_boundary |
---|
| 13 | from anuga import Time_boundary |
---|
| 14 | |
---|
| 15 | #------------------------------------------------------------------------------ |
---|
| 16 | # Setup computational domain |
---|
| 17 | #------------------------------------------------------------------------------ |
---|
| 18 | length = 24. |
---|
| 19 | width = 5. |
---|
| 20 | dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes |
---|
| 21 | |
---|
| 22 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
| 23 | len1=length, len2=width) |
---|
| 24 | domain = Domain(points, vertices, boundary) |
---|
| 25 | domain.set_name('channel_variable_bed_0.2_newviewer') # Output name |
---|
| 26 | print domain.statistics() |
---|
| 27 | domain.set_quantities_to_be_stored({'elevation': 2, |
---|
| 28 | 'stage': 2}) |
---|
| 29 | |
---|
| 30 | #------------------------------------------------------------------------------ |
---|
| 31 | # Setup initial conditions |
---|
| 32 | #------------------------------------------------------------------------------ |
---|
| 33 | def topography(x,y): |
---|
| 34 | """Complex topography defined by a function of vectors x and y.""" |
---|
| 35 | |
---|
| 36 | z = -x/100 |
---|
| 37 | |
---|
| 38 | N = len(x) |
---|
| 39 | for i in range(N): |
---|
| 40 | # Step |
---|
| 41 | if 2 < x[i] < 4: |
---|
| 42 | z[i] += 0.4 - 0.05*y[i] |
---|
| 43 | |
---|
| 44 | # Permanent pole |
---|
| 45 | if (x[i] - 8)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
| 46 | z[i] += 1 |
---|
| 47 | return z |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | def pole_increment(x,y): |
---|
| 51 | """This provides a small increment to a pole located mid stream |
---|
| 52 | For use with variable elevation data |
---|
| 53 | """ |
---|
| 54 | |
---|
| 55 | z = 0.0*x |
---|
| 56 | |
---|
| 57 | N = len(x) |
---|
| 58 | for i in range(N): |
---|
| 59 | # Pole 1 |
---|
| 60 | if (x[i] - 12)**2 + (y[i] - 3)**2 < 0.4**2: |
---|
| 61 | z[i] += 0.01 |
---|
| 62 | |
---|
| 63 | for i in range(N): |
---|
| 64 | # Pole 2 |
---|
| 65 | if (x[i] - 14)**2 + (y[i] - 2)**2 < 0.4**2: |
---|
| 66 | z[i] += 0.005 |
---|
| 67 | |
---|
| 68 | return z |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | domain.set_quantity('elevation', topography) # elevation is a function |
---|
| 72 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
| 73 | domain.set_quantity('stage', expression='elevation') # Dry initial condition |
---|
| 74 | |
---|
| 75 | #------------------------------------------------------------------------------ |
---|
| 76 | # Setup boundary conditions |
---|
| 77 | #------------------------------------------------------------------------------ |
---|
| 78 | Bi = Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
| 79 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
| 80 | Bo = Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
| 81 | |
---|
| 82 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
| 83 | |
---|
| 84 | #------------------------------------------------------------------------------ |
---|
| 85 | # Evolve system through time |
---|
| 86 | #------------------------------------------------------------------------------ |
---|
| 87 | |
---|
| 88 | growing = False |
---|
| 89 | shrinking = False |
---|
| 90 | done = False |
---|
| 91 | for t in domain.evolve(yieldstep=0.1, finaltime=40.0): |
---|
| 92 | print domain.timestepping_statistics() |
---|
| 93 | |
---|
| 94 | #w = domain.get_quantity('stage').\ |
---|
| 95 | # get_values(interpolation_points=[[18, 2.5]]) |
---|
| 96 | #print 'Level at gauge point = %.2fm' % w |
---|
| 97 | |
---|
| 98 | #z = domain.get_quantity('elevation').\ |
---|
| 99 | # get_values(interpolation_points=[[12, 3]]) |
---|
| 100 | #print 'Elevation at pole location = %.2fm' % z |
---|
| 101 | |
---|
| 102 | # Start variable elevation after 10 seconds |
---|
| 103 | if t > 10 and not (shrinking or growing or done): |
---|
| 104 | growing = True |
---|
| 105 | |
---|
| 106 | # Stop growing when pole has reached a certain height |
---|
| 107 | if t > 16 and growing: |
---|
| 108 | growing = False |
---|
| 109 | shrinking = False |
---|
| 110 | |
---|
| 111 | # Start shrinking |
---|
| 112 | if t > 20: |
---|
| 113 | shrinking = True |
---|
| 114 | growing = False |
---|
| 115 | |
---|
| 116 | # Stop changing when pole has shrunk to original level |
---|
| 117 | if t > 25 and shrinking: |
---|
| 118 | done = True |
---|
| 119 | shrinking = growing = False |
---|
| 120 | domain.set_quantity('elevation', topography) |
---|
| 121 | |
---|
| 122 | # Grow or shrink |
---|
| 123 | if growing: |
---|
| 124 | domain.add_quantity('elevation', pole_increment) |
---|
| 125 | |
---|
| 126 | if shrinking: |
---|
| 127 | domain.add_quantity('elevation', lambda x,y: -2*pole_increment(x,y)) |
---|
| 128 | |
---|