source: anuga_work/production/broome_2006/run_broome.py @ 3881

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

broome updates

File size: 9.0 KB
Line 
1"""Script for running a tsunami inundation scenario for Broome, WA, 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#-------------------------------------------------------------------------------
14# Import necessary modules
15#-------------------------------------------------------------------------------
16
17# Standard modules
18import os
19import time
20from shutil import copy
21from os import mkdir, access, F_OK
22import sys
23
24# Related major packages
25from anuga.shallow_water import Domain, Reflective_boundary, \
26                            Dirichlet_boundary, Time_boundary, File_boundary
27from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
28from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
29from anuga.geospatial_data.geospatial_data import *
30from anuga.abstract_2d_finite_volumes.util import Screen_Catcher
31
32# Application specific imports
33import project                 # Definition of file names and polygons
34
35#-------------------------------------------------------------------------------
36# Copy scripts to time stamped output directory and capture screen
37# output to file
38#-------------------------------------------------------------------------------
39
40# creates copy of code in output dir if dir doesn't exist
41if access(project.outputtimedir,F_OK) == 0 :
42    mkdir (project.outputtimedir)
43copy (project.codedirname, project.outputtimedir + project.codename)
44copy (project.codedir + 'run_broome.py', project.outputtimedir + 'run_broome.py')
45print'output dir', project.outputtimedir
46
47#normal screen output is stored in
48screen_output_name = project.outputtimedir + "screen_output.txt"
49screen_error_name = project.outputtimedir + "screen_error.txt"
50
51#used to catch screen output to file
52sys.stdout = Screen_Catcher(screen_output_name)
53sys.stderr = Screen_Catcher(screen_error_name)
54
55print 'USER:    ', project.user
56
57#-------------------------------------------------------------------------------
58# Preparation of topographic data
59#
60# Convert ASC 2 DEM 2 PTS using source data and store result in source data
61#-------------------------------------------------------------------------------
62
63# filenames
64onshore_dem_name = project.onshore_dem_name
65coast_points = project.coast_dem_name
66meshname = project.meshname+'.msh'
67
68# creates DEM from asc data
69convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True)
70
71#creates pts file for onshore DEM
72dem2pts(onshore_dem_name, use_cache=True, verbose=True)
73
74print 'create offshore'
75G1 = Geospatial_data(file_name = project.offshore_dem_name1 + '.xya')+\
76     Geospatial_data(file_name = project.offshore_dem_name2 + '.xya')+\
77     Geospatial_data(file_name = project.offshore_dem_name3 + '.xya')+\
78     Geospatial_data(file_name = project.offshore_dem_name4 + '.xya')+\
79     Geospatial_data(file_name = project.offshore_dem_name5 + '.xya')+\
80     Geospatial_data(file_name = project.offshore_dem_name6 + '.xya')+\
81     Geospatial_data(file_name = project.offshore_dem_name7 + '.xya')+\
82     Geospatial_data(file_name = project.offshore_dem_name8 + '.xya')+\
83     Geospatial_data(file_name = project.offshore_dem_name9 + '.xya')+\
84     Geospatial_data(file_name = project.offshore_dem_name10 + '.xya')+\
85     Geospatial_data(file_name = project.offshore_dem_name11 + '.xya')+\
86     Geospatial_data(file_name = project.offshore_dem_name12 + '.xya')+\
87     Geospatial_data(file_name = project.offshore_dem_name13 + '.xya')+\
88     Geospatial_data(file_name = project.offshore_dem_name14 + '.xya')+\
89     Geospatial_data(file_name = project.offshore_dem_name15 + '.xya')+\
90     Geospatial_data(file_name = project.offshore_dem_name16 + '.xya')+\
91     Geospatial_data(file_name = project.offshore_dem_name17 + '.xya')+\
92     Geospatial_data(file_name = project.offshore_dem_name18 + '.xya')+\
93     Geospatial_data(file_name = project.offshore_dem_name19 + '.xya')+\
94     Geospatial_data(file_name = project.offshore_dem_name20 + '.xya')+\
95     Geospatial_data(file_name = project.offshore_dem_name21 + '.xya')+\
96     Geospatial_data(file_name = project.offshore_dem_name22 + '.xya')
97print 'create onshore'
98G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts')
99print 'create coast'
100G3 = Geospatial_data(file_name = project.coast_dem_name + '.xya')
101print 'add'
102G = G1 + G2 + G3
103print 'export points'
104G.export_points_file(project.combined_dem_name + '.pts')
105
106#----------------------------------------------------------------------------
107# Create the triangular mesh based on overall clipping polygon with a tagged
108# boundary and interior regions defined in project.py along with
109# resolutions (maximal area of per triangle) for each polygon
110#-------------------------------------------------------------------------------
111
112from anuga.pmesh.mesh_interface import create_mesh_from_regions
113remainder_res = 750000
114local_res = 25000
115broome_res = 5000
116coast_res = 500
117beach_res = 500
118interior_regions = [[project.poly_broome1, local_res],
119                    [project.poly_broome2, broome_res],
120                    [project.poly_broome3, coast_res],
121                    [project.poly_broome4, beach_res]]
122
123from project import number_mesh_triangles
124print 'estimate of number of triangles', \
125      number_mesh_triangles(interior_regions, project.polyAll, remainder_res)
126
127from caching import cache
128_ = cache(create_mesh_from_regions,
129          project.polyAll,
130           {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2],
131                              'e3': [3], 'e4':[4], 'e5': [5],
132                              'e6': [6]},
133           'maximum_triangle_area': remainder_res,
134           'filename': meshname,
135           'interior_regions': interior_regions},
136          verbose = True, evaluate=False)
137print 'created mesh'
138
139#-------------------------------------------------------------------------------                                 
140# Setup computational domain
141#-------------------------------------------------------------------------------                                 
142domain = Domain(meshname, use_cache = True, verbose = True)
143
144print 'Number of triangles = ', len(domain)
145print 'The extent is ', domain.get_extent()
146print domain.statistics()
147
148domain.set_name(project.basename)
149domain.set_datadir(project.outputtimedir)
150domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
151domain.set_minimum_storable_height(0.01)
152
153#-------------------------------------------------------------------------------                                 
154# Setup initial conditions
155#-------------------------------------------------------------------------------
156
157tide = 0.0
158domain.set_quantity('stage', tide)
159domain.set_quantity('friction', 0.0) 
160domain.set_quantity('elevation', 
161                    filename = project.combined_dem_name + '.pts',
162                    use_cache = True,
163                    verbose = True,
164                    alpha = 0.1
165                    )
166
167#-------------------------------------------------------------------------------                                 
168# Setup boundary conditions
169#-------------------------------------------------------------------------------
170'''
171print 'start urs2sww'
172print '', project.boundary_basename
173from anuga.shallow_water.data_manager import urs2sww
174
175south = project.south
176north = project.north
177west  = project.west
178east  = project.east
179
180#note only need to do when an SWW file for the MOST boundary doesn't exist
181cache(urs2sww,
182      (source_dir + project.boundary_basename,
183       source_dir + project.boundary_basename),
184      {'verbose': True,
185       'minlat': south,
186       'maxlat': north,
187       'minlon': west,
188       'maxlon': east,
189       #'origin': domain.geo_reference.get_origin(),
190       'mean_stage': tide,
191       'zscale': 1,                 #Enhance tsunami
192       'fail_on_NaN': False,
193       'inverted_bathymetry': True},
194      #evaluate = True,
195       verbose = True,
196       dependencies = source_dir + project.boundary_basename + '.sww')
197
198'''
199print 'Available boundary tags', domain.get_boundary_tags()
200
201#Bf = File_boundary(source_dir + project.boundary_basename + '.sww',
202#                    domain, verbose = True)
203Br = Reflective_boundary(domain)
204Bd = Dirichlet_boundary([tide,0,0])
205
206# 7 min square wave starting at 1 min, 6m high
207Bw = Time_boundary(domain = domain,
208                   f=lambda t: [(60<t<480)*10, 0, 0])
209
210domain.set_boundary( {'e0': Bd,  'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd,
211                      'e5': Bd,  'e6': Bd} )
212
213
214#-------------------------------------------------------------------------------                                 
215# Evolve system through time
216#-------------------------------------------------------------------------------
217import time
218t0 = time.time()
219
220for t in domain.evolve(yieldstep = 240, finaltime = 480): 
221    domain.write_time()
222    domain.write_boundary_statistics(tags = 'e14')     
223   
224print 'That took %.2f seconds' %(time.time()-t0)
225
226print 'finished'
Note: See TracBrowser for help on using the repository browser.