source: production/sydney_2006/run_sydney_smf.py @ 3241

Last change on this file since 3241 was 3190, checked in by sexton, 19 years ago

MOST and ANUGA comparisons and updates

File size: 11.6 KB
RevLine 
[2240]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,
[2407]8the elevation data and a simulated submarine landslide.
[2240]9
[2407]10Ole Nielsen and Duncan Gray, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006
[2240]11"""
12
13
[2407]14#-------------------------------------------------------------------------------# Import necessary modules
15#-------------------------------------------------------------------------------
16
17# Standard modules
[2240]18import os
19import time
20
[2407]21# Related major packages
[2640]22from pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary
[2407]23from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts
[2640]24#from pyvolution.data_manager_old import convert_dem_from_ascii2netcdf, dem2pts
[2407]25from pyvolution.combine_pts import combine_rectangular_points_files
[2292]26from pyvolution.pmesh2domain import pmesh_to_domain_instance
[2640]27from pyvolution.quantity import Quantity
28from Numeric import allclose
[3190]29from utilities.polygon import inside_polygon
[2240]30
[2407]31# Application specific imports
32import project                 # Definition of file names and polygons
[2460]33from pyvolution.smf import slump_tsunami  # Function for submarine mudslide
[2407]34
35
36#-------------------------------------------------------------------------------
37# Preparation of topographic data
38#
[2292]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
[2407]42#-------------------------------------------------------------------------------
43
44# filenames
[2292]45coarsedemname = project.coarsedemname
46finedemname = project.finedemname
[2240]47meshname = project.meshname+'.msh'
48
[2292]49# coarse data
[2407]50convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True)
51dem2pts(coarsedemname, use_cache=True, verbose=True)
[2240]52
[2407]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)
[2240]62
[2292]63# combining the coarse and fine data
64combine_rectangular_points_files(project.finedemname + '.pts',
65                                 project.coarsedemname + '.pts',
66                                 project.combineddemname + '.pts')
[2407]67
[2456]68#from pmesh.create_mesh import create_mesh_from_regions
[2640]69#new interface
[2456]70from pmesh.mesh_interface import create_mesh_from_regions
[2407]71
[2640]72# original issue to Benfield
[3190]73interior_res = 5000
74interior_regions = [[project.harbour_polygon_2, interior_res],
75                    [project.botanybay_polygon_2, interior_res]]
[2350]76
[2640]77# used for finer mesh
[3190]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]]
[2640]84
[3190]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
[2640]101
[3190]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
[2407]126#FIXME: Fix caching of this one once the mesh_interface is ready
127from caching import cache
[2456]128
[2640]129# original + refined region
[2407]130_ = cache(create_mesh_from_regions,
[3190]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]},
[2407]137          {'boundary_tags': {'bottom': [0], 
[3190]138                             'bottom1': [1], 'right': [2],
139                             'top1': [3], 'top': [4], 'left1': [5],
[2407]140                             'left2': [6], 'left3': [7]},
[3190]141          #{'boundary_tags': {'bottom': [0], 'right': [1],
142          #                   'top': [2], 'left': [3]},
[2456]143           'maximum_triangle_area': 100000,
[2407]144           'filename': meshname,           
[2456]145           'interior_regions': interior_regions},
[2407]146          verbose = True)
[2350]147
[2640]148#-------------------------------------------------------------------------------                                 
[2407]149# Setup computational domain
[2640]150#-------------------------------------------------------------------------------                                 
[2407]151
152domain = pmesh_to_domain_instance(meshname, Domain,
153                                  use_cache = True,
154                                  verbose = True)
155
[2240]156print 'Number of triangles = ', len(domain)
157print 'The extent is ', domain.get_extent()
[2640]158print domain.statistics()
[2240]159
160domain.set_name(project.basename)
161domain.set_datadir(project.outputdir)
[2407]162domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
[2240]163
[2407]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,
[3190]175                               x0=project.slump_origin2[0], 
176                               y0=project.slump_origin2[1], 
[2407]177                               alpha=0.0, 
[3190]178                               domain=domain,
179                               verbose=True)
[2407]180
[2640]181#-------------------------------------------------------------------------------                                 
[2407]182# Setup initial conditions
183#-------------------------------------------------------------------------------
184
[2640]185# apply slump after 30 mins, initialise to water level of tide = 0
186domain.set_quantity('stage', 0.0)
[3190]187domain.set_quantity('friction', 0.04) 
[2407]188domain.set_quantity('elevation',
189                    filename = project.combineddemname + '.pts',
190                    use_cache = True,
191                    verbose = True)
[2240]192
[2407]193
194#-------------------------------------------------------------------------------                                 
195# Setup boundary conditions (all reflective)
196#-------------------------------------------------------------------------------
197
198print 'Available boundary tags', domain.get_boundary_tags()
199
[2240]200Br = Reflective_boundary(domain)
[2640]201Bd = Dirichlet_boundary([0, 0, 0])
[2292]202
[2640]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} )
[3190]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                             
[2640]212# enforce Dirichlet BC - from 30/03/06 Benfield visit
[3190]213domain.set_boundary( {'bottom': Bd, 'bottom1': Bd, 'right': Bd,
214                      'top1': Bd, 'top': Bd, 'left1': Bd,
[2640]215                      'left2': Bd, 'left3': Bd} )
216
217# increasingly finer interior regions
[3190]218#domain.set_boundary( {'bottom': Bd, 'right': Bd, 'left': Bd, 'top': Bd} )
[2640]219
220
[2407]221#-------------------------------------------------------------------------------                                 
222# Evolve system through time
223#-------------------------------------------------------------------------------
224
[2240]225import time
226t0 = time.time()
[2640]227thisfile = project.integraltimeseries+'.csv'
228fid = open(thisfile, 'w')
[2240]229
[3190]230# save every 10 secs leading up to slump initiation
231for t in domain.evolve(yieldstep = 10, finaltime = 60): # 6 steps
[2240]232    domain.write_time()
[2640]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)
[3190]238    # add slump after 30 secs
239    if allclose(t, 30):
[2640]240        slump = Quantity(domain)
241        slump.set_values(tsunami_source)
242        domain.set_quantity('stage', slump + thisstagestep)
[3190]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)
[2240]283   
[3190]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)
[2640]293   
[2240]294print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.