source: production/sydney_2006/run_sydney_smf.py @ 3347

Last change on this file since 3347 was 3190, checked in by sexton, 18 years ago

MOST and ANUGA comparisons and updates

File size: 11.6 KB
Line 
1"""Script for running a tsunami inundation scenario for Sydney, NSW, Australia.
2
3Source data such as elevation and boundary data is assumed to be available in
4directories specified by project.py
5The output sww file is stored in project.outputdir
6
7The scenario is defined by a triangular mesh created from project.polygon,
8the elevation data and a simulated submarine landslide.
9
10Ole Nielsen and Duncan Gray, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006
11"""
12
13
14#-------------------------------------------------------------------------------# Import necessary modules
15#-------------------------------------------------------------------------------
16
17# Standard modules
18import os
19import time
20
21# Related major packages
22from pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary
23from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts
24#from pyvolution.data_manager_old import convert_dem_from_ascii2netcdf, dem2pts
25from pyvolution.combine_pts import combine_rectangular_points_files
26from pyvolution.pmesh2domain import pmesh_to_domain_instance
27from pyvolution.quantity import Quantity
28from Numeric import allclose
29from utilities.polygon import inside_polygon
30
31# Application specific imports
32import project                 # Definition of file names and polygons
33from pyvolution.smf import slump_tsunami  # Function for submarine mudslide
34
35
36#-------------------------------------------------------------------------------
37# Preparation of topographic data
38#
39# Convert ASC 2 DEM 2 PTS using source data and store result in source data
40# Do for coarse and fine data
41# Fine pts file to be clipped to area of interest
42#-------------------------------------------------------------------------------
43
44# filenames
45coarsedemname = project.coarsedemname
46finedemname = project.finedemname
47meshname = project.meshname+'.msh'
48
49# coarse data
50convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True)
51dem2pts(coarsedemname, use_cache=True, verbose=True)
52
53# fine data (clipping the points file to smaller area)
54convert_dem_from_ascii2netcdf(finedemname, use_cache=True, verbose=True)
55dem2pts(finedemname,
56        easting_min=project.eastingmin,
57        easting_max=project.eastingmax,
58        northing_min=project.northingmin,
59        northing_max= project.northingmax,
60        use_cache=True, 
61        verbose=True)
62
63# combining the coarse and fine data
64combine_rectangular_points_files(project.finedemname + '.pts',
65                                 project.coarsedemname + '.pts',
66                                 project.combineddemname + '.pts')
67
68#from pmesh.create_mesh import create_mesh_from_regions
69#new interface
70from pmesh.mesh_interface import create_mesh_from_regions
71
72# original issue to Benfield
73interior_res = 5000
74interior_regions = [[project.harbour_polygon_2, interior_res],
75                    [project.botanybay_polygon_2, interior_res]]
76
77# used for finer mesh
78#interior_res1 = 5000
79#interior_res2 = 315
80#interior_regions = [[project.newpoly1, interior_res1],
81#                    [project.south1, interior_res1],
82#                    [project.finepolymanly, interior_res2],
83#                    [project.finepolyquay, interior_res2]]
84
85# used for coastal polygons constructed by GIS guys
86def get_polygon_from_file(filename):
87    """ Function to read in output from GIS determined polygon
88    """
89    fid = open(filename)
90    lines = fid.readlines()
91    fid.close()
92   
93    polygon = []
94    for line in lines[1:]:
95       fields = line.split(',')
96       x = float(fields[1])
97       y = float(fields[2])
98       polygon.append([x, y])
99       
100    return polygon
101
102num_polygons = 9
103fileext = '.csv'
104filename = project.polygonptsfile
105
106#interior_res = 1000
107#interior_regions = []
108#bounding_polygon = project.diffpolygonall#project.demopoly
109#count = 0
110#for p in range(1, num_polygons+1):
111#    thefilename = filename + str(p) + fileext
112#    print 'reading in polygon points', thefilename
113#    interior_polygon = get_polygon_from_file(thefilename)
114#    interior_regions.append([interior_polygon, interior_res])
115#    n = len(interior_polygon)
116#    # check interior polygon falls in bounding polygon
117#    if len(inside_polygon(interior_polygon, bounding_polygon,
118#                   closed = True, verbose = False)) <> len(interior_polygon):
119#        print 'WARNING: interior polygon %d is outside bounding polygon' %(p)
120#        count += 1
121#    # check for duplicate points in interior polygon
122   
123print 'number of interior polygons: ', len(interior_regions)
124#if count == 0: print 'interior polygons OK'
125
126#FIXME: Fix caching of this one once the mesh_interface is ready
127from caching import cache
128
129# original + refined region
130_ = cache(create_mesh_from_regions,
131          #project.demopoly,
132          project.diffpolygonall2,
133          #{'boundary_tags': {'bottom': [0],
134          #                   'right1': [1], 'right0': [2],
135          #                   'right2': [3], 'top': [4], 'left1': [5],
136          #                   'left2': [6], 'left3': [7]},
137          {'boundary_tags': {'bottom': [0], 
138                             'bottom1': [1], 'right': [2],
139                             'top1': [3], 'top': [4], 'left1': [5],
140                             'left2': [6], 'left3': [7]},
141          #{'boundary_tags': {'bottom': [0], 'right': [1],
142          #                   'top': [2], 'left': [3]},
143           'maximum_triangle_area': 100000,
144           'filename': meshname,           
145           'interior_regions': interior_regions},
146          verbose = True)
147
148#-------------------------------------------------------------------------------                                 
149# Setup computational domain
150#-------------------------------------------------------------------------------                                 
151
152domain = pmesh_to_domain_instance(meshname, Domain,
153                                  use_cache = True,
154                                  verbose = True)
155
156print 'Number of triangles = ', len(domain)
157print 'The extent is ', domain.get_extent()
158print domain.statistics()
159
160domain.set_name(project.basename)
161domain.set_datadir(project.outputdir)
162domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
163
164
165#-------------------------------------------------------------------------------
166# Set up scenario (tsunami_source is a callable object used with set_quantity)
167#-------------------------------------------------------------------------------
168
169tsunami_source = slump_tsunami(length=30000.0,
170                               depth=400.0,
171                               slope=6.0,
172                               thickness=176.0, 
173                               radius=3330,
174                               dphi=0.23,
175                               x0=project.slump_origin2[0], 
176                               y0=project.slump_origin2[1], 
177                               alpha=0.0, 
178                               domain=domain,
179                               verbose=True)
180
181#-------------------------------------------------------------------------------                                 
182# Setup initial conditions
183#-------------------------------------------------------------------------------
184
185# apply slump after 30 mins, initialise to water level of tide = 0
186domain.set_quantity('stage', 0.0)
187domain.set_quantity('friction', 0.04) 
188domain.set_quantity('elevation',
189                    filename = project.combineddemname + '.pts',
190                    use_cache = True,
191                    verbose = True)
192
193
194#-------------------------------------------------------------------------------                                 
195# Setup boundary conditions (all reflective)
196#-------------------------------------------------------------------------------
197
198print 'Available boundary tags', domain.get_boundary_tags()
199
200Br = Reflective_boundary(domain)
201Bd = Dirichlet_boundary([0, 0, 0])
202
203# original + refined regions
204#domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br,
205#                      'right2': Br, 'top': Br, 'left1': Br,
206#                      'left2': Br, 'left3': Br} )
207# for new tests 4 April 2006
208#domain.set_boundary( {'bottom': Br, 'bottom1': Br, 'right': Br,
209#                      'top1': Br, 'top': Br, 'left1': Br,
210#                      'left2': Br, 'left3': Br} )
211                             
212# enforce Dirichlet BC - from 30/03/06 Benfield visit
213domain.set_boundary( {'bottom': Bd, 'bottom1': Bd, 'right': Bd,
214                      'top1': Bd, 'top': Bd, 'left1': Bd,
215                      'left2': Bd, 'left3': Bd} )
216
217# increasingly finer interior regions
218#domain.set_boundary( {'bottom': Bd, 'right': Bd, 'left': Bd, 'top': Bd} )
219
220
221#-------------------------------------------------------------------------------                                 
222# Evolve system through time
223#-------------------------------------------------------------------------------
224
225import time
226t0 = time.time()
227thisfile = project.integraltimeseries+'.csv'
228fid = open(thisfile, 'w')
229
230# save every 10 secs leading up to slump initiation
231for t in domain.evolve(yieldstep = 10, finaltime = 60): # 6 steps
232    domain.write_time()
233    domain.write_boundary_statistics(tags = 'bottom')
234    # calculate integral
235    thisstagestep = domain.get_quantity('stage') 
236    s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral())
237    fid.write(s)
238    # add slump after 30 secs
239    if allclose(t, 30):
240        slump = Quantity(domain)
241        slump.set_values(tsunami_source)
242        domain.set_quantity('stage', slump + thisstagestep)
243        #test_stage = domain.get_quantity('stage')
244        #test_elevation = domain.get_quantity('elevation')
245        #test_depth = test_stage - test_elevation
246        #test_max = max(test_depth.get_values())
247        #print 'testing', test_max
248
249import sys; sys.exit()
250
251# save every two minutes leading up to interesting period
252for t in domain.evolve(yieldstep = 120, finaltime = 660, # steps
253                       skip_initial_step = True): 
254    domain.write_time()
255    domain.write_boundary_statistics(tags = 'bottom')
256    # calculate integral
257    thisstagestep = domain.get_quantity('stage') 
258    s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral())
259    fid.write(s)
260
261
262# save every thirty secs during interesting period
263for t in domain.evolve(yieldstep = 60, finaltime = 5000, # steps
264                       skip_initial_step = True):
265    domain.write_time()
266    domain.write_boundary_statistics(tags = 'bottom') #quantities = 'stage')
267    # calculate integral
268    thisstagestep = domain.get_quantity('stage') 
269    s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral())
270    fid.write(s)
271
272
273import sys; sys.exit()
274# save every two mins for next 5000 secs
275for t in domain.evolve(yieldstep = 120, finaltime = 10000, # about 42 steps
276                       skip_initial_step = True):
277    domain.write_time()
278    domain.write_boundary_statistics(tags = 'bottom') #quantities = 'stage')
279    # calculate integral
280    thisstagestep = domain.get_quantity('stage') 
281    s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral())
282    fid.write(s)
283   
284# save every half hour to end of simulation   
285for t in domain.evolve(yieldstep = 1800, finaltime = 10*60*60, # 14 steps
286                       skip_initial_step = True):
287    domain.write_time()
288    domain.write_boundary_statistics(tags = 'bottom') #quantities = 'stage'
289    # calculate integral
290    thisstagestep = domain.get_quantity('stage') 
291    s = '%.2f, %.2f\n' %(t, thisstagestep.get_integral())
292    fid.write(s)
293   
294print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.