source: trunk/anuga_core/demos/buildings.py @ 8969

Last change on this file since 8969 was 8728, checked in by steve, 12 years ago

Adding in usermanual and demos

File size: 3.9 KB
Line 
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#------------------------------------------------------------------------------
12import anuga
13
14def 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#------------------------------------------------------------------------------
26length = 50
27width = 10
28resolution = 1.0 # make this number smaller to make the simulation more accurate
29
30# Create the "world" as a long, skinny channel
31boundary_poly = poly_from_box(0, length, 0, width)
32boundary_tags = {'left': [0], 'bottom': [1], 'right': [2], 'top': [3]}
33
34# Place 3 buildings downstream
35building_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                                       
39building_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
45domain = 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 
54domain.set_name('buildings')                 # Output name
55
56
57#------------------------------------------------------------------------------
58# Setup initial conditions
59#------------------------------------------------------------------------------
60def topography(x,y):
61    return -x/15                             # gentle linear bed slope
62
63domain.set_quantity('elevation', topography) # Use function for elevation
64domain.set_quantity('friction', 0.03)        # Constant friction
65domain.set_quantity('stage',
66                    expression='elevation')  # Dry initial condition
67
68#------------------------------------------------------------------------------
69# Setup boundary conditions
70#------------------------------------------------------------------------------
71Bi = anuga.Dirichlet_boundary([1.0, 0, 0])   # Inflow
72Br = anuga.Reflective_boundary(domain)       # Solid reflective wall
73Bo = anuga.Dirichlet_boundary([-5, 0, 0])    # Outflow
74
75print domain.get_boundary_tags()
76
77domain.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#------------------------------------------------------------------------------
87for t in domain.evolve(yieldstep=0.2, finaltime=15.0):
88    print domain.timestepping_statistics()
89
90   
91# now turn off the tap
92domain.set_boundary({'left': Bo})
93
94for t in domain.evolve(yieldstep=0.1, finaltime=30.0):
95    print domain.timestepping_statistics()       
96
Note: See TracBrowser for help on using the repository browser.