source: production/pt_hedland_2006/run_pt_hedland.py @ 3271

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

update pt hedland scripts to write output results to perlite 2 - note, must change INUNDATIONHOME path variable to \perlite\cit\2\cit\data

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