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

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

update to broome

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