source: DVD_images/extra_files/Gosford/project/run_model.py @ 7380

Last change on this file since 7380 was 7380, checked in by jgriffin, 15 years ago
  • Property svn:executable set to *
File size: 6.6 KB
Line 
1"""Run a tsunami inundation scenario for Gosford, NSW, 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 create_sts_boundary
38from anuga.interface import csv2building_polygons
39from file_length import file_length
40
41from anuga.shallow_water.data_manager import start_screen_catcher
42from anuga.shallow_water.data_manager import copy_code_files
43from anuga.shallow_water.data_manager import urs2sts
44from anuga.utilities.polygon import read_polygon, Polygon_function
45
46# Application specific imports
47from setup_model import project
48import build_urs_boundary as bub
49
50#-------------------------------------------------------------------------------
51# Copy scripts to time stamped output directory and capture screen
52# output to file. Copy script must be before screen_catcher
53#-------------------------------------------------------------------------------
54
55copy_code_files(project.output_run, __file__, 
56                os.path.join(os.path.dirname(project.__file__),
57                             project.__name__+'.py'))
58start_screen_catcher(project.output_run, 0, 1)
59
60#-------------------------------------------------------------------------------
61# Create the computational domain based on overall clipping polygon with
62# a tagged boundary and interior regions defined in project.py along with
63# resolutions (maximal area of per triangle) for each polygon
64#-------------------------------------------------------------------------------
65
66print 'Create computational domain'
67
68# Create the STS file
69if not os.path.exists(project.event_sts + '.sts'):
70    bub.build_urs_boundary(project.mux_input_filename, project.event_sts)
71
72# Read in boundary from ordered sts file
73event_sts = create_sts_boundary(project.event_sts)
74
75# Reading the landward defined points, this incorporates the original clipping
76# polygon minus the 100m contour
77landward_boundary = read_polygon(project.landward_boundary)
78
79# Combine sts polyline with landward points
80bounding_polygon_sts = event_sts + landward_boundary
81
82# Number of boundary segments
83num_ocean_segments = len(event_sts) - 1
84# Number of landward_boundary points
85num_land_points = file_length(project.landward_boundary)
86
87# Boundary tags refer to project.landward_boundary
88# 4 points equals 5 segments start at N
89boundary_tags={'back': range(num_ocean_segments+1,
90                             num_ocean_segments+num_land_points),
91               'side': [num_ocean_segments,
92                        num_ocean_segments+num_land_points],
93               'ocean': range(num_ocean_segments)}
94
95# Build mesh and domain
96domain = create_domain_from_regions(bounding_polygon_sts,
97                                    boundary_tags=boundary_tags,
98                                    maximum_triangle_area=project.bounding_maxarea,
99                                    interior_regions=project.interior_regions,
100                                    mesh_filename=project.meshes,
101                                    use_cache=False,
102                                    verbose=True)
103
104domain.geo_reference.zone = project.zone
105print domain.statistics()
106
107domain.set_name(project.scenario_name)
108domain.set_datadir(project.output_run) 
109domain.set_minimum_storable_height(0.01)    # Don't store depth less than 1cm
110
111#-------------------------------------------------------------------------------
112# Setup initial conditions
113#-------------------------------------------------------------------------------
114
115print 'Setup initial conditions'
116
117# Set the initial stage in the offcoast region only
118if project.land_initial_conditions:
119    IC = Polygon_function(project.land_initial_conditions,
120                          default=project.tide,
121                          geo_reference=domain.geo_reference)
122else:
123    IC = 0
124domain.set_quantity('stage', IC, use_cache=True, verbose=True)
125domain.set_quantity('friction', project.friction) 
126domain.set_quantity('elevation', 
127                    filename=project.combined_elevation+'.pts',
128                    use_cache=True,
129                    verbose=True,
130                    alpha=project.alpha)
131
132#-------------------------------------------------------------------------------
133# Setup boundary conditions
134#-------------------------------------------------------------------------------
135
136print 'Set boundary - available tags:', domain.get_boundary_tags()
137
138Br = Reflective_boundary(domain)
139Bt = Transmissive_stage_zero_momentum_boundary(domain)
140Bd = Dirichlet_boundary([project.tide, 0, 0])
141Bf = Field_boundary(project.event_sts+'.sts',
142                    domain, mean_stage=project.tide,
143                    time_thinning=1,
144                    default_boundary=Dirichlet_boundary([0, 0, 0]),
145                    boundary_polygon=bounding_polygon_sts,                   
146                    use_cache=True,
147                    verbose=True)
148
149
150domain.set_boundary({'back': Br,
151                     'side': Bt,
152                     'ocean': Bf}) 
153
154#-------------------------------------------------------------------------------
155# Evolve system through time
156#-------------------------------------------------------------------------------
157
158t0 = time.time()
159
160for t in domain.evolve(yieldstep=project.yieldstep, 
161                       finaltime=project.finaltime,
162                       skip_initial_step=False): 
163    print domain.timestepping_statistics()
164    print domain.boundary_statistics(tags='ocean')
165##    print domain.volumetric_balance_statistics()
166
167print 'Simulation took %.2f seconds' % (time.time()-t0)
Note: See TracBrowser for help on using the repository browser.