source: production/pt_hedland_2006/run_pt_hedland.py @ 3287

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

more changes ...

File size: 9.0 KB
RevLine 
[3271]1"""Script for running a tsunami inundation scenario for Onslow, WA, Australia.
[2848]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
[3271]7The scenario is defined by a triangular mesh created from project.polygon,
8the elevation data and a simulated submarine landslide.
[2848]9
[3271]10Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006
[2848]11"""
[3271]12#-------------------------------------------------------------------------------# Import necessary modules
13#-------------------------------------------------------------------------------
[2848]14
15# Standard modules
[2902]16from os import sep
17from os.path import dirname, basename
[2848]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
[3271]32# Application specific imports
33import project                 # Definition of file names and polygons
34
[3272]35#-------------------------------------------------------------------------------
36# Copy scripts to time stamped output directory and capture screen
37# output to file
38#-------------------------------------------------------------------------------
[3271]39
[3272]40# creates copy of code in output dir if dir doesn't exist
41if access(project.outputtimedir,F_OK) == 0 :
42    mkdir (project.outputtimedir)
43copy (dirname(project.__file__) +sep+ project.__name__+'.py', project.outputtimedir + project.__name__+'.py')
44copy (__file__, project.outputtimedir + basename(__file__))
45print 'project.outputtimedir',project.outputtimedir
46
47# normal screen output is stored in
48screen_output_name = project.outputtimedir + "screen_output.txt"
49screen_error_name = project.outputtimedir + "screen_error.txt"
50
51# used to catch screen output to file
52sys.stdout = Screen_Catcher(screen_output_name)
53sys.stderr = Screen_Catcher(screen_error_name)
54print 'USER:    ', project.user
55
[3271]56#-------------------------------------------------------------------------------
[2848]57# Preparation of topographic data
58#
59# Convert ASC 2 DEM 2 PTS using source data and store result in source data
60# Do for coarse and fine data
61# Fine pts file to be clipped to area of interest
[3271]62#-------------------------------------------------------------------------------
[2848]63
64# filenames
65meshname = project.meshname+'.msh'
66source_dir = project.boundarydir
67
68# fine data (clipping the points file to smaller area)
69# creates DEM from asc data
[3281]70convert_dem_from_ascii2netcdf(project.onshore_dem_name, use_cache=True, verbose=True)
[2848]71
72#creates pts file from DEM
[3281]73dem2pts(project.onshore_dem_name,
[2848]74        easting_min=project.eastingmin,
75        easting_max=project.eastingmax,
76        northing_min=project.northingmin,
77        northing_max= project.northingmax,
[3271]78        use_cache=True,
[2848]79        verbose=True)
80
[3271]81print 'create G1'
[2848]82G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya')
[3271]83print 'create G2'
[2848]84G2 = Geospatial_data(file_name = project.offshore_dem_name2 + '.xya')
[3271]85print 'create G3'
[2848]86G3 = Geospatial_data(file_name = project.onshore_dem_name + '.pts')
[3274]87print 'create G4'
88G4 = Geospatial_data(file_name = project.coast_dem_name + '.xya')
89print 'add G1+G2+G3+G4'
90G = G1 + G2 + G3 + G4
[3271]91print 'export G'
[2848]92G.export_points_file(project.combined_dem_name + '.pts')
93
[3271]94#-------------------------------------------------------------------------------                                 
[2848]95# Create the triangular mesh based on overall clipping polygon with a tagged
96# boundary and interior regions defined in project.py along with
97# resolutions (maximal area of per triangle) for each polygon
[3271]98#-------------------------------------------------------------------------------
[2848]99
100from pmesh.mesh_interface import create_mesh_from_regions
101
[3286]102region_res = 500000
[3284]103coast_res = 500
[3286]104pt_hedland_res = 5000
[2902]105interior_regions = [[project.poly_pt_hedland, pt_hedland_res],
[3271]106                    [project.poly_region, region_res]]
[2848]107
108print 'number of interior regions', len(interior_regions)
109
[3272]110from utilities.polygon import plot_polygons
[3271]111if sys.platform == 'win32':
112    #figname = project.outputtimedir + 'pt_hedland_polys'
[3287]113    figname = 'pt_hedland_polys_test'
[3271]114    plot_polygons([project.polyAll,project.poly_pt_hedland,project.poly_region],
[2955]115              figname,
[3271]116              verbose = True)   
[2904]117
[2954]118print 'start create mesh from regions'
[2848]119from caching import cache
120_ = cache(create_mesh_from_regions,
121          project.polyAll,
[3272]122          {'boundary_tags': {'topright': [0], 'topleft': [1],
[3286]123                             'left': [2], 'bottom0': [3],
124                             'bottom1': [4], 'bottom2': [5],
[3287]125                             'bottom3': [6], 'right': [7]},
[3284]126           'maximum_triangle_area': 250000,
[2848]127           'filename': meshname,           
128           'interior_regions': interior_regions},
[3271]129          verbose = True, evaluate=True)
[2848]130
[3271]131#-------------------------------------------------------------------------------                                 
[2848]132# Setup computational domain
[3271]133#-------------------------------------------------------------------------------                                 
[2902]134domain = Domain(meshname, use_cache = False, verbose = True)
135
[3271]136print domain.statistics()
[2848]137print 'Number of triangles = ', len(domain)
138print 'The extent is ', domain.get_extent()
139print domain.statistics()
140
141domain.set_name(project.basename)
142domain.set_datadir(project.outputtimedir)
143domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
144
[3271]145#-------------------------------------------------------------------------------                                 
[2848]146# Setup initial conditions
[3271]147#-------------------------------------------------------------------------------
[2848]148
149tide = 0.
[3271]150#high
151#tide = 3.6
152#low
153#tide = -3.9
[2848]154
155domain.set_quantity('stage', tide)
156domain.set_quantity('friction', 0.0) 
157print 'hi and file',project.combined_dem_name + '.pts'
158
159domain.set_quantity('elevation', 
160                    filename = project.combined_dem_name + '.pts',
161                    use_cache = True,
162                    verbose = True,
163                    alpha = 0.1
164                    )
165
[3271]166#-------------------------------------------------------------------------------                                 
[2848]167# Setup boundary conditions (all reflective)
[3271]168#-------------------------------------------------------------------------------
[2848]169print 'start ferret2sww'
[2902]170# skipped as results in file SU-AU_clipped is correct for all WA
171
[2848]172from pyvolution.data_manager import ferret2sww
173
174south = project.south
175north = project.north
176west = project.west
177east = project.east
178
179#note only need to do when an SWW file for the MOST boundary doesn't exist
180cache(ferret2sww,
181      (source_dir + project.boundary_basename,
[3272]182       source_dir + project.boundary_basename+'_'+project.basename), 
[2848]183      {'verbose': True,
184       'minlat': south,
185       'maxlat': north,
186       'minlon': west,
187       'maxlon': east,
188#       'origin': project.mesh_origin,
189       'origin': domain.geo_reference.get_origin(),
190       'mean_stage': tide,
191       'zscale': 1,                 #Enhance tsunami
192       'fail_on_NaN': False,
193       'inverted_bathymetry': True},
[3271]194       evaluate = True,
[3272]195       verbose = True,
196      dependencies = source_dir + project.boundary_basename + '.sww')
[2848]197
198print 'Available boundary tags', domain.get_boundary_tags()
199
200Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
201                    domain, verbose = True)
202Br = Reflective_boundary(domain)
203Bd = Dirichlet_boundary([tide,0,0])
[3286]204domain.set_boundary( {'topright': Bf,'topleft': Bf, 'left':  Bd, 'bottom0': Bd,
205                      'bottom1': Bd, 'bottom2': Bd, 'bottom3': Bd, 
206                        'right': Bd})
[3287]207
[3271]208#-------------------------------------------------------------------------------                                 
[2848]209# Evolve system through time
[3271]210#-------------------------------------------------------------------------------
[2848]211import time
212t0 = time.time()
213
[3284]214for t in domain.evolve(yieldstep = 240, finaltime = 10800): 
[2848]215    domain.write_time()
[3284]216    domain.write_boundary_statistics(tags = 'topright')     
[2848]217
[3284]218for t in domain.evolve(yieldstep = 120, finaltime = 16200
[2848]219                       ,skip_initial_step = True): 
220    domain.write_time()
[3284]221    domain.write_boundary_statistics(tags = 'topright')     
[2848]222
[3284]223for t in domain.evolve(yieldstep = 60, finaltime = 21600
[2848]224                       ,skip_initial_step = True): 
225    domain.write_time()
[3284]226    domain.write_boundary_statistics(tags = 'topright')     
[2848]227   
[3284]228for t in domain.evolve(yieldstep = 120, finaltime = 27000
[2848]229                       ,skip_initial_step = True): 
230    domain.write_time()
[3284]231    domain.write_boundary_statistics(tags = 'topright')     
[2848]232
[2902]233for t in domain.evolve(yieldstep = 240, finaltime = 36000
[2848]234                       ,skip_initial_step = True): 
235    domain.write_time()
[3284]236    domain.write_boundary_statistics(tags = 'topright')   
[2848]237 
238print 'That took %.2f seconds' %(time.time()-t0)
239
240print 'finished'
Note: See TracBrowser for help on using the repository browser.