source: anuga_work/production/MOST_example/MOST_example/run_pt_hedland.py @ 3601

Last change on this file since 3601 was 3601, checked in by duncan, 18 years ago
File size: 8.2 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 anuga.pyvolution.shallow_water import Domain, Reflective_boundary, \
22                            Dirichlet_boundary, Time_boundary, File_boundary
23from anuga.pyvolution.data_manager import convert_dem_from_ascii2netcdf, \
24     dem2pts
25from anuga.pyvolution.combine_pts import combine_rectangular_points_files
26from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance
27from shutil import copy
28from os import mkdir, access, F_OK
29from anuga.geospatial_data.geospatial_data import *
30import sys
31from anuga.pyvolution.util import Screen_Catcher
32
33from anuga.fit_interpolate.fit import fit_to_mesh_file
34
35# Application specific imports
36import project                 # Definition of file names and polygons
37
38#-------------------------------------------------------------------------------
39# Copy scripts to time stamped output directory and capture screen
40# output to file
41#-------------------------------------------------------------------------------
42
43# creates copy of code in output dir if dir doesn't exist
44if access(project.outputtimedir,F_OK) == 0 :
45    mkdir (project.outputtimedir)
46copy (dirname(project.__file__) +sep+ project.__name__+'.py', project.outputtimedir + project.__name__+'.py')
47copy (__file__, project.outputtimedir + basename(__file__))
48print 'project.outputtimedir',project.outputtimedir
49
50# normal screen output is stored in
51#screen_output_name = project.outputtimedir + "screen_output.txt"
52#screen_error_name = project.outputtimedir + "screen_error.txt"
53
54# used to catch screen output to file
55#sys.stdout = Screen_Catcher(screen_output_name)
56#sys.stderr = Screen_Catcher(screen_error_name)
57print 'USER:    ', project.user
58
59#-------------------------------------------------------------------------------
60# Preparation of topographic data
61#
62# Convert ASC 2 DEM 2 PTS using source data and store result in source data
63# Do for coarse and fine data
64# Fine pts file to be clipped to area of interest
65#-------------------------------------------------------------------------------
66
67# filenames
68meshname = project.meshname + '.tsh'
69mesh_elevname = project.mesh_elevname  + '.tsh'
70source_dir = project.boundarydir
71
72
73#-------------------------------------------------------------------------------                                 
74# Create the triangular mesh based on overall clipping polygon with a tagged
75# boundary and interior regions defined in project.py along with
76# resolutions (maximal area of per triangle) for each polygon
77#-------------------------------------------------------------------------------
78
79from anuga.pmesh.mesh_interface import create_mesh_from_regions
80
81region_res = 5000000
82coast_res = 500000
83pt_hedland_res = 500000
84interior_regions = [[project.poly_pt_hedland, pt_hedland_res],
85                    [project.poly_region, region_res]]
86
87print 'number of interior regions', len(interior_regions)
88
89print 'start create mesh from regions'
90from caching import cache
91_ = cache(create_mesh_from_regions,
92          project.polyAll,
93          {'boundary_tags': {'topright': [0], 'topleft': [1],
94                             'left': [2], 'bottom0': [3],
95                             'bottom1': [4], 'bottom2': [5],
96                             'bottom3': [6], 'right': [7]},
97           'maximum_triangle_area': 5000000,
98           'filename': meshname,           
99           'interior_regions': interior_regions},
100          verbose = True, evaluate=True)
101
102cache(fit_to_mesh_file,(meshname,
103                 'pt_hedland_combined_elevation_31204' + '.pts',
104                 mesh_elevname),
105      {'verbose': True}
106      #,evaluate = True     
107      ,verbose = False
108      )
109#-------------------------------------------------------------------------------                                 
110# Setup computational domain
111#-------------------------------------------------------------------------------                                 
112domain = Domain(mesh_elevname, use_cache = False, verbose = True)
113
114print domain.statistics()
115print 'Number of triangles = ', len(domain)
116print 'The extent is ', domain.get_extent()
117print domain.statistics()
118
119domain.set_name(project.basename)
120domain.set_datadir(project.outputtimedir)
121domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
122
123#-------------------------------------------------------------------------------                                 
124# Setup initial conditions
125#-------------------------------------------------------------------------------
126
127tide = 0.
128#high
129#tide = 3.6
130#low
131#tide = -3.9
132
133domain.set_quantity('stage', tide)
134domain.set_quantity('friction', 0.0) 
135print 'hi and file',project.combined_dem_name + '.pts'
136
137#domain.set_quantity('elevation',
138#                    filename = project.combined_dem_name + '.pts',
139#                    use_cache = True,
140#                    verbose = True,
141#                    alpha = 0.1
142 #                   )
143
144#-------------------------------------------------------------------------------                                 
145# Setup boundary conditions (all reflective)
146#-------------------------------------------------------------------------------
147print 'start ferret2sww'
148# skipped as results in file SU-AU_clipped is correct for all WA
149
150from anuga.pyvolution.data_manager import ferret2sww
151
152south = project.south
153north = project.north
154west = project.west
155east = project.east
156
157#note only need to do when an SWW file for the MOST boundary doesn't exist
158cache(ferret2sww,
159      (project.boundary_basename,
160       project.boundary_basename+'_'+project.basename), 
161      {'verbose': True,
162       'minlat': south,
163       'maxlat': north,
164       'minlon': west,
165       'maxlon': east,
166#       'origin': project.mesh_origin,
167       'origin': domain.geo_reference.get_origin(),
168       'mean_stage': tide,
169       'zscale': 10,                 #Enhance tsunami
170       'fail_on_NaN': False,
171       'inverted_bathymetry': True},
172       evaluate = True,
173       verbose = True,
174      dependencies = source_dir + project.boundary_basename + '.sww')
175
176print 'Available boundary tags', domain.get_boundary_tags()
177
178Bf = File_boundary(project.boundary_basename+'_'+project.basename + '.sww', 
179                    domain, verbose = True)
180Br = Reflective_boundary(domain)
181Bd = Dirichlet_boundary([tide,0,0])
182domain.set_boundary( {'topright': Bf,'topleft': Bf, 'left':  Bd, 'bottom0': Bd,
183                      'bottom1': Bd, 'bottom2': Bd, 'bottom3': Bd, 
184                        'right': Bd})
185
186#-------------------------------------------------------------------------------                                 
187# Evolve system through time
188#-------------------------------------------------------------------------------
189import time
190t0 = time.time()
191
192for t in domain.evolve(yieldstep = 240, finaltime = 10800): 
193    domain.write_time()
194    domain.write_boundary_statistics(tags = 'topright')     
195
196for t in domain.evolve(yieldstep = 120, finaltime = 16200
197                       ,skip_initial_step = True): 
198    domain.write_time()
199    domain.write_boundary_statistics(tags = 'topright')     
200
201for t in domain.evolve(yieldstep = 60, finaltime = 21600
202                       ,skip_initial_step = True): 
203    domain.write_time()
204    domain.write_boundary_statistics(tags = 'topright')     
205   
206for t in domain.evolve(yieldstep = 120, finaltime = 27000
207                       ,skip_initial_step = True): 
208    domain.write_time()
209    domain.write_boundary_statistics(tags = 'topright')     
210
211for t in domain.evolve(yieldstep = 240, finaltime = 36000
212                       ,skip_initial_step = True): 
213    domain.write_time()
214    domain.write_boundary_statistics(tags = 'topright')   
215 
216print 'That took %.2f seconds' %(time.time()-t0)
217
218print 'finished'
Note: See TracBrowser for help on using the repository browser.