source: anuga_work/production/perth_2006/run_perth.py @ 4282

Last change on this file since 4282 was 4152, checked in by nick, 18 years ago

update perth_2006/run_perth.py

File size: 8.0 KB
Line 
1"""Script for running tsunami inundation scenario for Perth, 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.output_run_time_dir
6
7The scenario is defined by a triangular mesh created from project.polygon,
8the elevation data and a simulated tsunami generated with URS code.
9
10Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006
11"""
12
13#------------------------------------------------------------------------------
14# Import necessary modules
15#------------------------------------------------------------------------------
16
17# Standard modules
18from os import sep
19from os.path import dirname, basename
20from os import mkdir, access, F_OK
21from shutil import copy
22import time
23import sys
24
25# Related major packages
26from anuga.shallow_water import Domain
27from anuga.shallow_water import Dirichlet_boundary
28from anuga.shallow_water import File_boundary
29from anuga.shallow_water import Reflective_boundary
30from Numeric import allclose
31
32from anuga.pmesh.mesh_interface import create_mesh_from_regions
33from anuga.geospatial_data.geospatial_data import *
34from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files
35from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier
36from anuga.utilities.polygon import plot_polygons, polygon_area
37
38# Application specific imports
39import project                 # Definition of file names and polygons
40
41#------------------------------------------------------------------------------
42# Copy scripts to time stamped output directory and capture screen
43# output to file
44#------------------------------------------------------------------------------
45
46start_screen_catcher(project.output_run_time_dir, myid, numprocs)
47
48# filenames
49boundaries_name = project.scenario
50meshes_dir_name = project.meshes_dir_name+'.msh'
51#boundaries_time_dir_name = project.boundaries_time_dir_name
52boundaries_dir_name = project.boundaries_dir_name
53
54tide = project.tide
55
56# creates copy of code in output dir
57if myid == 0:
58    copy_code_files(project.output_run_time_dir,__file__, 
59                 dirname(project.__file__)+sep+ project.__name__+'.py' )
60barrier()
61
62print 'USER: ', project.user
63print 'min triangles', project.trigs_min,
64print 'Note: This is generally about 20% less than the final amount'
65
66#--------------------------------------------------------------------------
67# Create the triangular mesh based on overall clipping polygon with a
68# tagged
69# boundary and interior regions defined in project.py along with
70# resolutions (maximal area of per triangle) for each polygon
71#--------------------------------------------------------------------------
72
73if myid == 0:
74
75    print 'start create mesh from regions'
76#    interior_regions = [[project.poly_pos20_neg20, project.res_pos20_neg20],
77#                    [project.poly_cbd, project.res_cbd],
78#                    [project.poly_penguin, project.res_penguin]]   
79#                    [project.poly_interior, 1000]]       
80
81#    from anuga.utilities.polygon import plot_polygons
82#    figname = project.output_run_time_dir + 'poly_pic'
83#    plot_polygons([project.poly_coast,project.poly_pipeline,project.poly_facility,
84#               project.bounding_polygon],
85#               figname,
86#               verbose = True)
87#    import sys; sys.exit()
88
89    print 'start create mesh from regions'
90    create_mesh_from_regions(project.poly_all,
91                         boundary_tags={'back': [4], 'side': [0,3],
92                                        'ocean': [1, 2]},
93                         maximum_triangle_area=project.res_poly_all,
94                         interior_regions=project.interior_regions,
95#                         filename=meshes_time_dir_name,
96                         filename=meshes_dir_name,
97                         use_cache=True,
98                         verbose=True)
99
100# to sync all processors are ready
101barrier()
102
103#-------------------------------------------------------------------------
104# Setup computational domain
105#-------------------------------------------------------------------------
106print 'Setup computational domain'
107#domain = Domain(meshes_time_dir_name, use_cache=True, verbose=True)
108domain = Domain(meshes_dir_name, use_cache=True, verbose=True)
109print domain.statistics()
110'''
111print 'starting to create boundary conditions'
112boundaries_in_dir_name = project.boundaries_in_dir_name
113
114from anuga.shallow_water.data_manager import urs2sww, ferret2sww
115
116# put above distribute
117print 'boundary file is: ',boundaries_dir_name
118from caching import cache
119if myid == 0:
120    cache(ferret2sww,
121          (boundaries_in_dir_name,
122    #       boundaries_time_dir_name),
123           boundaries_dir_name),
124          {'verbose': True,
125           'minlat': project.south_boundary,
126           'maxlat': project.north_boundary,
127           'minlon': project.west_boundary,
128           'maxlon': project.east_boundary,
129#           'minlat': project.south,
130#           'maxlat': project.north,
131#           'minlon': project.west,
132#           'maxlon': project.east,
133           'mint': 0, 'maxt': 35100,
134           'origin': domain.geo_reference.get_origin(),
135           'mean_stage': project.tide,
136#           'zscale': 1,                 #Enhance tsunami
137           'fail_on_NaN': False},
138           verbose = True,
139           )
140barrier()
141'''
142
143#-------------------------------------------------------------------------
144# Setup initial conditions
145#-------------------------------------------------------------------------
146if myid == 0:
147
148    print 'Setup initial conditions'
149
150    domain.set_quantity('stage', tide)
151    domain.set_quantity('friction', 0.01) 
152    #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name
153    print 'Start Set quantity'
154
155    domain.set_quantity('elevation', 
156#                    filename = project.combined_dir_name+'.txt',
157                    filename = project.combined_smaller_name_dir+'.txt',
158                    use_cache = True,
159                    verbose = True,
160                    alpha = 0.1)
161    print 'Finished Set quantity'
162barrier()
163
164#------------------------------------------------------
165# Distribute domain to implement parallelism !!!
166#------------------------------------------------------
167
168if numprocs > 1:
169    domain=distribute(domain)
170
171#------------------------------------------------------
172# Set domain parameters
173#------------------------------------------------------
174
175domain.set_name(project.scenario_name)
176domain.set_datadir(project.output_run_time_dir)
177domain.set_default_order(2) # Apply second order scheme
178domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm
179domain.set_store_vertices_uniquely(False)
180domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
181domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK)
182
183#-------------------------------------------------------------------------
184# Setup boundary conditions
185#-------------------------------------------------------------------------
186print 'Available boundary tags', domain.get_boundary_tags()
187
188print 'Reading Boundary file'
189print 'domain id', id(domain)
190#Bf = File_boundary(boundaries_dir_name + '.sww',
191#                  domain, time_thinning=5, use_cache=True, verbose=True)
192
193print 'finished reading boundary file'
194Br = Reflective_boundary(domain)
195Bd = Dirichlet_boundary([tide,0,0])
196Bo = Dirichlet_boundary([tide+5.0,0,0])
197
198print'set_boundary'
199domain.set_boundary({'back': Br,
200                     'side': Bd,
201                     'ocean': Bd}) 
202print'finish set boundary'
203
204#----------------------------------------------------------------------------
205# Evolve system through time
206#----------------------------------------------------------------------------
207
208t0 = time.time()
209
210for t in domain.evolve(yieldstep = 60, finaltime = 10000):
211    domain.write_time()
212    domain.write_boundary_statistics(tags = 'ocean')
213    if allclose(t, 120):
214        domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo})
215
216    if allclose(t, 1020):
217        domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd})
218
219   
220print 'That took %.2f seconds' %(time.time()-t0)
221
Note: See TracBrowser for help on using the repository browser.