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

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

updates (clipping 25m data into 50m grid, putting MOST boundary on relevant boundary segments, change saving unique vertices to False)

File size: 9.9 KB
RevLine 
[3559]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,
[3615]8the elevation data and a tsunami wave generated by MOST.
[3559]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
[3626]23from anuga.shallow_water import Domain, Reflective_boundary, \
[3559]24                            Dirichlet_boundary, Time_boundary, File_boundary
[3626]25from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
[3650]26from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
[3559]27from anuga.geospatial_data.geospatial_data import *
[3626]28from anuga.abstract_2d_finite_volumes.util import Screen_Catcher
[3559]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)
[3626]42copy (project.codedir + 'run_hobart.py', project.outputtimedir + 'run_hobart.py')
[3559]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
[3671]63onshore_offshore_dem_name = project.onshore_offshore_dem_name
[3683]64onshore_offshore_dem_name_25 = project.onshore_offshore_dem_name_25
[3559]65meshname = project.meshname+'.msh'
66source_dir = project.boundarydir
67
68copied_files = False
69
[3683]70# create DEM from 50m asc data
[3671]71convert_dem_from_ascii2netcdf(onshore_offshore_dem_name, use_cache=True, verbose=True)
[3660]72
[3683]73# creates pts file for combined 50m DEM
[3671]74dem2pts(onshore_offshore_dem_name, use_cache=True, verbose=True)
[3650]75
[3683]76# 25m data (clipping the around the Hobart area)
77convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True)
78# creates pts file for 25m data around Hobart
79dem2pts(onshore_offshore_dem_name_25, project.hobart_dem_name_25,
80        easting_min=project.eastingmin25,
81        easting_max=project.eastingmax25,
82        northing_min=project.northingmin25,
83        northing_max= project.northingmax25,
84        use_cache=True, 
85        verbose=True)
86
87# combining the 50m and Hobart 25m data
88combine_rectangular_points_files(project.hobart_dem_name_25 + '.pts',
89                                 project.onshore_offshore_dem_name + '.pts',
90                                 project.combined_dem_name + '.pts')
91
92# 25m data (clipping the around site 24 on Bruny Island)
93convert_dem_from_ascii2netcdf(onshore_offshore_dem_name_25, use_cache=True, verbose=True)
94# creates pts file for 25m data around site 24 at Bruny Island
95dem2pts(onshore_offshore_dem_name_25, project.bruny_dem_name_25,
96        easting_min=project.eastingmin25_2,
97        easting_max=project.eastingmax25_2,
98        northing_min=project.northingmin25_2,
99        northing_max= project.northingmax25_2,
100        use_cache=True, 
101        verbose=True)
102
103# combining the 50m and Hobart 25m data with Bruny Island 25m data
104combine_rectangular_points_files(project.bruny_dem_name_25 + '.pts',
105                                 project.combined_dem_name + '.pts',
106                                 project.combined_dem_name_2 + '.pts')
107
[3671]108# create geospatial data set and export
[3683]109#G = Geospatial_data(file_name = project.onshore_offshore_dem_name + '.pts')
110#G.export_points_file(project.combined_dem_name + '.pts')
[3661]111
112#----------------------------------------------------------------------------
[3559]113# Create the triangular mesh based on overall clipping polygon with a tagged
114# boundary and interior regions defined in project.py along with
115# resolutions (maximal area of per triangle) for each polygon
116#-------------------------------------------------------------------------------
117
118from anuga.pmesh.mesh_interface import create_mesh_from_regions
119
[3615]120# use 75 for onshore components (12.5m DEM)
[3626]121island_res = 35000
122hobart_res = 35000
123peninsula_res = 35000
[3679]124interior_regions = [[project.poly_hobart1, hobart_res],
125                    [project.poly_hobart2, hobart_res],
126                    [project.poly_hobart3, hobart_res]]
[3559]127
128print 'number of interior regions', len(interior_regions)
129
130from caching import cache
131_ = cache(create_mesh_from_regions,
132          project.polyAll,
[3673]133           {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2],
[3679]134                              'e3': [3], 'e4':[4], 'e5': [5],
135                              'e6': [6], 'e7': [7], 'e8': [8],
136                              'e9': [9], 'e10': [10], 'e11': [11],
137                              'e12': [12], 'e13': [13], 'e14': [14],
138                              'e15': [15]},
[3683]139           'maximum_triangle_area': 2000000,
140           'filename': meshname,
[3679]141           'interior_regions': interior_regions},
142          verbose = True, evaluate=False)
[3559]143
144
145#-------------------------------------------------------------------------------                                 
146# Setup computational domain
147#-------------------------------------------------------------------------------                                 
[3679]148domain = Domain(meshname, use_cache = True, verbose = True)
[3559]149
150print 'Number of triangles = ', len(domain)
151print 'The extent is ', domain.get_extent()
152print domain.statistics()
153
154domain.set_name(project.basename)
155domain.set_datadir(project.outputtimedir)
156domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
[3642]157domain.set_minimum_storable_height(0.01)
[3683]158domain.set_store_vertices_uniquely(False)  # for writting to sww
[3559]159
160#-------------------------------------------------------------------------------                                 
161# Setup initial conditions
162#-------------------------------------------------------------------------------
163
164tide = 0.0
165
166domain.set_quantity('stage', tide)
167domain.set_quantity('friction', 0.0) 
168
169domain.set_quantity('elevation', 
170#                    filename = project.onshore_dem_name + '.pts',
[3683]171                    filename = project.combined_dem_name_2 + '.pts',
[3559]172#                    filename = project.offshore_dem_name + '.pts',
173                    use_cache = True,
174                    verbose = True,
175                    alpha = 0.1
176                    )
177
178#-------------------------------------------------------------------------------                                 
[3661]179# Setup boundary conditions
[3559]180#-------------------------------------------------------------------------------
181print 'start ferret2sww'
[3626]182from anuga.shallow_water.data_manager import ferret2sww
[3679]183
[3559]184south = project.south
185north = project.north
186west = project.west
187east = project.east
188
189#note only need to do when an SWW file for the MOST boundary doesn't exist
190cache(ferret2sww,
191      (source_dir + project.boundary_basename,
192       source_dir + project.boundary_basename), 
193      {'verbose': True,
194       'minlat': south,
195       'maxlat': north,
196       'minlon': west,
197       'maxlon': east,
198#       'origin': project.mesh_origin,
199       'origin': domain.geo_reference.get_origin(),
200       'mean_stage': tide,
201       'zscale': 1,                 #Enhance tsunami
202       'fail_on_NaN': False,
203       'inverted_bathymetry': True},
204      #evaluate = True,
205       verbose = True,
206       dependencies = source_dir + project.boundary_basename + '.sww')
207
[3679]208
[3559]209print 'Available boundary tags', domain.get_boundary_tags()
210
[3679]211Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
212                    domain, verbose = True)
[3559]213Br = Reflective_boundary(domain)
214Bd = Dirichlet_boundary([tide,0,0])
215
216
217# 7 min square wave starting at 1 min, 6m high
218Bw = Time_boundary(domain = domain,
[3671]219                   f=lambda t: [(60<t<480)*10, 0, 0])
[3559]220
[3615]221# for MOST BC
222#domain.set_boundary( {'top': Bd, 'left': Bd,
223#                      'bottom': Bf, 'right': Bf} )
[3559]224
[3615]225# for testing
[3673]226#domain.set_boundary( {'topr': Bd, 'left': Bd, 'top': Bd,
227#                      'bottom': Bw, 'bright': Bd} )
228domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd,
229                        'e5': Bd, 'e6': Bd, 'e7': Bd, 'e8': Bd, 'e9': Bd,
[3683]230                        'e10': Bd, 'e11': Bd, 'e12': Bf, 'e13': Bf, 'e14': Bf,
231                        'e15': Bf} )
[3615]232
[3559]233#-------------------------------------------------------------------------------                                 
234# Evolve system through time
235#-------------------------------------------------------------------------------
236import time
237t0 = time.time()
238
[3679]239for t in domain.evolve(yieldstep = 240, finaltime = 6800): 
[3559]240    domain.write_time()
[3615]241    domain.write_boundary_statistics(tags = 'bottom')     
[3559]242
[3679]243for t in domain.evolve(yieldstep = 30, finaltime = 9000
244                       ,skip_initial_step = True): 
245    domain.write_time()
246    domain.write_boundary_statistics(tags = 'bottom')     
247
248for t in domain.evolve(yieldstep = 240, finaltime = 15000
249                       ,skip_initial_step = True): 
250    domain.write_time()
251    domain.write_boundary_statistics(tags = 'bottom') 
[3559]252   
253print 'That took %.2f seconds' %(time.time()-t0)
254
255print 'finished'
Note: See TracBrowser for help on using the repository browser.