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

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

Hobart updates; using gridded data

File size: 8.1 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_offshore_dem_name = project.onshore_offshore_dem_name
64meshname = project.meshname+'.msh'
65source_dir = project.boundarydir
66
67copied_files = False
68
69# create DEM from asc data - 25m data
70convert_dem_from_ascii2netcdf(onshore_offshore_dem_name, use_cache=True, verbose=True)
71
72#creates pts file for combined DEM - 25
73dem2pts(onshore_offshore_dem_name, use_cache=True, verbose=True)
74
75# create geospatial data set and export
76G = Geospatial_data(file_name = project.onshore_offshore_dem_name + '.pts')
77G.export_points_file(project.combined_dem_name + '.pts')
78
79#----------------------------------------------------------------------------
80# Create the triangular mesh based on overall clipping polygon with a tagged
81# boundary and interior regions defined in project.py along with
82# resolutions (maximal area of per triangle) for each polygon
83#-------------------------------------------------------------------------------
84
85from anuga.pmesh.mesh_interface import create_mesh_from_regions
86
87# use 75 for onshore components (12.5m DEM)
88island_res = 35000
89hobart_res = 35000
90peninsula_res = 35000
91interior_regions = [[project.poly_hobart, hobart_res],
92                    [project.poly_tasman_peninsula, peninsula_res],
93                    [project.poly_bruny, island_res]]
94
95print 'number of interior regions', len(interior_regions)
96
97from caching import cache
98_ = cache(create_mesh_from_regions,
99          project.polyAll,
100          {'boundary_tags': {'bottom': [0], 'bright': [1],
101                             'topr': [2], 'top': [3], 'left': [4]},
102           'maximum_triangle_area': 250000,
103           'filename': meshname},           
104           #'interior_regions': interior_regions},
105          verbose = True, evaluate=True)
106
107
108#-------------------------------------------------------------------------------                                 
109# Setup computational domain
110#-------------------------------------------------------------------------------                                 
111domain = Domain(meshname, use_cache = False, verbose = True)
112
113print 'Number of triangles = ', len(domain)
114print 'The extent is ', domain.get_extent()
115print domain.statistics()
116
117domain.set_name(project.basename)
118domain.set_datadir(project.outputtimedir)
119domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
120domain.set_minimum_storable_height(0.01)
121domain.set_store_vertices_uniquely(True)  # for writting to sww
122
123#-------------------------------------------------------------------------------                                 
124# Setup initial conditions
125#-------------------------------------------------------------------------------
126
127tide = 0.0
128
129domain.set_quantity('stage', tide)
130domain.set_quantity('friction', 0.0) 
131
132domain.set_quantity('elevation', 
133#                    filename = project.onshore_dem_name + '.pts',
134                    filename = project.combined_dem_name + '.pts',
135#                    filename = project.offshore_dem_name + '.pts',
136                    use_cache = True,
137                    verbose = True,
138                    alpha = 0.1
139                    )
140
141#-------------------------------------------------------------------------------                                 
142# Setup boundary conditions
143#-------------------------------------------------------------------------------
144print 'start ferret2sww'
145from anuga.shallow_water.data_manager import ferret2sww
146'''
147south = project.south
148north = project.north
149west = project.west
150east = project.east
151
152#note only need to do when an SWW file for the MOST boundary doesn't exist
153cache(ferret2sww,
154      (source_dir + project.boundary_basename,
155       source_dir + project.boundary_basename),
156#      (project.MOST_dir + project.boundary_basename,
157#       source_dir + project.boundary_basename),
158      {'verbose': True,
159# note didn't work with the below
160#       'minlat': south - 1,
161#       'maxlat': north + 1,
162#       'minlon': west - 1,
163#       'maxlon': east + 1,
164       'minlat': south,
165       'maxlat': north,
166       'minlon': west,
167       'maxlon': east,
168#       'origin': project.mesh_origin,
169       'origin': domain.geo_reference.get_origin(),
170       'mean_stage': tide,
171       'zscale': 1,                 #Enhance tsunami
172       'fail_on_NaN': False,
173       'inverted_bathymetry': True},
174      #evaluate = True,
175       verbose = True,
176       dependencies = source_dir + project.boundary_basename + '.sww')
177
178'''
179print 'Available boundary tags', domain.get_boundary_tags()
180
181#Bf = File_boundary(source_dir + project.boundary_basename + '.sww',
182#                    domain, verbose = True)
183Br = Reflective_boundary(domain)
184Bd = Dirichlet_boundary([tide,0,0])
185
186
187# 7 min square wave starting at 1 min, 6m high
188Bw = Time_boundary(domain = domain,
189                   f=lambda t: [(60<t<480)*10, 0, 0])
190
191# for MOST BC
192#domain.set_boundary( {'top': Bd, 'left': Bd,
193#                      'bottom': Bf, 'right': Bf} )
194
195# for testing
196domain.set_boundary( {'topr': Bd, 'left': Bd, 'top': Bd,
197                      'bottom': Bw, 'bright': Bd} )
198
199#-------------------------------------------------------------------------------                                 
200# Evolve system through time
201#-------------------------------------------------------------------------------
202import time
203t0 = time.time()
204
205for t in domain.evolve(yieldstep = 60, finaltime = 120): 
206    domain.write_time()
207    domain.write_boundary_statistics(tags = 'bottom')     
208
209#for t in domain.evolve(yieldstep = 120, finaltime = 12600
210#                       ,skip_initial_step = True):
211#    domain.write_time()
212#    domain.write_boundary_statistics(tags = 'bottom')     
213   
214print 'That took %.2f seconds' %(time.time()-t0)
215
216print 'finished'
Note: See TracBrowser for help on using the repository browser.