source: anuga_work/production/hobart_2006/run_hobart.py @ 3701

Last change on this file since 3701 was 3701, checked in by sexton, 17 years ago

hobart script updates

File size: 9.8 KB
Line 
1"""Script for running a tsunami inundation scenario for Hobart, TAS, 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 tsunami wave generated by MOST.
9
10Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006
11"""
12#-------------------------------------------------------------------------------
13# Import necessary modules
14#-------------------------------------------------------------------------------
15
16# Standard modules
17import os
18import time
19from shutil import copy
20from os import mkdir, access, F_OK
21import sys
22
23# Related major packages
24from anuga.shallow_water import Domain, Reflective_boundary, \
25                            Dirichlet_boundary, Time_boundary, File_boundary
26from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
27from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
28from anuga.geospatial_data.geospatial_data import *
29from anuga.abstract_2d_finite_volumes.util import Screen_Catcher
30
31# Application specific imports
32import project                 # Definition of file names and polygons
33
34#-------------------------------------------------------------------------------
35# Copy scripts to time stamped output directory and capture screen
36# output to file
37#-------------------------------------------------------------------------------
38
39# creates copy of code in output dir if dir doesn't exist
40if access(project.outputtimedir,F_OK) == 0 :
41    mkdir (project.outputtimedir)
42copy (project.codedirname, project.outputtimedir + project.codename)
43copy (project.codedir + 'run_hobart.py', project.outputtimedir + 'run_hobart.py')
44print'output dir', project.outputtimedir
45
46#normal screen output is stored in
47screen_output_name = project.outputtimedir + "screen_output.txt"
48screen_error_name = project.outputtimedir + "screen_error.txt"
49
50#used to catch screen output to file
51sys.stdout = Screen_Catcher(screen_output_name)
52sys.stderr = Screen_Catcher(screen_error_name)
53
54print 'USER:    ', project.user
55
56#-------------------------------------------------------------------------------
57# Preparation of topographic data
58#
59# Convert ASC 2 DEM 2 PTS using source data and store result in source data
60#-------------------------------------------------------------------------------
61
62# filenames
63onshore_offshore_dem_name = project.onshore_offshore_dem_name
64onshore_offshore_dem_name_25 = project.onshore_offshore_dem_name_25
65meshname = project.meshname+'.msh'
66source_dir = project.boundarydir
67
68copied_files = False
69
70# create DEM from 50m asc data
71convert_dem_from_ascii2netcdf(onshore_offshore_dem_name, use_cache=True, verbose=True)
72
73# creates pts file for combined 50m DEM
74dem2pts(onshore_offshore_dem_name, use_cache=True, verbose=True)
75
76# 25m data (clipping the around the Hobart area)
77convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True)
78
79# creates pts file for 25m data around Hobart
80dem2pts(onshore_offshore_dem_name_25, project.hobart_dem_name_25,
81        easting_min=project.eastingmin25,
82        easting_max=project.eastingmax25,
83        northing_min=project.northingmin25,
84        northing_max= project.northingmax25,
85        use_cache=True, 
86        verbose=True)
87
88# combining the 50m and Hobart 25m data
89combine_rectangular_points_files(project.hobart_dem_name_25 + '.pts',
90                                 project.onshore_offshore_dem_name + '.pts',
91                                 project.combined_dem_name + '.pts')
92
93# 25m data (clipping the around site 24 on Bruny Island)
94#convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True)
95
96# creates pts file for 25m data around site 24 at Bruny Island
97dem2pts(onshore_offshore_dem_name_25, project.bruny_dem_name_25,
98        easting_min=project.eastingmin25_2,
99        easting_max=project.eastingmax25_2,
100        northing_min=project.northingmin25_2,
101        northing_max= project.northingmax25_2,
102        use_cache=True, 
103        verbose=True)
104
105# combining the 50m and Hobart 25m data with Bruny Island 25m data
106combine_rectangular_points_files(project.bruny_dem_name_25 + '.pts',
107                                 project.combined_dem_name + '.pts',
108                                 project.combined_dem_name_2 + '.pts')
109
110# If working with points, then add separate datasets together here
111# create geospatial data set and export
112#G = Geospatial_data(file_name = project.onshore_offshore_dem_name + '.pts')
113#G.export_points_file(project.combined_dem_name + '.pts')
114
115
116#----------------------------------------------------------------------------
117# Create the triangular mesh based on overall clipping polygon with a tagged
118# boundary and interior regions defined in project.py along with
119# resolutions (maximal area of per triangle) for each polygon
120#-------------------------------------------------------------------------------
121
122from anuga.pmesh.mesh_interface import create_mesh_from_regions
123
124# use 75 for onshore components (12.5m DEM)
125# Resolution refers to max triangle area in a region
126#island_res    = 35000
127hobart_res    =  7000
128#peninsula_res = 35000
129interior_regions = [[project.poly_hobart1, hobart_res],
130                    [project.poly_hobart2, hobart_res],
131                    [project.poly_hobart3, hobart_res]]
132
133print 'number of interior regions', len(interior_regions)
134
135
136# Number tags correspond to number segments from bounding polygon
137# maximum_triangle_area refers to max triangle area in a region
138# Interion_regions either comment out (perhaps empty list)
139from caching import cache
140_ = cache(create_mesh_from_regions,
141          project.polyAll,
142           {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2],
143                              'e3': [3], 'e4':[4], 'e5': [5],
144                              'e6': [6], 'e7': [7], 'e8': [8],
145                              'e9': [9], 'e10': [10], 'e11': [11],
146                              'e12': [12], 'e13': [13], 'e14': [14],
147                              'e15': [15]},
148           'maximum_triangle_area': 750000,
149           'filename': meshname,
150           'interior_regions': interior_regions},
151          verbose = True, evaluate=False)
152
153
154#-------------------------------------------------------------------------------                                 
155# Setup computational domain
156#-------------------------------------------------------------------------------                                 
157domain = Domain(meshname, use_cache = True, verbose = True)
158
159print 'Number of triangles = ', len(domain)
160print 'The extent is ', domain.get_extent()
161print domain.statistics()
162
163domain.set_name(project.basename)
164domain.set_datadir(project.outputtimedir)
165domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
166domain.set_minimum_storable_height(0.01)
167domain.set_store_vertices_uniquely(False)  # for writting to sww
168
169
170#-------------------------------------------------------------------------------                                 
171# Setup initial conditions
172#-------------------------------------------------------------------------------
173
174tide = 0.0
175domain.set_quantity('stage', tide)
176domain.set_quantity('friction', 0.0) 
177
178domain.set_quantity('elevation', 
179                    filename = project.combined_dem_name_2 + '.pts',
180                    use_cache = True,
181                    verbose = True,
182                    alpha = 0.1
183                    )
184
185
186#-------------------------------------------------------------------------------                                 
187# Setup boundary conditions
188#-------------------------------------------------------------------------------
189print 'start ferret2sww'
190from anuga.shallow_water.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
198##cache(ferret2sww,
199##      (source_dir + project.boundary_basename,
200##       source_dir + project.boundary_basename),
201##      {'verbose': True,
202##       'minlat': south,
203##       'maxlat': north,
204##       'minlon': west,
205##       'maxlon': east,
206###       'origin': project.mesh_origin,
207##       'origin': domain.geo_reference.get_origin(),
208##       'mean_stage': tide,
209##       'zscale': 1,                 #Enhance tsunami
210##       'fail_on_NaN': False,
211##       'inverted_bathymetry': True},
212##      #evaluate = True,
213##       verbose = True,
214##       dependencies = source_dir + project.boundary_basename + '.sww')
215
216
217print 'Available boundary tags', domain.get_boundary_tags()
218
219Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
220                    domain, verbose = True)
221Br = Reflective_boundary(domain)
222Bd = Dirichlet_boundary([tide,0,0])
223
224
225# 7 min square wave starting at 1 min, 6m high
226Bw = Time_boundary(domain = domain,
227                   f=lambda t: [(60<t<480)*10, 0, 0])
228
229domain.set_boundary( {'e0': Bd,  'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd,
230                      'e5': Bd,  'e6': Bd, 'e7': Bd, 'e8': Bd, 'e9': Bd,
231                      'e10': Bd, 'e11': Bd, 'e12': Bf, 'e13': Bf, 'e14': Bf,
232                      'e15': Bf} )
233
234
235#-------------------------------------------------------------------------------                                 
236# Evolve system through time
237#-------------------------------------------------------------------------------
238import time
239t0 = time.time()
240
241for t in domain.evolve(yieldstep = 240, finaltime = 6800): 
242    domain.write_time()
243    domain.write_boundary_statistics(tags = 'e14')     
244
245for t in domain.evolve(yieldstep = 30, finaltime = 9000
246                       ,skip_initial_step = True): 
247    domain.write_time()
248    domain.write_boundary_statistics(tags = 'e14')     
249
250for t in domain.evolve(yieldstep = 240, finaltime = 15000
251                       ,skip_initial_step = True): 
252    domain.write_time()
253    domain.write_boundary_statistics(tags = 'e14') 
254   
255print 'That took %.2f seconds' %(time.time()-t0)
256
257print 'finished'
Note: See TracBrowser for help on using the repository browser.