source: anuga_work/production/australia_ph2/LHI/run_model.py @ 6486

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

scripts for Lord Howe Island model. run_model.py has been edited as there is no landward boundary

File size: 7.2 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 + '.sts'):
75    bub.build_urs_boundary(project.mux_input_filename, project.event_sts)
76
77# Read in boundary from ordered sts file
78event_sts = create_sts_boundary(project.event_sts)
79
80# Reading the landward defined points, this incorporates the original clipping
81# polygon minus the 100m contour
82
83# NO LANDWARD BOUNDARY FOR ISLAND MODEL
84##landward_boundary = read_polygon(project.landward_boundary)
85
86# Combine sts polyline with landward points
87bounding_polygon_sts = event_sts #+ landward_boundary
88
89# Number of boundary segments
90num_ocean_segments = len(event_sts) - 1
91# Number of landward_boundary points
92num_land_points = 0 #file_length(project.landward_boundary)
93
94# Boundary tags refer to project.landward_boundary
95# 4 points equals 5 segments start at N
96boundary_tags={'back': range(num_ocean_segments+1,
97                             num_ocean_segments+num_land_points),
98               'side': [num_ocean_segments,
99                        num_ocean_segments+num_land_points],
100               'ocean': range(num_ocean_segments)}
101
102# Build mesh and domain
103domain = create_domain_from_regions(bounding_polygon_sts,
104                                    boundary_tags=boundary_tags,
105                                    maximum_triangle_area=project.bounding_maxarea,
106                                    interior_regions=project.interior_regions,
107                                    mesh_filename=project.meshes,
108                                    use_cache=True,
109                                    verbose=True)
110print domain.statistics()
111
112domain.set_name(project.scenario_name)
113domain.set_datadir(project.output_run) 
114domain.set_minimum_storable_height(0.01)    # Don't store depth less than 1cm
115
116#-------------------------------------------------------------------------------
117# Setup initial conditions
118#-------------------------------------------------------------------------------
119
120print 'Setup initial conditions'
121
122# Set the initial stage in the offcoast region only
123if project.land_initial_conditions:
124    IC = Polygon_function(project.land_initial_conditions,
125                          default=project.tide,
126                          geo_reference=domain.geo_reference)
127else:
128    IC = 0
129domain.set_quantity('stage', IC, use_cache=True, verbose=True)
130domain.set_quantity('friction', project.friction) 
131domain.set_quantity('elevation', 
132                    filename=project.combined_elevation+'.pts',
133                    use_cache=True,
134                    verbose=True,
135                    alpha=project.alpha)
136
137#-------------------------------------------------------------------------------
138# Setup boundary conditions
139#-------------------------------------------------------------------------------
140
141print 'Set boundary - available tags:', domain.get_boundary_tags()
142
143# Prepare time boundary
144TB.prepare_timeboundary(project.boundary_csv)
145f = file_function(project.boundary_csv[:-4] + '.tms')
146
147Br = Reflective_boundary(domain)
148Bt = Transmissive_stage_zero_momentum_boundary(domain)
149Bd = Dirichlet_boundary([project.tide, 0, 0])
150
151if project.wave == 'Bf':
152    Bf = Field_boundary(project.event_sts+'.sts',
153                        domain, mean_stage=project.tide,
154                        time_thinning=1,
155                        default_boundary=Bd,
156                        boundary_polygon=bounding_polygon_sts,                   
157                        use_cache=True,
158                        verbose=True)
159    domain.set_boundary({'back': Br,
160                     'side': Bd,
161                     'ocean': Bf}) 
162   
163elif project.wave == 'Tb':
164    Tb = Time_boundary(domain,f,default_boundary=Bd,
165                       verbose=True)
166
167    domain.set_boundary({'back': Br,
168                         'side': Bd,
169                         'ocean': Tb})
170else:
171    print 'No wave specified in project script (Bf or Tb)'
172   
173
174#-------------------------------------------------------------------------------
175# Evolve system through time
176#-------------------------------------------------------------------------------
177
178t0 = time.time()
179for t in domain.evolve(yieldstep=project.yieldstep, 
180                       finaltime=project.finaltime,
181                       skip_initial_step=False): 
182    print domain.timestepping_statistics()
183    print domain.boundary_statistics(tags='ocean')
184
185print 'Simulation took %.2f seconds' % (time.time()-t0)
Note: See TracBrowser for help on using the repository browser.