source: anuga_work/production/australia_ph2/melbourne/run_model.py @ 6692

Last change on this file since 6692 was 6692, checked in by myall, 15 years ago

adding melbourne phase 2

running get timeseries for latest WA models

File size: 9.0 KB
Line 
1"""Run a tsunami inundation scenario for Busselton, WA, Australia.
2
3The scenario is defined by a triangular mesh created from project.polygon, the
4elevation data is compiled into a pts file through build_elevation.py and a
5simulated tsunami is generated through an sts file from build_boundary.py.
6
7Input: sts file (build_boundary.py for respective event)
8       pts file (build_elevation.py)
9       information from project file
10Outputs: sww file stored in project.output_run_time_dir
11The export_results_all.py and get_timeseries.py is reliant
12on the outputs of this script
13
14Ole Nielsen and Duncan Gray, GA - 2005, Jane Sexton, Nick Bartzis, GA - 2006
15Ole Nielsen, Jane Sexton and Kristy Van Putten - 2008
16"""
17
18#------------------------------------------------------------------------------
19# Import necessary modules
20#------------------------------------------------------------------------------
21
22# Standard modules
23import os
24import os.path
25import time
26from time import localtime, strftime, gmtime
27
28# Related major packages
29from Scientific.IO.NetCDF import NetCDFFile
30import Numeric as num
31
32from anuga.interface import create_domain_from_regions
33from anuga.interface import Transmissive_stage_zero_momentum_boundary
34from anuga.interface import Dirichlet_boundary
35from anuga.interface import Reflective_boundary
36from anuga.interface import Field_boundary
37from anuga.interface import Time_boundary
38from anuga.interface import file_function
39
40from anuga.interface import create_sts_boundary
41from anuga.interface import csv2building_polygons
42from file_length import file_length
43
44from anuga.shallow_water.data_manager import start_screen_catcher
45from anuga.shallow_water.data_manager import copy_code_files
46from anuga.shallow_water.data_manager import urs2sts
47from anuga.utilities.polygon import read_polygon, Polygon_function
48
49# Application specific imports
50from setup_model import project
51import build_urs_boundary as bub
52import prepare_timeboundary as TB
53
54#-------------------------------------------------------------------------------
55# Copy scripts to time stamped output directory and capture screen
56# output to file. Copy script must be before screen_catcher
57#-------------------------------------------------------------------------------
58
59copy_code_files(project.output_run, __file__, 
60                os.path.join(os.path.dirname(project.__file__),
61                             project.__name__+'.py'))
62start_screen_catcher(project.output_run, 0, 1)
63
64#-------------------------------------------------------------------------------
65# Create the computational domain based on overall clipping polygon with
66# a tagged boundary and interior regions defined in project.py along with
67# resolutions (maximal area of per triangle) for each polygon
68#-------------------------------------------------------------------------------
69
70print 'Create computational domain'
71
72# Create the STS file
73print 'project.mux_data_folder=%s' % project.mux_data_folder
74if not os.path.exists(project.event_sts_east + '.sts'):
75    bub.build_urs_boundary(project.mux_input_filename, project.event_sts_east, project.urs_order_east)
76if not os.path.exists(project.event_sts_west + '.sts'):
77    bub.build_urs_boundary(project.mux_input_filename, project.event_sts_west, project.urs_order_west)
78
79# Read in boundary from ordered sts file
80event_sts_east = create_sts_boundary(project.event_sts_east)
81event_sts_west = create_sts_boundary(project.event_sts_west)
82
83# Reading the landward defined points, this incorporates the original clipping
84# polygon minus the 100m contour
85landward_boundary_N = read_polygon(project.landward_boundary_N)
86landward_boundary_S = read_polygon(project.landward_boundary_S)
87
88##print 'land N', landward_boundary_N, ' with length ', len(landward_boundary_N)
89##print 'land S', landward_boundary_S, ' with length ', len(landward_boundary_S)
90
91# Combine sts polyline with landward points
92bounding_polygon_sts = landward_boundary_N + event_sts_east + landward_boundary_S + event_sts_west
93
94print 'bounding polygon sts',bounding_polygon_sts,'length',len(bounding_polygon_sts)
95
96# 4 sides: north (land), east (ocean), south (land), west (ocean)
97num_north_points = len(landward_boundary_N)
98num_east_points = len(event_sts_east)
99num_south_points = len(landward_boundary_S)
100num_west_points = len(event_sts_west)
101
102# Boundary tags refer to project.landward_boundary
103# 4 points equals 5 segments start at N
104boundary_tags={'back': range(num_north_points-1) + range(num_north_points+num_east_points,num_north_points+num_east_points+num_south_points-1),
105               'side': [num_north_points-1,
106                        num_north_points+num_east_points-1,
107                        num_north_points+num_east_points+num_south_points-1,
108                        num_north_points+num_east_points+num_south_points+num_west_points-1],
109               'oceanE': range(num_north_points,num_north_points+num_east_points-1),
110               'oceanW': range(num_north_points+num_east_points+num_south_points,num_north_points+num_east_points+num_south_points+num_west_points-1)}
111
112##print 'tags',boundary_tags
113
114# Build mesh and domain
115domain = create_domain_from_regions(bounding_polygon_sts,
116                                    boundary_tags=boundary_tags,
117                                    maximum_triangle_area=project.bounding_maxarea,
118                                    interior_regions=project.interior_regions,
119                                    mesh_filename=project.meshes,
120                                    use_cache=True,
121                                    verbose=True)
122print domain.statistics()
123
124domain.set_name(project.scenario_name)
125domain.set_datadir(project.output_run) 
126domain.set_minimum_storable_height(0.01)    # Don't store depth less than 1cm
127
128#-------------------------------------------------------------------------------
129# Setup initial conditions
130#-------------------------------------------------------------------------------
131
132print 'Setup initial conditions'
133
134# Set the initial stage in the offcoast region only
135if project.land_initial_conditions:
136    IC = Polygon_function(project.land_initial_conditions,
137                          default=project.tide,
138                          geo_reference=domain.geo_reference)
139else:
140    IC = 0
141domain.set_quantity('stage', IC, use_cache=True, verbose=True)
142domain.set_quantity('friction', project.friction) 
143domain.set_quantity('elevation', 
144                    filename=project.combined_elevation+'.pts',
145                    use_cache=True,
146                    verbose=True,
147                    alpha=project.alpha)
148
149#-------------------------------------------------------------------------------
150# Setup boundary conditions
151#-------------------------------------------------------------------------------
152
153print 'Set boundary - available tags:', domain.get_boundary_tags()
154
155# Prepare time boundary
156TB.prepare_timeboundary(project.boundary_csv)
157f = file_function(project.boundary_csv[:-4] + '.tms')
158
159Br = Reflective_boundary(domain)
160Bt = Transmissive_stage_zero_momentum_boundary(domain)
161Bd = Dirichlet_boundary([project.tide, 0, 0])
162
163if project.wave == 'Bf':
164    Bfe = Field_boundary(project.event_sts_east+'.sts',
165                        domain, mean_stage=project.tide,
166                        time_thinning=1,
167                        default_boundary=Dirichlet_boundary([0, 0, 0]),
168                        boundary_polygon=bounding_polygon_sts,                   
169                        use_cache=True,
170                        verbose=True)
171    Bfw = Field_boundary(project.event_sts_west+'.sts',
172                        domain, mean_stage=project.tide,
173                        time_thinning=1,
174                        default_boundary=Dirichlet_boundary([0, 0, 0]),
175                        boundary_polygon=bounding_polygon_sts,                   
176                        use_cache=True,
177                        verbose=True)
178    domain.set_boundary({'back': Br,
179                     'side': Bt,
180                     'oceanE': Bfe,
181                     'oceanW': Bfw}) 
182   
183elif project.wave == 'Tb':
184    Tb = Time_boundary(domain,f,default_boundary=Dirichlet_boundary([0, 0, 0]) )
185
186    if project.event_side == 'east' :
187        domain.set_boundary({'back': Br,
188                             'side': Bt,
189                             'oceanW': Bt,
190                             'oceanE': Tb})
191    elif project.event_side == 'west' :
192        domain.set_boundary({'back': Br,
193                             'side': Bt,
194                             'oceanW': Tb,
195                             'oceanE': Bt})
196    else:
197        print 'need to specify which side event is on'
198
199else:
200    print 'No wave specified in project script (Bf or Tb)'
201   
202
203#-------------------------------------------------------------------------------
204# Evolve system through time
205#-------------------------------------------------------------------------------
206
207t0 = time.time()
208for t in domain.evolve(yieldstep=project.yieldstep, 
209                       finaltime=project.finaltime,
210                       skip_initial_step=False): 
211    print domain.timestepping_statistics()
212    print domain.boundary_statistics(tags='ocean')
213
214print 'Simulation took %.2f seconds' % (time.time()-t0)
Note: See TracBrowser for help on using the repository browser.