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

Last change on this file since 3724 was 3721, checked in by sexton, 18 years ago

hobart testing and report making

File size: 9.9 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': 2500000,
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
178#domain.set_quantity('elevation',
179#                    filename = project.combined_dem_name_2 + '.pts',
180#                    filename = onshore_offshore_dem_name + '.pts',
181#                    use_cache = True,
182#                    verbose = True,
183#                    alpha = 0.1
184#                    )
185
186
187#-------------------------------------------------------------------------------                                 
188# Setup boundary conditions
189#-------------------------------------------------------------------------------
190print 'start ferret2sww'
191print '', project.boundary_basename
192from anuga.shallow_water.data_manager import ferret2sww
193
194south = project.south
195north = project.north
196west  = project.west
197east  = project.east
198
199#note only need to do when an SWW file for the MOST boundary doesn't exist
200cache(ferret2sww,
201      (source_dir + project.boundary_basename,
202       source_dir + project.boundary_basename), 
203      {'verbose': True,
204       'minlat': south,
205       'maxlat': north,
206       'minlon': west,
207       'maxlon': east,
208#       'origin': project.mesh_origin,
209       'origin': domain.geo_reference.get_origin(),
210       'mean_stage': tide,
211       'zscale': 1,                 #Enhance tsunami
212       'fail_on_NaN': False,
213       'inverted_bathymetry': True},
214      #evaluate = True,
215       verbose = True,
216       dependencies = source_dir + project.boundary_basename + '.sww')
217
218
219print 'Available boundary tags', domain.get_boundary_tags()
220
221Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
222                    domain, verbose = True)
223Br = Reflective_boundary(domain)
224Bd = Dirichlet_boundary([tide,0,0])
225
226
227# 7 min square wave starting at 1 min, 6m high
228Bw = Time_boundary(domain = domain,
229                   f=lambda t: [(60<t<480)*10, 0, 0])
230
231domain.set_boundary( {'e0': Bd,  'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd,
232                      'e5': Bd,  'e6': Bd, 'e7': Bd, 'e8': Bd, 'e9': Bd,
233                      'e10': Bd, 'e11': Bd, 'e12': Bf, 'e13': Bf, 'e14': Bf,
234                      'e15': Bf} )
235
236
237#-------------------------------------------------------------------------------                                 
238# Evolve system through time
239#-------------------------------------------------------------------------------
240import time
241t0 = time.time()
242
243for t in domain.evolve(yieldstep = 240, finaltime = 6800): 
244    domain.write_time()
245    domain.write_boundary_statistics(tags = 'e14')     
246
247for t in domain.evolve(yieldstep = 30, finaltime = 9000
248                       ,skip_initial_step = True): 
249    domain.write_time()
250    domain.write_boundary_statistics(tags = 'e14')     
251
252for t in domain.evolve(yieldstep = 240, finaltime = 15000
253                       ,skip_initial_step = True): 
254    domain.write_time()
255    domain.write_boundary_statistics(tags = 'e14') 
256   
257print 'That took %.2f seconds' %(time.time()-t0)
258
259print 'finished'
Note: See TracBrowser for help on using the repository browser.