source: anuga_work/production/sydney_2006/run_sydney_slide.py @ 4423

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

updates for export scripts

File size: 9.1 KB
Line 
1"""Script for running a tsunami inundation scenario for Sydney, NSW, Australia.
2
3Source data such as elevation and boundary data is assumed to be available in
4directories specified by project_slide.py
5The output sww file is stored in project_slide.outputtimedir
6
7The scenario is defined by a triangular mesh created from project_slide.polygon,
8the elevation data and a tsunami wave generated by s submarine mass failure.
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.path import dirname, basename
22from os import mkdir, access, F_OK, sep
23import sys
24
25# Related major packages
26from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary
27from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
28from anuga.geospatial_data.geospatial_data import *
29from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files
30from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier
31
32# Application specific imports
33import project_slide              # 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
41#copy_code_files(project_slide.outputtimedir,__file__,dirname(project_slide.__file__)+sep+ project_slide.__name__+'.py' )
42myid = 0
43numprocs = 1
44#start_screen_catcher(project_slide.outputtimedir, myid, numprocs)
45#barrier()
46
47print 'USER:    ', project_slide.user
48
49#-------------------------------------------------------------------------------
50# Preparation of topographic data
51#
52# Convert ASC 2 DEM 2 PTS using source data and store result in source data
53#-------------------------------------------------------------------------------
54
55# filenames
56on_offshore25_dem_name = project_slide.on_offshore25_dem_name
57on_offshore100_dem_name = project_slide.on_offshore100_dem_name
58nsw_dem_name = project_slide.nsw_dem_name
59meshname = project_slide.meshname+'.msh'
60'''
61# creates DEM from asc data
62convert_dem_from_ascii2netcdf(on_offshore25_dem_name, use_cache=True, verbose=True)
63convert_dem_from_ascii2netcdf(on_offshore100_dem_name, use_cache=True, verbose=True)
64convert_dem_from_ascii2netcdf(nsw_dem_name, use_cache=True, verbose=True)
65
66#creates pts file for onshore DEM
67dem2pts(on_offshore25_dem_name,
68        easting_min=project_slide.eastingmin25,
69        easting_max=project_slide.eastingmax25,
70        northing_min=project_slide.northingmin25,
71        northing_max= project_slide.northingmax25,
72        use_cache=True, verbose=True)
73dem2pts(on_offshore100_dem_name,
74        easting_min=project_slide.eastingmin100,
75        easting_max=project_slide.eastingmax100,
76        northing_min=project_slide.northingmin100,
77        northing_max= project_slide.northingmax100,
78        use_cache=True, verbose=True)
79dem2pts(nsw_dem_name,
80        easting_min=project_slide.eastingmin_nsw,
81        easting_max=project_slide.eastingmax_nsw,
82        northing_min=project_slide.northingmin_nsw,
83        northing_max= project_slide.northingmax_nsw,
84        use_cache=True, verbose=True)
85
86print 'create offshore'
87G11 = Geospatial_data(file_name = project_slide.offshore_dem_name1 + '.xya')+\
88      Geospatial_data(file_name = project_slide.offshore_dem_name2 + '.xya')+\
89      Geospatial_data(file_name = project_slide.offshore_dem_name3 + '.xya')
90G12 = Geospatial_data(file_name = project_slide.offshore_dem_name4 + '.xya')+\
91      Geospatial_data(file_name = project_slide.offshore_dem_name5 + '.xya')+\
92      Geospatial_data(file_name = project_slide.offshore_dem_name6 + '.xya')+\
93      Geospatial_data(file_name = project_slide.offshore_dem_name7 + '.xya')+\
94      Geospatial_data(file_name = project_slide.offshore_dem_name8 + '.xya')+\
95      Geospatial_data(file_name = project_slide.offshore_dem_name9 + '.xya')
96print 'create onshore'
97G2 = Geospatial_data(file_name = project_slide.on_offshore25_dem_name + '.pts')
98G3 = Geospatial_data(file_name = project_slide.on_offshore100_dem_name + '.pts')
99G4 = Geospatial_data(file_name = project_slide.nsw_dem_name + '.pts')
100print 'add'
101G = G11.clip(Geospatial_data(project_slide.poly_surveyclip)) +\
102    G12.clip(Geospatial_data(project_slide.polyAll)) +\
103    G2.clip(Geospatial_data(project_slide.poly_25mclip)) +\
104    G3.clip(Geospatial_data(project_slide.poly_origsyd)) +\
105    (G4.clip(Geospatial_data(project_slide.polyAll))).clip_outside(Geospatial_data(project_slide.poly_surveyclip)).clip_outside(Geospatial_data(project_slide.poly_origsyd))
106print 'export points'
107G.export_points_file(project_slide.combined_dem_name + '.pts')
108#G.export_points_file(project_slide.combined_dem_name + '.xya')
109'''
110#----------------------------------------------------------------------------
111# Create the triangular mesh based on overall clipping polygon with a tagged
112# boundary and interior regions defined in project_slide.py along with
113# resolutions (maximal area of per triangle) for each polygon
114#-------------------------------------------------------------------------------
115
116from anuga.pmesh.mesh_interface import create_mesh_from_regions
117remainder_res = 250000.
118local_res = 50000.
119coast_res = 500.
120interior_regions = [[project_slide.poly_syd1, local_res],
121                    [project_slide.poly_coast, coast_res]]
122
123from caching import cache
124_ = cache(create_mesh_from_regions,
125          project_slide.polyAll,
126           {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2],
127                              'e3': [3], 'e4':[4]},
128           'maximum_triangle_area': remainder_res,
129           'filename': meshname,
130           'interior_regions': interior_regions},
131          verbose = True, evaluate=False)
132print 'created mesh'
133
134#-------------------------------------------------------------------------------                                 
135# Setup computational domain
136#-------------------------------------------------------------------------------                                 
137domain = Domain(meshname, use_cache = True, verbose = True)
138
139print 'Number of triangles = ', len(domain)
140print 'The extent is ', domain.get_extent()
141print domain.statistics()
142
143domain.set_name(project_slide.basename)
144domain.set_datadir(project_slide.outputtimedir)
145domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
146domain.set_minimum_storable_height(0.01)
147
148#-------------------------------------------------------------------------------                                 
149# Setup initial conditions
150#-------------------------------------------------------------------------------
151
152tide = 0.0
153domain.set_quantity('stage', tide)
154domain.set_quantity('friction', 0.0) 
155domain.set_quantity('elevation', 
156                    filename = project_slide.combined_dem_name + '.pts',
157                    use_cache = True,
158                    verbose = True,
159                    alpha = 0.1
160                    )
161
162#-------------------------------------------------------------------------------
163# Set up scenario (tsunami_source is a callable object used with set_quantity)
164#-------------------------------------------------------------------------------
165from smf import slide_tsunami
166
167tsunami_source = slide_tsunami(length=project_slide.yacaaba_length,
168                               width=project_slide.yacaaba_width,
169                               depth=project_slide.yacaaba_depth,
170                               slope=project_slide.yacaaba_slope,
171                               thickness=project_slide.yacaaba_thickness, 
172                               x0=project_slide.slide_origin_yacaaba_b[0], 
173                               y0=project_slide.slide_origin_yacaaba_b[1], 
174                               alpha=project_slide.yacaaba_alpha, 
175                               domain=domain)
176
177#-------------------------------------------------------------------------------                                 
178# Setup boundary conditions
179#-------------------------------------------------------------------------------
180print 'Available boundary tags', domain.get_boundary_tags()
181
182Br = Reflective_boundary(domain)
183Bd = Dirichlet_boundary([tide,0,0])
184
185domain.set_boundary( {'e0': Bd,  'e1': Bd, 'e2': Bd, 'e3': Bd, 'e4': Bd} )
186
187
188#-------------------------------------------------------------------------------                                 
189# Evolve system through time
190#-------------------------------------------------------------------------------
191import time
192from Numeric import allclose
193from anuga.abstract_2d_finite_volumes.quantity import Quantity
194
195t0 = time.time()
196
197for t in domain.evolve(yieldstep = 30, finaltime = 5000): 
198    domain.write_time()
199    domain.write_boundary_statistics(tags = 'e2')
200    stagestep = domain.get_quantity('stage') 
201
202    if allclose(t, 30):
203        slide = Quantity(domain)
204        slide.set_values(tsunami_source)
205        domain.set_quantity('stage', slide + stagestep)
206   
207print 'That took %.2f seconds' %(time.time()-t0)
208
209print 'finished'
Note: See TracBrowser for help on using the repository browser.