source: documentation/user_manual/examples/harbour.py @ 3383

Last change on this file since 3383 was 3275, checked in by sexton, 19 years ago

updates on sydney demo for user manual

File size: 5.8 KB
RevLine 
[3224]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#------------------------------------------------------------------------------
16
17from pmesh.mesh_interface import create_mesh_from_regions
18from pyvolution.shallow_water import Domain
19from pyvolution.shallow_water import Reflective_boundary
20from pyvolution.shallow_water import Dirichlet_boundary
21from pyvolution.shallow_water import Time_boundary
22from pyvolution.shallow_water import Transmissive_boundary
23
24waveheight = 1.0
25harbour_length = 2000.0 
26shelf_length = 10000.0
[3248]27bottom_length = 10000.0
[3224]28harbour_width = 250.0
29shelf_depth = -100. 
30harbour_depth = -10.
31if harbour_depth > shelf_depth: print 'WARNING: depths not consistent'
32#------------------------------------------------------------------------------
33# Setup computational domain
34#------------------------------------------------------------------------------
35
[3275]36east = 10000.+harbour_length+shelf_length+bottom_length
37west = 0.
[3248]38south = 0.
39north = 5000.
[3224]40polygon = [[east,north],[west,north],[west,south],[east,south]]
41meshname = 'harbour_test.msh'
42
43create_mesh_from_regions(polygon,
44                         boundary_tags={'top': [0],
45                                        'left': [1],
46                                        'bottom': [2],
47                                        'right': [3]},
48                         maximum_triangle_area=50000,
49                         filename=meshname)
50                         #interior_regions=interior_regions)
51
52domain = Domain(meshname,use_cache=True,verbose = True)
[3247]53domain.set_name('harbour')                  # Output to harbour.sww
[3224]54domain.set_datadir('.')                     # Use current directory for output
55domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities
56                                    'xmomentum',
57                                    'ymomentum'])   
58
59
60#------------------------------------------------------------------------------
61# Setup initial conditions
62#------------------------------------------------------------------------------
63# if can't do this, then can set up x = arange(west,east,xstep)
64# and y = arange(south,north,ystep) and use Geospatial data to set elevation
65
66def topography(x,y):
67    from Numeric import zeros, Float
68    z = zeros(len(x),len(y),Float)
69    ycentre = (south+north)/2.
70    ycentreup = ycentre+harbour_width/2.
71    ycentredown = ycentre-harbour_width/2.
72    for i, xi in enumerate(x):
73        for j, yi in enumerate(y):
74           if xi >= centre: z[i,j] = shelf_depth
75           if xi > west and xi <= centre-harbour_length: 
76                if yi < ycentredown: z[i,j] = 0.0
77                if yi > ycentreup: z[i,j] = 0.0
[3247]78                if yi > ycentredown and yi < ycentreup: z[i,j] = harbour_depth
79           if xi > centre-harbour_length and xi < centre: z[i,j] = harbour_depth
[3224]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 = Reflective_boundary(domain)      # Solid reflective wall
92Bt = Transmissive_boundary(domain)    # Continue all values on boundary
93Bd = Dirichlet_boundary([0.,0.,0.])   # Constant boundary values
94Bw = 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
[3247]108#-----------------------------------------------------------------------------
109# Interrogate solution
110#-----------------------------------------------------------------------------
111
[3224]112# Gauge line
113def gauge_line(west,east,north,south):
114    from Numeric import arange
[3248]115    gaugex = arange(east,west,-1000.)
[3224]116    gauges = []
[3248]117    gaugey = []
[3224]118    for x in gaugex:
119        y = (north+south)/2.
[3248]120        gaugey.append(y)
[3224]121        gauges.append([x,y])
[3248]122    return gauges, gaugex, gaugey
[3224]123
[3248]124gauges, gaugex, gaugey = gauge_line(west,east,north,south)
[3224]125
[3247]126from pyvolution.util import file_function
127
128f = file_function('harbour.sww',
129                  quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
130                  interpolation_points = gauges,
131                  verbose = True,
132                  use_cache = True)
133
[3248]134from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure
135ion()
136
137maxw = []
138minw = []
139maxd = []
140count = 0
[3224]141for k, g in enumerate(gauges):
[3248]142    stage = []
143    elevation = []
144    depths = []
[3224]145    for i, t in enumerate(f.get_time()):
[3247]146        w = f(t, point_id = k)[0]
[3248]147        elev = f(t, point_id = k)[1]
148        depth = w-elev
149        stage.append(w)
150        elevation.append(elev)
151        depths.append(elev)
152    maxw.append(max(stage))
153    minw.append(min(stage))
154    maxd.append(max(depths))
[3224]155
[3248]156filename = 'point'+str(waveheight)+'.csv'
157fid = open(filename,'w')   
158s = 'Waveheight,\n'
159fid.write(s)
160
161figure(1)
162plot(gaugex[:loc],maxw[:loc],'g-')
[3224]163xlabel('x')
164ylabel('stage')
165title('Maximum stage for gauge line')
[3248]166savefig('max_stage')
167
[3247]168close('all')
Note: See TracBrowser for help on using the repository browser.