source: production/pt_hedland_2006/run_pt_hedland.py @ 2904

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

add plot of polygons to script

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