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

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

updates for Hobart and want to export elevation grid for Onslow

File size: 12.3 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#-------------------------------------------------------------------------------# Import necessary modules
13#-------------------------------------------------------------------------------
14
15# Standard modules
16import os
17import time
18from shutil import copy
19from os import mkdir, access, F_OK
20import sys
21
22# Related major packages
23from anuga.shallow_water import Domain, Reflective_boundary, \
24                            Dirichlet_boundary, Time_boundary, File_boundary
25from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
26from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
27from anuga.geospatial_data.geospatial_data import *
28from anuga.abstract_2d_finite_volumes.util import Screen_Catcher
29
30# Application specific imports
31import project                 # Definition of file names and polygons
32
33#-------------------------------------------------------------------------------
34# Copy scripts to time stamped output directory and capture screen
35# output to file
36#-------------------------------------------------------------------------------
37
38# creates copy of code in output dir if dir doesn't exist
39if access(project.outputtimedir,F_OK) == 0 :
40    mkdir (project.outputtimedir)
41copy (project.codedirname, project.outputtimedir + project.codename)
42copy (project.codedir + 'run_hobart.py', project.outputtimedir + 'run_hobart.py')
43print'output dir', project.outputtimedir
44
45#normal screen output is stored in
46screen_output_name = project.outputtimedir + "screen_output.txt"
47screen_error_name = project.outputtimedir + "screen_error.txt"
48
49#used to catch screen output to file
50sys.stdout = Screen_Catcher(screen_output_name)
51#sys.stderr = 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_dem_name = project.onshore_dem_name
64onshore_dem_name_25 = project.onshore_dem_name_25
65meshname = project.meshname+'.msh'
66source_dir = project.boundarydir
67
68copied_files = False
69
70# creates DEM from asc data
71convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True)
72
73#creates pts file for onshore DEM - 12.5
74dem2pts(onshore_dem_name,
75        easting_min=project.eastingmin,
76        easting_max=project.eastingmax,
77        northing_min=project.northingmin,
78        northing_max= project.northingmax,
79        use_cache=True, verbose=True)
80
81#creates pts file for onshore DEM - 25
82dem2pts(onshore_dem_name_25, use_cache=True, verbose=True)
83
84combine_rectangular_points_files(project.onshore_dem_name + '.pts',
85                                 project.onshore_dem_name_25 + '.pts',
86                                 project.all_onshore_dem_name + '.pts')
87#print 'local offshore data sets'
88#G1 = Geospatial_data(file_name = project.offshore_dem_name_local1 + '.xya')
89#G2 = Geospatial_data(file_name = project.offshore_dem_name_local2 + '.xya')
90#G3 = Geospatial_data(file_name = project.offshore_dem_name_local3 + '.xya')
91#G4 = Geospatial_data(file_name = project.offshore_dem_name_local4 + '.xya')
92#G11 = G1 + G2 + G3 + G4
93#print 'aho offshore data sets'
94#G5 = Geospatial_data(file_name = project.offshore_dem_name_aho1 + '.xya')
95#G6 = Geospatial_data(file_name = project.offshore_dem_name_aho2 + '.xya')
96#G7 = Geospatial_data(file_name = project.offshore_dem_name_aho3 + '.xya')
97#G8 = Geospatial_data(file_name = project.offshore_dem_name_aho4 + '.xya')
98#G9 = Geospatial_data(file_name = project.offshore_dem_name_aho5 + '.xya')
99#G10 = Geospatial_data(file_name = project.offshore_dem_name_aho6 + '.xya')
100#G11 = Geospatial_data(file_name = project.offshore_dem_name_aho7 + '.xya')
101#G12 = Geospatial_data(file_name = project.offshore_dem_name_aho8 + '.xya')
102#G13 = Geospatial_data(file_name = project.offshore_dem_name_aho9 + '.xya')
103#G14 = Geospatial_data(file_name = project.offshore_dem_name_aho10 + '.xya')
104#G15 = Geospatial_data(file_name = project.offshore_dem_name_aho11 + '.xya')
105#G16 = Geospatial_data(file_name = project.offshore_dem_name_aho12 + '.xya')
106#G17 = Geospatial_data(file_name = project.offshore_dem_name_aho13 + '.xya')
107#G18 = Geospatial_data(file_name = project.offshore_dem_name_aho14 + '.xya')
108#G19 = Geospatial_data(file_name = project.offshore_dem_name_aho15 + '.xya')
109#G20 = Geospatial_data(file_name = project.offshore_dem_name_aho16 + '.xya')
110#G12 = G5+G6+G7+G8+G9+G10+G11+G12+G13+G14+G15+G16+G17+G18+G19+G20
111#print 'local onshore dem'
112#G21 = Geospatial_data(file_name = project.onshore_dem_name + '.pts')
113print 'coast'
114#G22 = Geospatial_data(file_name = project.coast_dem_name + '.xya')
115#print 'adding data sets'
116#G = G11 + G12 + G21 + G22
117#G = G1+G2+G3+G4+G5+G6+G7+G8+G9+G10+G11+G12+G13+G14+G15+G16+G17+G18+G19+G20+G21+G22
118#G = G5+G6+G7+G8+G9+G10+G11+G12+G13+G14+G15+G16+G17+G18+G19+G20+G21+G22
119#G = G21+G22+G5+G6+G7+G8+G9+G10+G11+G12+G13+G14+G15+G16+G17+G18+G19+G20
120#G = G21+G22+G5
121#G = Geospatial_data(file_name = project.onshore_dem_name + '.pts') #+ \
122#    Geospatial_data(file_name = project.coast_dem_name + '.xya') #+ \
123#    Geospatial_data(file_name = project.offshore_dem_name_aho1 + '.xya')
124G = Geospatial_data(file_name = project.offshore_dem_name_local1 + '.xya')+\
125    Geospatial_data(file_name = project.offshore_dem_name_local2 + '.xya')+\
126    Geospatial_data(file_name = project.offshore_dem_name_local3 + '.xya')+\
127    Geospatial_data(file_name = project.offshore_dem_name_local4 + '.xya')+\
128    Geospatial_data(file_name = project.offshore_dem_name_aho1 + '.xya')+\
129    Geospatial_data(file_name = project.offshore_dem_name_aho2 + '.xya')+\
130    Geospatial_data(file_name = project.offshore_dem_name_aho3 + '.xya')+\
131    Geospatial_data(file_name = project.offshore_dem_name_aho4 + '.xya')+\
132    Geospatial_data(file_name = project.offshore_dem_name_aho5 + '.xya')+\
133    Geospatial_data(file_name = project.offshore_dem_name_aho6 + '.xya')+\
134    Geospatial_data(file_name = project.offshore_dem_name_aho7 + '.xya')+\
135    Geospatial_data(file_name = project.offshore_dem_name_aho8 + '.xya')+\
136    Geospatial_data(file_name = project.offshore_dem_name_aho9 + '.xya')+\
137    Geospatial_data(file_name = project.offshore_dem_name_aho10 + '.xya')+\
138    Geospatial_data(file_name = project.offshore_dem_name_aho11 + '.xya')+\
139    Geospatial_data(file_name = project.offshore_dem_name_aho12 + '.xya')+\
140    Geospatial_data(file_name = project.offshore_dem_name_aho13 + '.xya')+\
141    Geospatial_data(file_name = project.offshore_dem_name_aho14 + '.xya')+\
142    Geospatial_data(file_name = project.offshore_dem_name_aho15 + '.xya')+\
143    Geospatial_data(file_name = project.offshore_dem_name_aho16 + '.xya')+\
144    Geospatial_data(file_name = project.all_onshore_dem_name + '.pts')
145G.export_points_file(project.combined_dem_name + '.pts')
146
147#-------------------------------------------------------------------------------                                 
148# Create the triangular mesh based on overall clipping polygon with a tagged
149# boundary and interior regions defined in project.py along with
150# resolutions (maximal area of per triangle) for each polygon
151#-------------------------------------------------------------------------------
152
153from anuga.pmesh.mesh_interface import create_mesh_from_regions
154
155# use 75 for onshore components (12.5m DEM)
156island_res = 35000
157hobart_res = 35000
158peninsula_res = 35000
159interior_regions = [[project.poly_hobart, hobart_res],
160                    [project.poly_tasman_peninsula, peninsula_res],
161                    [project.poly_bruny, island_res]]
162
163print 'number of interior regions', len(interior_regions)
164
165from caching import cache
166_ = cache(create_mesh_from_regions,
167          project.polyAll,
168          {'boundary_tags': {'bottom': [0], 'right': [1],
169                             'top': [2], 'left': [3]},
170           'maximum_triangle_area': 250000,
171           'filename': meshname,           
172           'interior_regions': interior_regions},
173          verbose = True, evaluate=True)
174
175
176#-------------------------------------------------------------------------------                                 
177# Setup computational domain
178#-------------------------------------------------------------------------------                                 
179domain = Domain(meshname, use_cache = False, verbose = True)
180
181print 'Number of triangles = ', len(domain)
182print 'The extent is ', domain.get_extent()
183print domain.statistics()
184
185domain.set_name(project.basename)
186domain.set_datadir(project.outputtimedir)
187domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
188domain.set_minimum_storable_height(0.01)
189domain.set_store_vertices_uniquely(True)  # for writting to sww
190
191#-------------------------------------------------------------------------------                                 
192# Setup initial conditions
193#-------------------------------------------------------------------------------
194
195tide = 0.0
196
197domain.set_quantity('stage', tide)
198domain.set_quantity('friction', 0.0) 
199
200domain.set_quantity('elevation', 
201#                    filename = project.onshore_dem_name + '.pts',
202                    filename = project.combined_dem_name + '.pts',
203#                    filename = project.offshore_dem_name + '.pts',
204                    use_cache = True,
205                    verbose = True,
206                    alpha = 0.1
207                    )
208
209#-------------------------------------------------------------------------------                                 
210# Setup boundary conditions (all reflective)
211#-------------------------------------------------------------------------------
212print 'start ferret2sww'
213from anuga.shallow_water.data_manager import ferret2sww
214'''
215south = project.south
216north = project.north
217west = project.west
218east = project.east
219
220#note only need to do when an SWW file for the MOST boundary doesn't exist
221cache(ferret2sww,
222      (source_dir + project.boundary_basename,
223       source_dir + project.boundary_basename),
224#      (project.MOST_dir + project.boundary_basename,
225#       source_dir + project.boundary_basename),
226      {'verbose': True,
227# note didn't work with the below
228#       'minlat': south - 1,
229#       'maxlat': north + 1,
230#       'minlon': west - 1,
231#       'maxlon': east + 1,
232       'minlat': south,
233       'maxlat': north,
234       'minlon': west,
235       'maxlon': east,
236#       'origin': project.mesh_origin,
237       'origin': domain.geo_reference.get_origin(),
238       'mean_stage': tide,
239       'zscale': 1,                 #Enhance tsunami
240       'fail_on_NaN': False,
241       'inverted_bathymetry': True},
242      #evaluate = True,
243       verbose = True,
244       dependencies = source_dir + project.boundary_basename + '.sww')
245
246'''
247print 'Available boundary tags', domain.get_boundary_tags()
248
249#Bf = File_boundary(source_dir + project.boundary_basename + '.sww',
250#                    domain, verbose = True)
251Br = Reflective_boundary(domain)
252Bd = Dirichlet_boundary([tide,0,0])
253
254
255# 7 min square wave starting at 1 min, 6m high
256Bw = Time_boundary(domain = domain,
257                   f=lambda t: [(60<t<480)*6, 0, 0])
258
259# for MOST BC
260#domain.set_boundary( {'top': Bd, 'left': Bd,
261#                      'bottom': Bf, 'right': Bf} )
262
263# for testing
264domain.set_boundary( {'top': Bd, 'left': Bd,
265                      'bottom': Bd, 'right': Bw} )
266
267#-------------------------------------------------------------------------------                                 
268# Evolve system through time
269#-------------------------------------------------------------------------------
270import time
271t0 = time.time()
272
273for t in domain.evolve(yieldstep = 240, finaltime = 7200): 
274    domain.write_time()
275    domain.write_boundary_statistics(tags = 'bottom')     
276
277for t in domain.evolve(yieldstep = 120, finaltime = 12600
278                       ,skip_initial_step = True): 
279    domain.write_time()
280    domain.write_boundary_statistics(tags = 'bottom')     
281   
282print 'That took %.2f seconds' %(time.time()-t0)
283
284print 'finished'
Note: See TracBrowser for help on using the repository browser.