source: trunk/anuga_documentation/user_manual/demos/cairns/run_parallel_cairns.py @ 8899

Last change on this file since 8899 was 8714, checked in by steve, 12 years ago

Added parallel version of runcairns.py

File size: 7.6 KB
Line 
1"""Script for running a tsunami inundation scenario for Cairns, QLD 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 directory named after the scenario, i.e
6slide or fixed_wave.
7
8The scenario is defined by a triangular mesh created from project.polygon,
9the elevation data and a tsunami wave generated by a submarine mass failure.
10
11Geoscience Australia, 2004-present
12"""
13
14#------------------------------------------------------------------------------
15# Import necessary modules
16#------------------------------------------------------------------------------
17# Standard modules
18import os
19import time
20import sys
21
22# Related major packages
23import anuga
24
25
26# Application specific imports
27import project                 # Definition of file names and polygons
28
29# The parallel interface
30from anuga_parallel import distribute, myid, numprocs, finalize, barrier
31
32#------------------------------------------------------------------------------
33# Do the domain creation on processor 0
34#------------------------------------------------------------------------------
35if myid == 0:
36
37    #------------------------------------------------------------------------------
38    # Preparation of topographic data
39    # Convert ASC 2 DEM 2 PTS using source data and store result in source data
40    #------------------------------------------------------------------------------
41    # Create DEM from asc data
42    #anuga.asc2dem(project.name_stem+'.asc', use_cache=project.cache, verbose=project.verbose)
43
44    # Create pts file for onshore DEM
45    #anuga.dem2pts(project.name_stem+'.dem', use_cache=project.cache, verbose=project.verbose)
46
47    #------------------------------------------------------------------------------
48    # Create the triangular mesh and domain based on
49    # overall clipping polygon with a tagged
50    # boundary and interior regions as defined in project.py
51    #------------------------------------------------------------------------------
52    domain = anuga.create_domain_from_regions(project.bounding_polygon,
53                                        boundary_tags={'top': [0],
54                                                       'ocean_east': [1],
55                                                       'bottom': [2],
56                                                       'onshore': [3]},
57                                        maximum_triangle_area=project.default_res,
58                                        mesh_filename=project.meshname,
59                                        interior_regions=project.interior_regions,
60                                        use_cache=project.cache,
61                                        verbose=project.verbose)
62
63    # Print some stats about mesh and domain
64    print 'Number of triangles = ', len(domain)
65    print 'The extent is ', domain.get_extent()
66    print domain.statistics()
67
68    #------------------------------------------------------------------------------
69    # Setup parameters of computational domain
70    #------------------------------------------------------------------------------
71    domain.set_name('cairns_' + project.scenario) # Name of sww file
72    domain.set_datadir('.')                       # Store sww output here
73    domain.set_minimum_storable_height(0.01)      # Store only depth > 1cm
74    domain.set_flow_algorithm('tsunami')
75
76
77   
78
79    #------------------------------------------------------------------------------
80    # Setup initial conditions
81    #------------------------------------------------------------------------------
82    tide = project.tide
83    domain.set_quantity('stage', project.tide)
84    domain.set_quantity('friction', 0.0)
85
86
87    domain.set_quantity('elevation',
88                        filename=project.name_stem + '.pts',
89                        use_cache=project.cache,
90                        verbose=project.verbose,
91                        alpha=0.1)
92
93
94
95else:
96    domain = None
97
98
99
100#------------------------------------------------------------------------------
101# Now produce parallel domain
102#------------------------------------------------------------------------------
103domain = distribute(domain,verbose=project.verbose)
104
105domain.set_store_vertices_uniquely(False)
106
107#------------------------------------------------------------------------------
108# Setup information for slide scenario (to be applied 1 min into simulation
109#------------------------------------------------------------------------------
110if project.scenario == 'slide':
111    # Function for submarine slide
112    tsunami_source = anuga.slide_tsunami(length=35000.0,
113                                   depth=project.slide_depth,
114                                   slope=6.0,
115                                   thickness=500.0, 
116                                   x0=project.slide_origin[0], 
117                                   y0=project.slide_origin[1], 
118                                   alpha=0.0, 
119                                   domain=domain,
120                                   verbose=True)
121
122#------------------------------------------------------------------------------
123# Setup boundary conditions
124#------------------------------------------------------------------------------
125print 'Available boundary tags', domain.get_boundary_tags()
126
127Bd = anuga.Dirichlet_boundary([project.tide, 0, 0]) # Mean water level
128Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary
129
130if project.scenario == 'fixed_wave':
131    # Huge 50m wave starting after 60 seconds and lasting 1 hour.
132    Bw = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
133                        domain=domain, 
134                        function=lambda t: [(60<t<3660)*50, 0, 0])
135
136    domain.set_boundary({'ocean_east': Bw,
137                         'bottom': Bs,
138                         'onshore': Bd,
139                         'top': Bs})
140
141if project.scenario == 'slide':
142    # Boundary conditions for slide scenario
143    domain.set_boundary({'ocean_east': Bd,
144                         'bottom': Bd,
145                         'onshore': Bd,
146                         'top': Bd})
147
148#------------------------------------------------------------------------------
149# Evolve system through time
150#------------------------------------------------------------------------------
151import time
152t0 = time.time()
153
154from numpy import allclose
155
156if project.scenario == 'slide':
157    # Initial run without any event
158    for t in domain.evolve(yieldstep=10, finaltime=60): 
159        print domain.timestepping_statistics()
160        #print domain.boundary_statistics(tags='ocean_east')
161       
162    # Add slide to water surface
163    if allclose(t, 60):
164        domain.add_quantity('stage', tsunami_source)   
165
166    # Continue propagating wave
167    for t in domain.evolve(yieldstep=10, finaltime=5000, 
168                           skip_initial_step=True):
169        print domain.timestepping_statistics()
170        #print domain.boundary_statistics(tags='ocean_east')
171
172if project.scenario == 'fixed_wave':
173    # Save every two mins leading up to wave approaching land
174    for t in domain.evolve(yieldstep=2*60, finaltime=5000): 
175        print domain.timestepping_statistics()
176        #print domain.boundary_statistics(tags='ocean_east')
177
178    # Save every 30 secs as wave starts inundating ashore
179    for t in domain.evolve(yieldstep=60*0.5, finaltime=10000, 
180                           skip_initial_step=True):
181        print domain.timestepping_statistics()
182        #print domain.boundary_statistics(tags='ocean_east')
183           
184print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.