source: anuga_work/production/onslow_2006/run_onslow.py @ 5702

Last change on this file since 5702 was 5362, checked in by kristy, 17 years ago

updated, anuga directory structure

File size: 9.7 KB
Line 
1"""Script for running a tsunami inundation scenario for Onslow, 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 simulated submarine landslide.
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, ferret2sww
28#from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
29from anuga.geospatial_data.geospatial_data import *
30#from anuga.abstract_2d_finite_volumes.util import Screen_Catcher
31#from anuga.shallow_water.data_manager import start_screen_catcher
32
33# Application specific imports
34import project                 # Definition of file names and polygons
35
36#-------------------------------------------------------------------------------
37# Copy scripts to time stamped output directory and capture screen
38# output to file
39#-------------------------------------------------------------------------------
40
41### creates copy of code in output dir if dir doesn't exist
42if access(project.outputtimedir,F_OK) == 0 :
43    mkdir (project.outputtimedir)
44copy (project.codedirname, project.outputtimedir + project.codename)
45copy (project.codedir + 'run_onslow.py', project.outputtimedir + 'run_onslow.py')
46print'output dir', project.outputtimedir
47
48###normal screen output is stored in
49##screen_output_name = project.outputtimedir + "screen_output.txt"
50##screen_error_name = project.outputtimedir + "screen_error.txt"
51##
52###used to catch screen output to file
53##sys.stdout = Screen_Catcher(screen_output_name)
54###sys.stderr = Screen_Catcher(screen_output_name)
55##sys.stderr = Screen_Catcher(screen_error_name)
56##
57##print 'USER:    ', project.user
58
59#-------------------------------------------------------------------------------
60# Preparation of topographic data
61#
62# Convert ASC 2 DEM 2 PTS using source data and store result in source data
63# Do for coarse and fine data
64# Fine pts file to be clipped to area of interest
65#-------------------------------------------------------------------------------
66
67# filenames
68onshore_dem_name = project.onshore_dem_name
69islands_dem_name = project.islands_dem_name
70coast_points = project.coast_dem_name
71offshore_points = project.offshore_dem_name
72meshname = project.meshname+'.msh'
73source_dir = project.boundarydir
74
75copied_files = False
76
77# files to be used
78files_used = [onshore_dem_name, offshore_points, coast_points,]
79
80# fine data (clipping the points file to smaller area)
81# creates DEM from asc data
82convert_dem_from_ascii2netcdf(onshore_dem_name, use_cache=True, verbose=True)
83
84#creates pts file for onshore DEM
85dem2pts(onshore_dem_name,
86        easting_min=project.eastingmin,
87        easting_max=project.eastingmax,
88        northing_min=project.northingmin,
89        northing_max= project.northingmax,
90        use_cache=True, 
91        verbose=True)
92
93convert_dem_from_ascii2netcdf(islands_dem_name, use_cache=True, verbose=True)
94
95#creates pts file for islands DEM
96dem2pts(islands_dem_name, use_cache=True, verbose=True)
97
98print'create G1'
99G1 = Geospatial_data(file_name = project.offshore_dem_name + '.txt')
100print'create G2'
101G2 = Geospatial_data(file_name = project.onshore_dem_name + '.pts')
102print'create G3'
103G3 = Geospatial_data(file_name = project.coast_dem_name + '.txt')
104print'create G4'
105G4 = Geospatial_data(file_name = project.islands_dem_name + '.pts')
106print'add G1+G2+G3+G4'
107G = G1 + G2 + G3 + G4
108print'export G'
109G.export_points_file(project.combined_dem_name + '.pts')
110
111#-------------------------------------------------------------------------------                                 
112# Create the triangular mesh based on overall clipping polygon with a tagged
113# boundary and interior regions defined in project.py along with
114# resolutions (maximal area of per triangle) for each polygon
115#-------------------------------------------------------------------------------
116
117from anuga.pmesh.mesh_interface import create_mesh_from_regions
118
119#new
120region_res = 200000
121coast_res = 25000
122onslow_res = 5000
123interior_regions = [[project.poly_onslow, onslow_res],
124                    [project.poly_coast, coast_res],
125                    [project.poly_region, region_res]]
126
127print 'number of interior regions', len(interior_regions)
128
129from caching import cache
130_ = cache(create_mesh_from_regions,
131          project.polyAll,
132          {'boundary_tags': {'top': [0], 'topleft': [1],
133                             'topleft1': [2], 'bottomleft': [3],
134                             'bottom': [4], 'bottomright': [5],
135                             'topright':[6]},
136           'maximum_triangle_area': 100000,
137           'filename': meshname,           
138           'interior_regions': interior_regions},
139          verbose = True, evaluate=True)
140
141
142#-------------------------------------------------------------------------------                                 
143# Setup computational domain
144#-------------------------------------------------------------------------------                                 
145
146#domain = pmesh_to_domain_instance(meshname, Domain,
147#                                  use_cache = False,
148#                                  verbose = True)
149
150domain = Domain(meshname, use_cache = False, verbose = True)
151
152print 'Number of triangles = ', len(domain)
153print 'The extent is ', domain.get_extent()
154print domain.statistics()
155
156domain.set_name(project.basename)
157domain.set_datadir(project.outputtimedir)
158domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
159
160
161#-------------------------------------------------------------------------------                                 
162# Setup initial conditions
163#-------------------------------------------------------------------------------
164
165tide = 0.0
166
167domain.set_quantity('stage', tide)
168domain.set_quantity('friction', 0.0) 
169print 'hi and file',project.combined_dem_name + '.pts'
170
171domain.set_quantity('elevation', 
172#                    0.
173#                    filename = project.onshore_dem_name + '.pts',
174                    filename = project.combined_dem_name + '.pts',
175#                    filename = project.offshore_dem_name + '.pts',
176                    use_cache = True,
177                    verbose = True,
178                    alpha = 0.1
179                    )
180
181print 'hi1'
182
183#-------------------------------------------------------------------------------                                 
184# Setup boundary conditions (all reflective)
185#-------------------------------------------------------------------------------
186print 'start ferret2sww'
187
188
189south = project.south
190north = project.north
191west = project.west
192east = project.east
193
194#note only need to do when an SWW file for the MOST boundary doesn't exist
195cache(ferret2sww,
196      (source_dir + project.boundary_basename,
197       source_dir + project.boundary_basename), 
198#      (project.MOST_dir + project.boundary_basename,
199#       source_dir + project.boundary_basename),
200      {'verbose': True,
201# note didn't work with the below
202#       'minlat': south - 1,
203#       'maxlat': north + 1,
204#       'minlon': west - 1,
205#       'maxlon': east + 1,
206       'minlat': south,
207       'maxlat': north,
208       'minlon': west,
209       'maxlon': east,
210#       'origin': project.mesh_origin,
211       'origin': domain.geo_reference.get_origin(),
212       'mean_stage': tide,
213       'zscale': 1,                 #Enhance tsunami
214       'fail_on_NaN': False,
215       'inverted_bathymetry': True},
216      #evaluate = True,
217       verbose = True,
218       dependencies = source_dir + project.boundary_basename + '.sww')
219
220
221print 'Available boundary tags', domain.get_boundary_tags()
222
223Bf = File_boundary(source_dir + project.boundary_basename + '.sww', 
224                    domain, verbose = True)
225Br = Reflective_boundary(domain)
226Bd = Dirichlet_boundary([tide,0,0])
227
228
229# 7 min square wave starting at 1 min, 6m high
230Bw = Time_boundary(domain = domain,
231                   f=lambda t: [(60<t<480)*6, 0, 0])
232
233domain.set_boundary( {'top': Bf, 'topleft': Bf,
234                      'topleft1': Bf, 'bottomleft': Bd,
235                      'bottom': Br, 'bottomright': Br, 'topright': Bd} )
236
237#-------------------------------------------------------------------------------                                 
238# Evolve system through time
239#-------------------------------------------------------------------------------
240import time
241t0 = time.time()
242
243for t in domain.evolve(yieldstep = 240, finaltime = 7200): 
244    domain.write_time()
245    domain.write_boundary_statistics(tags = 'top')     
246
247for t in domain.evolve(yieldstep = 120, finaltime = 12600
248                       ,skip_initial_step =True): 
249    domain.write_time()
250    domain.write_boundary_statistics(tags = 'top')     
251
252for t in domain.evolve(yieldstep = 60, finaltime = 19800
253                       ,skip_initial_step = True): 
254    domain.write_time()
255    domain.write_boundary_statistics(tags = 'top')     
256   
257for t in domain.evolve(yieldstep = 120, finaltime = 25200
258                       ,skip_initial_step = True): 
259    domain.write_time()
260    domain.write_boundary_statistics(tags = 'top')     
261
262for t in domain.evolve(yieldstep = 240, finaltime = 36000
263                       ,skip_initial_step = True): 
264    domain.write_time()
265    domain.write_boundary_statistics(tags = 'top')
266   
267print 'That took %.2f seconds' %(time.time()-t0)
268
269print 'finished'
Note: See TracBrowser for help on using the repository browser.