[5112] | 1 | """Simple water flow example using ANUGA |
---|
| 2 | |
---|
| 3 | Water driven up a linear slope and time varying boundary, |
---|
| 4 | similar to a beach environment |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | #------------------------------------------------------------------------------ |
---|
| 9 | # Import necessary modules |
---|
| 10 | #------------------------------------------------------------------------------ |
---|
| 11 | |
---|
| 12 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
| 13 | from anuga.shallow_water import Domain |
---|
| 14 | from anuga.shallow_water import Reflective_boundary |
---|
| 15 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 16 | from anuga.shallow_water import Time_boundary |
---|
| 17 | from anuga.shallow_water import Transmissive_boundary |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #------------------------------------------------------------------------------ |
---|
| 21 | # Setup computational domain |
---|
| 22 | #------------------------------------------------------------------------------ |
---|
| 23 | |
---|
| 24 | points, vertices, boundary = rectangular_cross(10, 10,len1=1.0, len2= 1.0 ) # Basic mesh |
---|
| 25 | |
---|
| 26 | domain = Domain(points, vertices, boundary) # Create domain |
---|
| 27 | domain.set_name('runup') # Output to file runup.sww |
---|
| 28 | domain.set_datadir('.') # Use current directory for output |
---|
| 29 | #domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities |
---|
| 30 | # 'xmomentum', |
---|
| 31 | # 'ymomentum']) |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | #------------------------------------------------------------------------------ |
---|
| 35 | # Setup initial conditions |
---|
| 36 | #------------------------------------------------------------------------------ |
---|
| 37 | |
---|
| 38 | def topography(x,y): |
---|
| 39 | return -x/2 # linear bed slope |
---|
| 40 | #return x*(-(2.0-x)*.5) # curved bed slope |
---|
| 41 | |
---|
| 42 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 43 | domain.set_quantity('friction', 0.1) # Constant friction |
---|
| 44 | domain.set_quantity('stage', -.4) # Constant negative initial stage |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | #------------------------------------------------------------------------------ |
---|
| 48 | # Setup boundary conditions |
---|
| 49 | #------------------------------------------------------------------------------ |
---|
| 50 | |
---|
| 51 | from math import sin, pi, exp |
---|
| 52 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
| 53 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
| 54 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
| 55 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
| 56 | f=lambda t: [(.1*sin(t*2*pi)-0.3) , 0.0, 0.0]) |
---|
| 57 | |
---|
| 58 | # Associate boundary tags with boundary objects |
---|
| 59 | domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br}) |
---|
| 60 | |
---|
| 61 | #=============================================================================== |
---|
| 62 | from anuga.visualiser import RealtimeVisualiser |
---|
| 63 | vis = RealtimeVisualiser(domain) |
---|
| 64 | vis.render_quantity_height("elevation", zScale=1.0, dynamic=False) |
---|
| 65 | vis.render_quantity_height("stage", dynamic=True) |
---|
| 66 | vis.colour_height_quantity('stage', (lambda q:q['stage'], -0.5, 0.5)) |
---|
| 67 | vis.start() |
---|
| 68 | #=============================================================================== |
---|
| 69 | |
---|
| 70 | import time |
---|
| 71 | t0 = time.time() |
---|
| 72 | #------------------------------------------------------------------------------ |
---|
| 73 | # Evolve system through time |
---|
| 74 | #------------------------------------------------------------------------------ |
---|
| 75 | |
---|
| 76 | for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0): |
---|
| 77 | domain.write_time() |
---|
| 78 | vis.update() |
---|
| 79 | |
---|
| 80 | vis.evolveFinished() |
---|
| 81 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 82 | |
---|