source: anuga_work/production/hobart_2009/For_DVD/run_model.py @ 7324

Last change on this file since 7324 was 7324, checked in by kristy, 14 years ago

Updating script to look better!

File size: 6.5 KB
Line 
1"""Run a tsunami inundation scenario.
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) - found in project.event_folder
8       pts file (build_elevation.py) - found in project.boundaries_folder
9       information from project file
10Outputs: sww file stored in project.output_run
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
16Ole Nielsen, Jane Sexton, Ross Wilson and Kristy Van Putten - 2009
17"""
18
19#------------------------------------------------------------------------------
20# Import necessary modules
21#------------------------------------------------------------------------------
22
23# Standard modules
24import os
25import os.path
26import time
27from time import localtime, strftime, gmtime
28
29# Related major packages
30from Scientific.IO.NetCDF import NetCDFFile
31import Numeric as num
32
33from anuga.interface import create_domain_from_regions
34from anuga.interface import Transmissive_stage_zero_momentum_boundary
35from anuga.interface import Dirichlet_boundary
36from anuga.interface import Reflective_boundary
37from anuga.interface import Field_boundary
38from anuga.interface import create_sts_boundary
39from anuga.interface import csv2building_polygons
40from file_length import file_length
41
42from anuga.shallow_water.data_manager import start_screen_catcher
43from anuga.shallow_water.data_manager import copy_code_files
44from anuga.shallow_water.data_manager import urs2sts
45from anuga.utilities.polygon import read_polygon, Polygon_function
46
47# Application specific imports
48from setup_model import project
49import build_urs_boundary as bub
50
51#-------------------------------------------------------------------------------
52# Copy scripts to time stamped output directory and capture screen
53# output to file. Copy script must be before screen_catcher
54#-------------------------------------------------------------------------------
55
56copy_code_files(project.output_run, __file__, 
57                os.path.join(os.path.dirname(project.__file__),
58                             project.__name__+'.py'))
59start_screen_catcher(project.output_run, 0, 1)
60
61#-------------------------------------------------------------------------------
62# Create the computational domain based on overall clipping polygon with
63# a tagged boundary and interior regions defined in project.py along with
64# resolutions (maximal area of per triangle) for each polygon
65#-------------------------------------------------------------------------------
66
67print 'Create computational domain'
68
69# Create the STS file
70if not os.path.exists(project.event_sts + '.sts'):
71    print 'sts file has not been generated'
72
73# Read in boundary from ordered sts file
74event_sts = create_sts_boundary(project.event_sts)
75
76# Reading the landward defined points, this incorporates the original clipping
77# polygon minus the 100m contour
78landward_boundary = read_polygon(project.landward_boundary)
79
80# Combine sts polyline with landward points
81bounding_polygon_sts = event_sts + landward_boundary
82
83# Number of boundary segments
84num_ocean_segments = len(event_sts) - 1
85# Number of landward_boundary points
86num_land_points = file_length(project.landward_boundary)
87
88# Boundary tags refer to project.landward_boundary
89# 4 points equals 5 segments start at N
90boundary_tags={'back': range(num_ocean_segments+1,
91                             num_ocean_segments+num_land_points),
92               'side': [num_ocean_segments,
93                        num_ocean_segments+num_land_points],
94               'ocean': range(num_ocean_segments)}
95
96# Build mesh and domain
97domain = create_domain_from_regions(bounding_polygon_sts,
98                                    boundary_tags=boundary_tags,
99                                    maximum_triangle_area=project.bounding_maxarea,
100                                    interior_regions=project.interior_regions,
101                                    mesh_filename=project.meshes,
102                                    use_cache=True,
103                                    verbose=True)
104print domain.statistics()
105
106domain.set_name(project.scenario_name)
107domain.set_datadir(project.output_run) 
108domain.set_minimum_storable_height(0.01)    # Don't store depth less than 1cm
109
110#-------------------------------------------------------------------------------
111# Setup initial conditions
112#-------------------------------------------------------------------------------
113
114print 'Setup initial conditions'
115
116# Set the initial stage in the offcoast region only
117if project.land_initial_conditions:
118    IC = Polygon_function(project.land_initial_conditions,
119                          default=project.tide,
120                          geo_reference=domain.geo_reference)
121else:
122    IC = 0
123domain.set_quantity('stage', IC, use_cache=True, verbose=True)
124domain.set_quantity('friction', project.friction) 
125domain.set_quantity('elevation', 
126                    filename=project.combined_elevation+'.pts',
127                    use_cache=True,
128                    verbose=True,
129                    alpha=project.alpha)
130
131#-------------------------------------------------------------------------------
132# Setup boundary conditions
133#-------------------------------------------------------------------------------
134
135print 'Set boundary - available tags:', domain.get_boundary_tags()
136
137Br = Reflective_boundary(domain)
138Bt = Transmissive_stage_zero_momentum_boundary(domain)
139Bf = Field_boundary(project.event_sts+'.sts',
140                    domain, mean_stage=project.tide,
141                    time_thinning=1,
142                    default_boundary=Dirichlet_boundary([0, 0, 0]),
143                    boundary_polygon=bounding_polygon_sts,                   
144                    use_cache=True,
145                    verbose=True)
146
147domain.set_boundary({'back': Br,
148                     'side': Bt,
149                     'ocean': Bf}) 
150
151#-------------------------------------------------------------------------------
152# Evolve system through time
153#-------------------------------------------------------------------------------
154
155t0 = time.time()
156for t in domain.evolve(yieldstep=project.yieldstep, 
157                       finaltime=project.finaltime,
158                       skip_initial_step=False): 
159    print domain.timestepping_statistics()
160    print domain.boundary_statistics(tags='ocean')
161
162print 'Simulation took %.2f seconds' % (time.time()-t0)
Note: See TracBrowser for help on using the repository browser.