source: anuga_work/production/perth/run_perth.py @ 5002

Last change on this file since 5002 was 4359, checked in by nick, 18 years ago

update perth

File size: 6.6 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
55print 'hello'
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'
65import sys
66sys.exit()
67#--------------------------------------------------------------------------
68# Create the triangular mesh based on overall clipping polygon with a
69# tagged
70# boundary and interior regions defined in project.py along with
71# resolutions (maximal area of per triangle) for each polygon
72#--------------------------------------------------------------------------
73
74if myid == 0:
75
76    print 'start create mesh from regions'
77    create_mesh_from_regions(project.poly_all,
78                         boundary_tags={'back': [4], 'side': [0,3],
79                                        'ocean': [1, 2]},
80                         maximum_triangle_area=project.res_poly_all,
81                         interior_regions=project.interior_regions,
82#                         filename=meshes_time_dir_name,
83                         filename=meshes_dir_name,
84                         use_cache=True,
85                         verbose=True)
86
87# to sync all processors are ready
88barrier()
89
90#-------------------------------------------------------------------------
91# Setup computational domain
92#-------------------------------------------------------------------------
93print 'Setup computational domain'
94#domain = Domain(meshes_time_dir_name, use_cache=True, verbose=True)
95domain = Domain(meshes_dir_name, use_cache=True, verbose=True)
96print domain.statistics()
97
98#-------------------------------------------------------------------------
99# Setup initial conditions
100#-------------------------------------------------------------------------
101if myid == 0:
102
103    print 'Setup initial conditions'
104
105    domain.set_quantity('stage', tide)
106    domain.set_quantity('friction', 0.01) 
107    #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name
108    print 'Start Set quantity'
109
110    domain.set_quantity('elevation', 
111                    filename = project.combined_dir_name+'.txt',
112#                    filename = project.combined_smaller_name_dir+'.txt',
113                    use_cache = True,
114                    verbose = True,
115                    alpha = 0.1)
116    print 'Finished Set quantity'
117barrier()
118
119#------------------------------------------------------
120# Distribute domain to implement parallelism !!!
121#------------------------------------------------------
122
123if numprocs > 1:
124    domain=distribute(domain)
125
126#------------------------------------------------------
127# Set domain parameters
128#------------------------------------------------------
129
130domain.set_name(project.scenario_name)
131domain.set_datadir(project.output_run_time_dir)
132domain.set_default_order(2) # Apply second order scheme
133domain.set_minimum_storable_height(0.001) # Don't store anything less than 0.1cm
134#domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm
135#domain.set_minimum_storable_height(0.1) # Don't store anything less than 10cm
136domain.set_store_vertices_uniquely(False)
137domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
138domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK)
139
140#-------------------------------------------------------------------------
141# Setup boundary conditions
142#-------------------------------------------------------------------------
143print 'Available boundary tags', domain.get_boundary_tags()
144
145print 'Reading Boundary file'
146print 'domain id', id(domain)
147#Bf = File_boundary(boundaries_dir_name + '.sww',
148#                  domain, time_thinning=5, use_cache=True, verbose=True)
149
150print 'finished reading boundary file'
151Br = Reflective_boundary(domain)
152Bd = Dirichlet_boundary([tide,0,0])
153Bo = Dirichlet_boundary([tide+5.0,0,0])
154
155print'set_boundary'
156domain.set_boundary({'back': Br,
157                     'side': Bd,
158                     'ocean': Bd}) 
159print'finish set boundary'
160
161#----------------------------------------------------------------------------
162# Evolve system through time
163#----------------------------------------------------------------------------
164
165t0 = time.time()
166
167for t in domain.evolve(yieldstep = 60, finaltime = 10000):
168    domain.write_time()
169    domain.write_boundary_statistics(tags = 'ocean')
170    if allclose(t, 120):
171        domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo})
172
173    if allclose(t, 1020):
174        domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd})
175
176   
177print 'That took %.2f seconds' %(time.time()-t0)
178
Note: See TracBrowser for help on using the repository browser.