source: production/pt_hedland_2006/run_pt_hedland.py @ 3031

Last change on this file since 3031 was 2955, checked in by nick, 19 years ago

update pt hedland
geospatial_data object updated
updated polygon.py to allow numeric arrays

File size: 9.9 KB
Line 
1"""Script for running a tsunami inundation scenario for Onslow, WA, 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.outputtimedir
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 Nick Bartzis, GA - 2006
11"""
12
13
14#-------------------------------------------------------------------------------# Import necessary modules
15#-------------------------------------------------------------------------------
16
17# Standard modules
18import os 
19
20from os import sep
21from os.path import dirname, basename
22
23import time
24
25# Related major packages
26from pyvolution.shallow_water import Domain, Reflective_boundary, \
27                            Dirichlet_boundary, Time_boundary, File_boundary
28from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts
29from pyvolution.combine_pts import combine_rectangular_points_files
30from pyvolution.pmesh2domain import pmesh_to_domain_instance
31#from geospatial_data import add_points_files
32
33# Application specific imports
34import project                 # Definition of file names and polygons
35from smf import slump_tsunami  # Function for submarine mudslide
36
37from shutil import copy
38from os import mkdir, access, F_OK
39
40from geospatial_data import *
41import sys
42from pyvolution.util import Screen_Catcher
43
44#-------------------------------------------------------------------------------
45# Preparation of topographic data
46#
47# Convert ASC 2 DEM 2 PTS using source data and store result in source data
48# Do for coarse and fine data
49# Fine pts file to be clipped to area of interest
50#-------------------------------------------------------------------------------
51
52# filenames
53onshore_dem_name = project.onshore_dem_name
54offshore_points1 = project.offshore_dem_name1
55offshore_points2 = project.offshore_dem_name2
56meshname = project.meshname+'.msh'
57source_dir = project.boundarydir
58
59
60
61
62#import sys; sys.exit()
63
64# creates copy of code in output dir if dir doesn't exist
65if access(project.outputtimedir,F_OK) == 0 :
66    mkdir (project.outputtimedir)
67copy (dirname(project.__file__) +sep+ project.__name__+'.py', project.outputtimedir + project.__name__+'.py')
68copy (__file__, project.outputtimedir + basename(__file__))
69
70
71#normal screen output is stored in
72screen_output_name = project.outputtimedir + "screen_output.txt"
73screen_error_name = project.outputtimedir + "screen_error.txt"
74
75#used to catch screen output to file
76#sys.stdout = Screen_Catcher(screen_output_name)
77#sys.stderr = Screen_Catcher(screen_error_name)
78
79
80'''
81# fine data (clipping the points file to smaller area)
82# creates DEM from asc data
83convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True)
84
85#creates pts file from DEM
86dem2pts(onshore_dem_name,
87        easting_min=project.eastingmin,
88        easting_max=project.eastingmax,
89        northing_min=project.northingmin,
90        northing_max= project.northingmax,
91        use_cache=True,
92        verbose=True)
93
94print'create G1'
95G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya')
96
97print'create G2'
98G2 = Geospatial_data(file_name = project.offshore_dem_name2 + '.xya')
99
100print'create G3'
101G3 = Geospatial_data(file_name = project.onshore_dem_name + '.pts')
102
103print'add G1+G2+G3'
104G = G1 + G2 + G3
105
106print'export G'
107G.export_points_file(project.combined_dem_name + '.pts')
108
109'''
110#-------------------------------------------------------------------------------                                 
111# Create the triangular mesh based on overall clipping polygon with a tagged
112# boundary and interior regions defined in project.py along with
113# resolutions (maximal area of per triangle) for each polygon
114#-------------------------------------------------------------------------------
115
116from pmesh.mesh_interface import create_mesh_from_regions
117
118region_res = 100000
119coast_res = 2500
120pt_hedland_res = 500
121# derive poly_coast from project.coast_name using alpha_shape
122interior_regions = [[project.poly_pt_hedland, pt_hedland_res],
123                    [project.poly_coast, coast_res]]
124#                    [project.poly_region, region_res]]
125
126print 'number of interior regions', len(interior_regions)
127
128from utilities.polygon import inside_polygon, plot_polygons
129
130bounding_polygon = project.polyAll
131count = 0
132for i in range(len(interior_regions)):
133    region = interior_regions[i]
134    interior_polygon = region[0]
135    if len(inside_polygon(interior_polygon, bounding_polygon,
136                   closed = True, verbose = False)) <> len(interior_polygon):
137        print 'WARNING: interior polygon %d is outside bounding polygon' %(i)
138        count += 1
139
140figname = 'pt_hedland_polys'
141print'pt_hedland_polys'
142#plot_polygons([project.polyAll, project.poly_pt_hedland, project.poly_region],
143plot_polygons([project.poly_coast],
144              figname,
145              verbose = True)
146
147if count == 0:
148    print 'interior regions OK'
149else:
150    print 'check out your interior polygons'
151    print 'check %s in production directory' %figname
152    import sys; sys.exit()
153
154print 'start create mesh from regions'
155from caching import cache
156_ = cache(create_mesh_from_regions,
157          project.polyAll,
158#          {'boundary_tags': {'right': [0], 'bottomright': [1],
159#                             'bottomleft': [2], 'left': [3], 'top': [4]},
160          {'boundary_tags': {'topright': [0], 'top': [1],'topleft': [2], 'left': [3],
161                             'bottomleft': [4], 'bottomright': [5], 'right': [6]},
162           'maximum_triangle_area': 10000000,
163           'filename': meshname,           
164           'interior_regions': interior_regions},
165          verbose = True)
166
167
168#-------------------------------------------------------------------------------                                 
169# Setup computational domain
170#-------------------------------------------------------------------------------                                 
171'''
172domain = pmesh_to_domain_instance(meshname, Domain,
173                                  use_cache = False,
174                                  verbose = True)
175'''
176
177domain = Domain(meshname, use_cache = False, verbose = True)
178
179print 'Number of triangles = ', len(domain)
180print 'The extent is ', domain.get_extent()
181print domain.statistics()
182
183domain.set_name(project.basename)
184domain.set_datadir(project.outputtimedir)
185domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
186
187#-------------------------------------------------------------------------------                                 
188# Setup initial conditions
189#-------------------------------------------------------------------------------
190
191tide = 0.
192
193domain.set_quantity('stage', tide)
194domain.set_quantity('friction', 0.0) 
195print 'hi and file',project.combined_dem_name + '.pts'
196
197domain.set_quantity('elevation', 
198                    filename = project.combined_dem_name + '.pts',
199                    use_cache = True,
200                    verbose = True,
201                    alpha = 0.1
202                    )
203
204#print 'have sent quantities OK - now exiting'
205#import sys; sys.exit()
206
207#-------------------------------------------------------------------------------                                 
208# Setup boundary conditions (all reflective)
209#-------------------------------------------------------------------------------
210print 'start ferret2sww'
211# skipped as results in file SU-AU_clipped is correct for all WA
212
213from pyvolution.data_manager import ferret2sww
214
215south = project.south
216north = project.north
217west = project.west
218east = project.east
219
220#note only need to do when an SWW file for the MOST boundary doesn't exist
221cache(ferret2sww,
222      (source_dir + project.boundary_basename,
223       source_dir + project.boundary_basename), 
224      {'verbose': True,
225       'minlat': south,
226       'maxlat': north,
227       'minlon': west,
228       'maxlon': east,
229#       'origin': project.mesh_origin,
230       'origin': domain.geo_reference.get_origin(),
231       'mean_stage': tide,
232       'zscale': 1,                 #Enhance tsunami
233       'fail_on_NaN': False,
234       'inverted_bathymetry': True},
235      #evaluate = True,
236       verbose = True)
237
238
239print 'Available boundary tags', domain.get_boundary_tags()
240
241Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
242                    domain, verbose = True)
243Br = Reflective_boundary(domain)
244Bd = Dirichlet_boundary([tide,0,0])
245
246# 7 min square wave starting at 1 min, 6m high
247Bw = Time_boundary(domain = domain,
248                   f=lambda t: [(60<t<480)*6, 0, 0])
249
250#domain.set_boundary( {'top': Bf, 'left': Br, 'bottomleft': Br, 'bottomright': Br, 'right': Br} )
251#
252domain.set_boundary( {'topright': Bf, 'top': Bf,'topleft': Bf, 'left':  Br,
253                             'bottomleft': Br, 'bottomright': Br, 'right': Br})
254                             
255#-------------------------------------------------------------------------------                                 
256# Evolve system through time
257#-------------------------------------------------------------------------------
258import time
259t0 = time.time()
260
261for t in domain.evolve(yieldstep = 240, finaltime = 7200): 
262    domain.write_time()
263    domain.write_boundary_statistics(tags = 'top')     
264
265for t in domain.evolve(yieldstep = 120, finaltime = 12600
266                       ,skip_initial_step = True): 
267    domain.write_time()
268    domain.write_boundary_statistics(tags = 'top')     
269
270for t in domain.evolve(yieldstep = 60, finaltime = 19800
271                       ,skip_initial_step = True): 
272    domain.write_time()
273    domain.write_boundary_statistics(tags = 'top')     
274   
275for t in domain.evolve(yieldstep = 120, finaltime = 25200
276                       ,skip_initial_step = True): 
277    domain.write_time()
278    domain.write_boundary_statistics(tags = 'top')     
279
280for t in domain.evolve(yieldstep = 240, finaltime = 36000
281                       ,skip_initial_step = True): 
282    domain.write_time()
283    domain.write_boundary_statistics(tags = 'top')     
284 
285print 'That took %.2f seconds' %(time.time()-t0)
286
287print 'finished'
Note: See TracBrowser for help on using the repository browser.