source: production/sydney_2006/run_sydney_smf_polyingo.py @ 3171

Last change on this file since 3171 was 2732, checked in by sexton, 19 years ago

updates on the black screen of death

File size: 10.0 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, Time_boundary
23from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts
24from pyvolution.combine_pts import combine_rectangular_points_files
25from pyvolution.pmesh2domain import pmesh_to_domain_instance
26from pyvolution.quantity import Quantity
27from geospatial_data import *
28
29# Application specific imports
30import project                 # Definition of file names and polygons
31from smf import slump_tsunami  # Function for submarine mudslide
32
33
34#-------------------------------------------------------------------------------
35# Preparation of topographic data
36#
37# Convert ASC 2 DEM 2 PTS using source data and store result in source data
38# Do for coarse and fine data
39# Fine pts file to be clipped to area of interest
40#-------------------------------------------------------------------------------
41# filenames
42coarsedemname = project.coarsedemname
43finedemname = project.finedemname
44
45
46# coarse data
47convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True)
48#dem2pts(coarsedemname, use_cache=True, verbose=True)
49dem2pts(coarsedemname,
50        easting_min=project.eastingmin,
51        easting_max=project.eastingmax,
52        northing_min=project.northingmin,
53        northing_max= project.northingmax,
54        use_cache=True, 
55        verbose=True)
56
57# fine data (clipping the points file to smaller area)
58convert_dem_from_ascii2netcdf(finedemname, use_cache=True, verbose=True)
59dem2pts(finedemname,
60        easting_min=project.eastingmin,
61        easting_max=project.eastingmax,
62        northing_min=project.northingmin,
63        northing_max= project.northingmax,
64        use_cache=True, 
65        verbose=True)
66
67
68# combining the coarse and fine data
69combine_rectangular_points_files(project.finedemname + '.pts',
70                                 project.coarsedemname + '.pts',
71                                 project.combineddemname + '.pts')
72
73#-------------------------------------------------------------------------------                                 
74# Create the triangular mesh based on overall clipping polygon with a tagged
75# boundary and interior regions defined in project.py along with
76# resolutions (maximal area of per triangle) for each polygon
77#-------------------------------------------------------------------------------
78#from pmesh.create_mesh import create_mesh_from_regions
79from pmesh.mesh_interface import create_mesh_from_regions
80
81meshname = project.meshname4+'.msh'
82
83interior_res1 = 25000
84interior_res2 = 1315
85print 'interior resolution', interior_res1, interior_res2
86
87# Read in files containing polygon points (generated by GIS)
88# and construct list of interior polygons into interior_regions.
89
90def get_polygon_from_file(filename):
91    """ Function to read in output from GIS determined polygon
92    """
93    fid = open(filename)
94    lines = fid.readlines()
95    fid.close()
96   
97    polygon = []
98    for line in lines[1:]:
99       fields = line.split(',')
100       x = float(fields[1])
101       y = float(fields[2])
102       polygon.append([x, y])
103       
104    return polygon
105
106num_polygons = 3
107fileext = '.csv'
108filename = project.polygonptsfile
109
110interior_regions = []
111
112for p in range(3, num_polygons+1):
113    thefilename = filename + str(p) + fileext
114    print 'reading in polygon points', thefilename
115    interior_polygon = get_polygon_from_file(thefilename)
116    interior_regions.append([interior_polygon, interior_res1])
117
118print 'number of interior polygons: ', len(interior_regions)
119
120#print 'Number of interior polygons: ', len(interior_regions)
121
122# original
123#interior_regions = []
124#interior_regions = [[project.harbour_polygon_2, interior_res1],
125#                    [project.botanybay_polygon_2, interior_res1]]
126
127# finer set
128#interior_regions = [[project.newpoly1, interior_res1],
129#                    #[project.parrariver, interior_res1], #remove for second run
130#                    [project.south1, interior_res1],
131#                    [project.finepolymanly, interior_res2],
132#                    [project.finepolyquay, interior_res2]]
133
134#FIXME: Fix caching of this one once the mesh_interface is ready
135from caching import cache
136
137#_ = cache(create_mesh_from_regions,
138#          project.diffpolygonall,
139#          {'boundary_tags': {'bottom': [0],
140#                             'right1': [1], 'right0': [2],
141#                             'right2': [3], 'top': [4], 'left1': [5],
142#                             'left2': [6], 'left3': [7]},
143#           'maximum_triangle_area': 100000,
144#           'filename': meshname,           
145#           'interior_regions': interior_regions},
146#          verbose = True)
147
148_ = cache(create_mesh_from_regions,
149          project.diffpolygonall_test,
150          {'boundary_tags': {'bottom': [0], 'right': [1],
151                             'top': [2], 'left': [3]},
152           'maximum_triangle_area': 100000,
153           'filename': meshname,           
154           'interior_regions': interior_regions},
155          verbose = True)
156
157#mesh_geo_reference:
158#-------------------------------------------------------------------------------                                 
159# Setup computational domain
160#-------------------------------------------------------------------------------                                 
161
162domain = pmesh_to_domain_instance(meshname, Domain,
163                                  use_cache = True,
164                                  verbose = True)
165
166print 'Number of triangles = ', len(domain)
167print 'The extent is ', domain.get_extent()
168print domain.statistics()
169
170domain.set_name(project.basename4)
171domain.set_datadir(project.outputdir)
172domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
173
174
175
176
177#-------------------------------------------------------------------------------
178# Set up scenario (tsunami_source is a callable object used with set_quantity)
179#-------------------------------------------------------------------------------
180
181tsunami_source = slump_tsunami(length=30000.0,
182                               depth=400.0,
183                               slope=6.0,
184                               thickness=176.0, 
185                               radius=3330,
186                               dphi=0.23,
187                               x0=project.slump_origin[0], 
188                               y0=project.slump_origin[1], 
189                               alpha=0.0, 
190                               domain=domain)
191
192#print 'testing', tsunami_source.get_integral()
193
194#-------------------------------------------------------------------------------                                 
195# Setup initial conditions
196#-------------------------------------------------------------------------------
197
198G = Geospatial_data(project.test_pts, project.test_elev) #points, attributes
199domain.set_quantity('stage', 0) #tsunami_source)
200domain.set_quantity('friction', 0.0) # supplied by Benfield, initial value 0.03
201domain.set_quantity('elevation', alpha = 10.0,#G, alpha = 550.0,
202                    #filename = project.combineddemname + '.pts',
203                    filename = project.coarsedemname + '.pts',
204                    use_cache = False,
205                    verbose = True)
206
207from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA
208
209#Add elevation data to the mesh
210#fit_to_mesh_file(mesh_file, point_file, mesh_output_file, DEFAULT_ALPHA,
211#                 verbose=True, expand_search=True, precrop=True)
212#pointname = project.coarsedemname + '.pts'
213#mesh_elevname = project.meshelevname
214#cache(fit_to_mesh_file,(meshname,
215#                 pointname,
216#                 mesh_elevname,
217#                 DEFAULT_ALPHA),
218#      {'verbose': True,
219#       'expand_search': True,
220#       'precrop': True}
221#      ,dependencies = [meshname, pointname]
222#      #,evaluate = True     
223#      ,verbose = False
224#      )
225
226#-------------------------------------------------------------------------------                                 
227# Setup boundary conditions (all reflective)
228#-------------------------------------------------------------------------------
229
230print 'Available boundary tags', domain.get_boundary_tags()
231
232Br = Reflective_boundary(domain)
233
234#domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br,
235#                      'right2': Br, 'top': Br, 'left1': Br,
236#                      'left2': Br, 'left3': Br} )
237domain.set_boundary( {'bottom': Br, 'right': Br, 'left': Br, 'top': Br} )
238#domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br,
239#                      'right2': Br, 'top': Br, 'left1': Br,
240#                      'left2': Br, 'left3': Br} )
241
242
243#-------------------------------------------------------------------------------                                 
244# Evolve system through time
245#-------------------------------------------------------------------------------
246
247import time
248t0 = time.time()
249thisfile = project.integraltimeseries+'.csv'
250fid = open(thisfile, 'w')
251   
252# original
253for t in domain.evolve(yieldstep = 1, finaltime = 10):
254    domain.write_time()
255    domain.write_boundary_statistics(tags = 'bottom')
256    stagestep = domain.get_quantity('stage') 
257    s = '%.2f, %.2f\n' %(t, stagestep.get_integral())
258    fid.write(s)
259
260print 'That took %.2f seconds' %(time.time()-t0)
261
262
263
Note: See TracBrowser for help on using the repository browser.