source: trunk/anuga_documentation/user_manual/examples/harbour.py @ 9268

Last change on this file since 9268 was 8181, checked in by steve, 14 years ago

Jakir found a problem

File size: 5.6 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water driven towards a continental slope and into a harbour
4environment. Set up as per:
5P.L.-F Liu
6Effects of the Continental Shelf on Harbor Resonance, in
7Tsunamis - Their Science and Engineering,
8edited by K. Iida and T. Iwasaki, 303-314.
91983, Terra Scientific Publishing Company, Tokyo.
10
11"""
12
13#------------------------------------------------------------------------------
14# Import necessary modules
15#------------------------------------------------------------------------------
16import anuga
17
18waveheight = 1.0
19harbour_length = 2000.0 
20shelf_length = 10000.0
21bottom_length = 10000.0
22harbour_width = 250.0
23shelf_depth = -100. 
24harbour_depth = -10.
25if harbour_depth > shelf_depth: print 'WARNING: depths not consistent'
26#------------------------------------------------------------------------------
27# Setup computational domain
28#------------------------------------------------------------------------------
29
30east = 10000.+harbour_length+shelf_length+bottom_length
31west = 0.
32south = 0.
33north = 5000.
34polygon = [[east,north],[west,north],[west,south],[east,south]]
35meshname = 'harbour_test.msh'
36
37anuga.create_mesh_from_regions(polygon,
38                         boundary_tags={'top': [0],
39                                        'left': [1],
40                                        'bottom': [2],
41                                        'right': [3]},
42                         maximum_triangle_area=50000,
43                         filename=meshname)
44                         #interior_regions=interior_regions)
45
46domain = anuga.Domain(meshname,use_cache=True,verbose = True)
47domain.set_name('harbour')                  # Output to harbour.sww
48domain.set_datadir('.')                     # Use current directory for output
49
50domain.quantities_to_be_stored = {'elevation': 1, 
51                                        'stage': 2, 
52                                        'xmomentum': 2, 
53                                        'ymomentum': 2}
54 
55
56
57#------------------------------------------------------------------------------
58# Setup initial conditions
59#------------------------------------------------------------------------------
60# if can't do this, then can set up x = arange(west,east,xstep)
61# and y = arange(south,north,ystep) and use Geospatial data to set elevation
62
63def topography(x,y):
64    from numpy import zeros, float
65    z = zeros(len(x), float)
66   
67    xcentre = (west+east)/2.
68    ycentre = (south+north)/2.
69    ycentreup = ycentre+harbour_width/2.
70    ycentredown = ycentre-harbour_width/2.
71    for i, xi in enumerate(x):
72        yi = y[i]
73        if xi >= xcentre: z[i] = shelf_depth
74        if xi > west and xi <= xcentre-harbour_length: 
75            if yi < ycentredown: z[i] = 0.0
76            if yi > ycentreup: z[i] = 0.0
77            if yi > ycentredown and yi < ycentreup: z[i] = harbour_depth
78        if xi > xcentre-harbour_length and xi < xcentre: z[i] = harbour_depth
79       
80    return z
81
82domain.set_quantity('elevation', topography) # Use function for elevation
83domain.set_quantity('friction', 0. )         # Constant friction
84domain.set_quantity('stage', 0.0)            # Constant initial stage
85
86#------------------------------------------------------------------------------
87# Setup boundary conditions
88#------------------------------------------------------------------------------
89
90from math import sin, pi
91Br = anuga.Reflective_boundary(domain)      # Solid reflective wall
92Bt = anuga.Transmissive_boundary(domain)    # Continue all values on boundary
93Bd = anuga.Dirichlet_boundary([0.,0.,0.])   # Constant boundary values
94Bw = anuga.Time_boundary(domain=domain,     # Time dependent boundary 
95                   f=lambda t: [((10<t<20)*waveheight), 0.0, 0.0])
96
97# Associate boundary tags with boundary objects
98domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br})
99
100#------------------------------------------------------------------------------
101# Evolve system through time
102#------------------------------------------------------------------------------
103
104stagestep = []
105for t in domain.evolve(yieldstep = 10, finaltime = 100.0):
106    domain.write_time()
107
108#-----------------------------------------------------------------------------
109# Interrogate solution
110#-----------------------------------------------------------------------------
111
112# Gauge line
113def gauge_line(west,east,north,south):
114    from numpy import arange
115    gaugex = arange(east,west,-1000.)
116    gauges = []
117    gaugey = []
118    for x in gaugex:
119        y = (north+south)/2.
120        gaugey.append(y)
121        gauges.append([x,y])
122    return gauges, gaugex, gaugey
123
124gauges, gaugex, gaugey = gauge_line(west,east,north,south)
125
126f = anuga.file_function('harbour.sww',
127                  quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
128                  interpolation_points = gauges,
129                  verbose = True,
130                  use_cache = True)
131
132from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure, show
133ion()
134
135maxw = []
136minw = []
137maxd = []
138count = 0
139for k, g in enumerate(gauges):
140    stage = []
141    elevation = []
142    depths = []
143    for i, t in enumerate(f.get_time()):
144        w = f(t, point_id = k)[0]
145        elev = f(t, point_id = k)[1]
146        depth = w-elev
147        stage.append(w)
148        elevation.append(elev)
149        depths.append(elev)
150    maxw.append(max(stage))
151    minw.append(min(stage))
152    maxd.append(max(depths))
153
154filename = 'point'+str(waveheight)+'.csv'
155fid = open(filename,'w')   
156s = 'Waveheight,\n'
157fid.write(s)
158
159figure(1)
160plot(gaugex,maxw,'g-')
161xlabel('x')
162ylabel('stage')
163title('Maximum stage for gauge line')
164show()
165savefig('max_stage')
166
167close('all')
Note: See TracBrowser for help on using the repository browser.