source: anuga_core/documentation/user_manual/demos/cairns/runcairns.py @ 3979

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

moving cairns demo into user_manual directory

File size: 9.1 KB
Line 
1"""Script for running a tsunami inundation scenario for Broome, 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 tsunami wave generated by MOST.
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
28from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
29from anuga.geospatial_data.geospatial_data import *
30from anuga.abstract_2d_finite_volumes.util import Screen_Catcher
31
32# Application specific imports
33import project                 # Definition of file names and polygons
34
35#-------------------------------------------------------------------------------
36# Define scenario as either slump or fixed_wave.
37#-------------------------------------------------------------------------------
38scenario = 'slump' # 'fixedwave'
39mkdir (scenario)
40basename = scenario + project.basename
41
42#-------------------------------------------------------------------------------
43# Copy scripts to time stamped output directory and capture screen
44# output to file
45#-------------------------------------------------------------------------------
46
47# creates copy of code in output dir if dir doesn't exist
48if access(project.outputtimedir,F_OK) == 0 :
49    mkdir (project.outputtimedir)
50copy (project.codedirname, project.outputtimedir + project.codename)
51copy (project.codedir + 'runcairns.py', project.outputtimedir + 'runcairns2.py')
52print'output dir', project.outputtimedir
53
54#normal screen output is stored in
55screen_output_name = project.outputtimedir + "screen_output.txt"
56screen_error_name = project.outputtimedir + "screen_error.txt"
57
58#used to catch screen output to file
59sys.stdout = Screen_Catcher(screen_output_name)
60sys.stderr = Screen_Catcher(screen_error_name)
61
62print 'USER:    ', project.user
63
64#-------------------------------------------------------------------------------
65# Preparation of topographic data
66#
67# Convert ASC 2 DEM 2 PTS using source data and store result in source data
68#-------------------------------------------------------------------------------
69
70# filenames
71dem_name = project.dem_name
72meshname = project.meshname+'.msh'
73
74# creates DEM from asc data
75convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True)
76
77#creates pts file for onshore DEM
78dem2pts(dem_name, use_cache=True, verbose=True)
79
80#----------------------------------------------------------------------------
81# Create the triangular mesh based on overall clipping polygon with a tagged
82# boundary and interior regions defined in project.py along with
83# resolutions (maximal area of per triangle) for each polygon
84#-------------------------------------------------------------------------------
85
86from anuga.pmesh.mesh_interface import create_mesh_from_regions
87remainder_res = 10000000
88islands_res = 100000
89cairns_res = 100000
90shallow_res = 500000
91interior_regions = [[project.poly_cairns, cairns_res],
92                    [project.poly_island0, islands_res],
93                    [project.poly_island1, islands_res],
94                    [project.poly_island2, islands_res],
95                    [project.poly_island3, islands_res],
96                    [project.poly_shallow, shallow_res]]
97
98from caching import cache
99_ = cache(create_mesh_from_regions,
100          project.polyAll,
101           {'boundary_tags': {'top': [0], 'ocean_east': [1],
102                              'bottom': [2], 'onshore': [3]},
103           'maximum_triangle_area': remainder_res,
104           'filename': meshname,
105           'interior_regions': interior_regions},
106          verbose = True, evaluate=False)
107print 'created mesh'
108
109#-------------------------------------------------------------------------------                                 
110# Setup computational domain
111#-------------------------------------------------------------------------------                                 
112domain = Domain(meshname, use_cache = True, verbose = True)
113
114print 'Number of triangles = ', len(domain)
115print 'The extent is ', domain.get_extent()
116print domain.statistics()
117
118domain.set_name(basename) #domain.set_name(project.basename)
119domain.set_datadir(scenario) #domain.set_datadir(project.outputtimedir)
120domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
121domain.set_minimum_storable_height(0.01)
122
123#-------------------------------------------------------------------------------                                 
124# Setup initial conditions
125#-------------------------------------------------------------------------------
126
127tide = 0.0
128domain.set_quantity('stage', tide)
129domain.set_quantity('friction', 0.0) 
130domain.set_quantity('elevation', 
131                    filename = project.dem_name + '.pts',
132                    use_cache = True,
133                    verbose = True,
134                    alpha = 0.1
135                    )
136
137#-------------------------------------------------------------------------------                                 
138# Setup information for slump scenario (to be applied 1 min into simulation
139#-------------------------------------------------------------------------------
140if scenario == 'slump':
141    from anuga.shallow_water.smf import slump_tsunami  # Function for submarine slump
142    tsunami_source = slump_tsunami(length=15000.0,
143                                   depth=project.slump_depth,
144                                   slope=6.0,
145                                   thickness=250.0, 
146                                   radius=3330,
147                                   dphi=0.23,
148                                   x0=project.slump_origin[0], 
149                                   y0=project.slump_origin[1], 
150                                   alpha=0.0, 
151                                   domain=domain,
152                                   verbose=True)
153
154
155#-------------------------------------------------------------------------------                                 
156# Setup boundary conditions
157#-------------------------------------------------------------------------------
158print 'Available boundary tags', domain.get_boundary_tags()
159
160Br = Reflective_boundary(domain)
161Bd = Dirichlet_boundary([tide,0,0])
162
163# 7 min square wave starting at 1 min, 10m high
164if scenario == 'fixed_wave':
165    Bw = Time_boundary(domain = domain,
166                       f=lambda t: [(60<t<480)*10, 0, 0])
167    domain.set_boundary( {'ocean_east': Bw, 'bottom': Bd, 'onshore': Bd,
168                           'top': Bd} )
169
170# boundary conditions for slump scenario
171if scenario == 'slump':
172    domain.set_boundary( {'ocean_east': Bd, 'bottom': Bd, 'onshore': Bd,
173                          'top': Bd} )
174
175
176#-------------------------------------------------------------------------------                                 
177# Evolve system through time
178#-------------------------------------------------------------------------------
179import time
180t0 = time.time()
181
182from Numeric import allclose
183from anuga.abstract_2d_finite_volumes.quantity import Quantity
184
185if scenario == 'slump':
186   
187    for t in domain.evolve(yieldstep = 30, finaltime = 60): 
188        domain.write_time()
189        domain.write_boundary_statistics(tags = 'ocean_east')     
190       
191        # add slump
192        thisstagestep = domain.get_quantity('stage')
193        if allclose(t, 60):
194            slump = Quantity(domain)
195            slump.set_values(tsunami_source)
196            domain.set_quantity('stage', slump + thisstagestep)
197
198        # save every two mins leading up to wave approaching land
199        for t in domain.evolve(yieldstep = 120, finaltime = 1000, 
200                               skip_initial_step = True):
201            domain.write_time()
202            domain.write_boundary_statistics(tags = 'ocean_east')
203
204        # save every 30 secs as wave starts inundating ashore
205        for t in domain.evolve(yieldstep = 30, finaltime = 10000, 
206                               skip_initial_step = True):
207            domain.write_time()
208            domain.write_boundary_statistics(tags = 'ocean_east')
209
210if scenario == 'fixed_wave':
211
212    # save every two mins leading up to wave approaching land
213    for t in domain.evolve(yieldstep = 120, finaltime = 1000): 
214        domain.write_time()
215        domain.write_boundary_statistics(tags = 'ocean_east')     
216
217        # save every 30 secs as wave starts inundating ashore
218        for t in domain.evolve(yieldstep = 30, finaltime = 10000, 
219                               skip_initial_step = True):
220            domain.write_time()
221            domain.write_boundary_statistics(tags = 'ocean_east')
222           
223print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.