[8728] | 1 | """Simple buildings example using ANUGA |
---|
| 2 | |
---|
| 3 | A simple example using internal boundaries to represent buildings, using new |
---|
| 4 | functionality found in ANUGA 1.2. |
---|
| 5 | |
---|
| 6 | written by James Hudson |
---|
| 7 | """ |
---|
| 8 | |
---|
| 9 | #------------------------------------------------------------------------------ |
---|
| 10 | # Import necessary modules |
---|
| 11 | #------------------------------------------------------------------------------ |
---|
| 12 | import anuga |
---|
| 13 | |
---|
| 14 | def poly_from_box(W, E, N, S): |
---|
| 15 | """ |
---|
| 16 | Helper function to create a counter-clockwise polygon |
---|
| 17 | from the given box. |
---|
| 18 | |
---|
| 19 | N, E, S, W are the extents of the box. |
---|
| 20 | """ |
---|
| 21 | return [[W, N], [W, S], [E, S], [E, N]] |
---|
| 22 | |
---|
| 23 | #------------------------------------------------------------------------------ |
---|
| 24 | # Setup computational domain - a long skinny channel with obstructing boxes |
---|
| 25 | #------------------------------------------------------------------------------ |
---|
| 26 | length = 50 |
---|
| 27 | width = 10 |
---|
| 28 | resolution = 1.0 # make this number smaller to make the simulation more accurate |
---|
| 29 | |
---|
| 30 | # Create the "world" as a long, skinny channel |
---|
| 31 | boundary_poly = poly_from_box(0, length, 0, width) |
---|
| 32 | boundary_tags = {'left': [0], 'bottom': [1], 'right': [2], 'top': [3]} |
---|
| 33 | |
---|
| 34 | # Place 3 buildings downstream |
---|
| 35 | building_polys = [ poly_from_box(10, 15, 2.5, 7.5), # upstream box |
---|
| 36 | poly_from_box(22.5, 27.5, 1.5, 6.5), # middle box |
---|
| 37 | poly_from_box(35, 40, 3.5, 8.5)] # downstream box |
---|
| 38 | |
---|
| 39 | building_tags = [ { 'upstream' : [1]}, # Set segment[0], default others |
---|
| 40 | None, # Use default interior tag |
---|
| 41 | { 'downstream' : [0,1]} ] # set segments[0,1],default others |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | # create a domain mesh, with 3 building holes in it |
---|
| 45 | domain = anuga.create_domain_from_regions(boundary_poly, |
---|
| 46 | boundary_tags=boundary_tags, |
---|
| 47 | maximum_triangle_area = resolution, |
---|
| 48 | mesh_filename = 'building.msh', |
---|
| 49 | interior_holes = building_polys, |
---|
| 50 | hole_tags = building_tags, |
---|
| 51 | use_cache=True, # to speed it up |
---|
| 52 | verbose=True) # log output on |
---|
| 53 | |
---|
| 54 | domain.set_name('buildings') # Output name |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | #------------------------------------------------------------------------------ |
---|
| 58 | # Setup initial conditions |
---|
| 59 | #------------------------------------------------------------------------------ |
---|
| 60 | def topography(x,y): |
---|
| 61 | return -x/15 # gentle linear bed slope |
---|
| 62 | |
---|
| 63 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
| 64 | domain.set_quantity('friction', 0.03) # Constant friction |
---|
| 65 | domain.set_quantity('stage', |
---|
| 66 | expression='elevation') # Dry initial condition |
---|
| 67 | |
---|
| 68 | #------------------------------------------------------------------------------ |
---|
| 69 | # Setup boundary conditions |
---|
| 70 | #------------------------------------------------------------------------------ |
---|
| 71 | Bi = anuga.Dirichlet_boundary([1.0, 0, 0]) # Inflow |
---|
| 72 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
| 73 | Bo = anuga.Dirichlet_boundary([-5, 0, 0]) # Outflow |
---|
| 74 | |
---|
| 75 | print domain.get_boundary_tags() |
---|
| 76 | |
---|
| 77 | domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br, |
---|
| 78 | 'interior': Br ,# default interior boundary tag |
---|
| 79 | 'downstream': Br ,# downstream building |
---|
| 80 | 'upstream' : Br # upstream building boundary |
---|
| 81 | }) |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | #------------------------------------------------------------------------------ |
---|
| 85 | # Evolve system through time |
---|
| 86 | #------------------------------------------------------------------------------ |
---|
| 87 | for t in domain.evolve(yieldstep=0.2, finaltime=15.0): |
---|
| 88 | print domain.timestepping_statistics() |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | # now turn off the tap |
---|
| 92 | domain.set_boundary({'left': Bo}) |
---|
| 93 | |
---|
| 94 | for t in domain.evolve(yieldstep=0.1, finaltime=30.0): |
---|
| 95 | print domain.timestepping_statistics() |
---|
| 96 | |
---|