source: production/onslow_2006/run_onslow.py @ 2974

Last change on this file since 2974 was 2956, checked in by nick, 18 years ago

update to Onslow

File size: 10.0 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
27#from 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
49#coarsedemname = project.coarsedemname
50
51onshore_dem_name = project.onshore_dem_name
52
53offshore_points = project.offshore_dem_name
54
55meshname = project.meshname+'.msh'
56
57source_dir = project.boundarydir
58
59# creates copy of code in output dir if dir doesn't exist
60if access(project.outputtimedir,F_OK) == 0 :
61    mkdir (project.outputtimedir)
62copy (project.codedirname, project.outputtimedir + project.codename)
63copy (project.codedir + 'run_onslow.py', project.outputtimedir + 'run_onslow.py')
64print'output dir', project.outputtimedir
65
66#normal screen output is stored in
67screen_output_name = project.outputtimedir + "screen_output.txt"
68screen_error_name = project.outputtimedir + "screen_error.txt"
69
70#used to catch screen output to file
71sys.stdout = Screen_Catcher(screen_output_name)
72#sys.stderr = Screen_Catcher(screen_output_name)
73sys.stderr = Screen_Catcher(screen_error_name)
74
75'''
76copied_files = False
77
78# files to be used
79files_used = [onshore_dem_name, offshore_points,]
80
81if sys.platform != 'win32':   
82    copied_files = True
83    for name in file_list:
84        copy(name, )
85'''   
86#print' most file', project.MOST_dir + project.boundary_basename+'_ha.nc'
87#if access(project.MOST_dir + project.boundary_basename+'_ha.nc',F_OK) == 1 :
88#    print' most file', project.MOST_dir + project.boundary_basename
89
90"""
91# fine data (clipping the points file to smaller area)
92# creates DEM from asc data
93convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True)
94
95#creates pts file from DEM
96dem2pts(onshore_dem_name,
97        easting_min=project.eastingmin,
98        easting_max=project.eastingmax,
99        northing_min=project.northingmin,
100        northing_max= project.northingmax,
101        use_cache=True,
102        verbose=True)
103
104print'create G1'
105G1 = Geospatial_data(file_name = project.offshore_dem_name + '.xya')
106
107print'create G2'
108G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts')
109
110print'add G1+G2'
111G = G1 + G2
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
125#new
126region_res = 50000
127coast_res = 2500
128onslow_res = 500
129interior_regions = [[project.poly_onslow, onslow_res],
130                    [project.poly_coast, coast_res]]
131#,
132#                    [project.poly_region, region_res]]
133
134print 'number of interior regions', len(interior_regions)
135
136from caching import cache
137_ = cache(create_mesh_from_regions,
138          project.polyAll,
139          {'boundary_tags': {'top': [0], 'topleft': [1],
140                             'topleft1': [2], 'bottomleft': [3],
141                             'bottom': [4], 'bottomright': [5],
142                             'topright':[6]},
143           'maximum_triangle_area': 1000000,
144           'filename': meshname,           
145           'interior_regions': interior_regions},
146          verbose = True)
147
148
149#-------------------------------------------------------------------------------                                 
150# Setup computational domain
151#-------------------------------------------------------------------------------                                 
152
153domain = pmesh_to_domain_instance(meshname, Domain,
154                                  use_cache = False,
155                                  verbose = True)
156
157print 'Number of triangles = ', len(domain)
158print 'The extent is ', domain.get_extent()
159print domain.statistics()
160
161domain.set_name(project.basename)
162domain.set_datadir(project.outputtimedir)
163domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
164
165#-------------------------------------------------------------------------------
166# Set up scenario (tsunami_source is a callable object used with set_quantity)
167#-------------------------------------------------------------------------------
168'''
169tsunami_source = slump_tsunami(length=30000.0,
170                               depth=400.0,
171                               slope=6.0,
172                               thickness=176.0,
173                               radius=3330,
174                               dphi=0.23,
175                               x0=project.slump_origin[0],
176                               y0=project.slump_origin[1],
177                               alpha=0.0,
178                               domain=domain)
179
180'''
181#-------------------------------------------------------------------------------                                 
182# Setup initial conditions
183#-------------------------------------------------------------------------------
184
185tide = 0.0
186
187domain.set_quantity('stage', tide)
188domain.set_quantity('friction', 0.0) 
189print 'hi and file',project.combined_dem_name + '.pts'
190
191domain.set_quantity('elevation', 
192#                    0.
193#                    filename = project.onshore_dem_name + '.pts',
194                    filename = project.combined_dem_name + '.pts',
195#                    filename = project.offshore_dem_name + '.pts',
196                    use_cache = True,
197                    verbose = True,
198                    alpha = 0.1
199                    )
200
201print 'hi1'
202
203#-------------------------------------------------------------------------------                                 
204# Setup boundary conditions (all reflective)
205#-------------------------------------------------------------------------------
206print 'start ferret2sww'
207from pyvolution.data_manager import ferret2sww
208
209south = project.south
210north = project.north
211west = project.west
212east = project.east
213
214#note only need to do when an SWW file for the MOST boundary doesn't exist
215cache(ferret2sww,
216      (source_dir + project.boundary_basename,
217       source_dir + project.boundary_basename), 
218#      (project.MOST_dir + project.boundary_basename,
219#       source_dir + project.boundary_basename),
220      {'verbose': True,
221# note didn't work with the below
222#       'minlat': south - 1,
223#       'maxlat': north + 1,
224#       'minlon': west - 1,
225#       'maxlon': east + 1,
226       'minlat': south,
227       'maxlat': north,
228       'minlon': west,
229       'maxlon': east,
230#       'origin': project.mesh_origin,
231       'origin': domain.geo_reference.get_origin(),
232       'mean_stage': tide,
233       'zscale': 1,                 #Enhance tsunami
234       'fail_on_NaN': False,
235       'inverted_bathymetry': True},
236      #evaluate = True,
237       verbose = True)
238
239
240print 'Available boundary tags', domain.get_boundary_tags()
241
242Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
243                    domain, verbose = True)
244Br = Reflective_boundary(domain)
245Bd = Dirichlet_boundary([tide,0,0])
246
247
248# 7 min square wave starting at 1 min, 6m high
249Bw = Time_boundary(domain = domain,
250                   f=lambda t: [(60<t<480)*6, 0, 0])
251
252domain.set_boundary( {'top': Bf, 'topleft': Bf,
253                             'topleft1': Bf, 'bottomleft': Bd,
254                             'bottom': Br, 'bottomright': Br, 'topright': Bd} )
255
256#-------------------------------------------------------------------------------                                 
257# Evolve system through time
258#-------------------------------------------------------------------------------
259import time
260t0 = time.time()
261
262for t in domain.evolve(yieldstep = 240, finaltime = 7200): 
263    domain.write_time()
264    domain.write_boundary_statistics(tags = 'top')     
265
266for t in domain.evolve(yieldstep = 120, finaltime = 12600
267                       ,skip_initial_step = True): 
268    domain.write_time()
269    domain.write_boundary_statistics(tags = 'top')     
270
271for t in domain.evolve(yieldstep = 60, finaltime = 19800
272                       ,skip_initial_step = True): 
273    domain.write_time()
274    domain.write_boundary_statistics(tags = 'top')     
275   
276for t in domain.evolve(yieldstep = 120, finaltime = 25200
277                       ,skip_initial_step = True): 
278    domain.write_time()
279    domain.write_boundary_statistics(tags = 'top')     
280
281for t in domain.evolve(yieldstep = 240, finaltime = 36000
282                       ,skip_initial_step = True): 
283    domain.write_time()
284    domain.write_boundary_statistics(tags = 'top')     
285 
286print 'That took %.2f seconds' %(time.time()-t0)
287
288print 'finished'
Note: See TracBrowser for help on using the repository browser.