source: production/pt_hedland_2006/run_pt_hedland.py @ 2855

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

updates

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