source: branches/numpy_anuga_validation/automated_validation_tests/patong_beach_validation/run_model.py @ 6832

Last change on this file since 6832 was 6832, checked in by rwilson, 15 years ago

Most recent changes to SVN - moving to Linux box.

File size: 8.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 create_sts_boundary
38from anuga.interface import csv2building_polygons
39from anuga.lib.file_length.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
45from anuga.caching import cache
46
47import anuga.utilities.log as log
48
49# Application specific imports
50from setup_model import project
51import build_urs_boundary as bub
52
53#-------------------------------------------------------------------------------
54# Copy scripts to time stamped output directory and capture screen
55# output to file. Copy script must be before screen_catcher
56#-------------------------------------------------------------------------------
57
58copy_code_files(project.output_run, __file__, 
59                os.path.join(os.path.dirname(project.__file__),
60                             project.__name__+'.py'))
61start_screen_catcher(project.output_run, 0, 1)
62
63#-------------------------------------------------------------------------------
64# Create the computational domain based on overall clipping polygon with
65# a tagged boundary and interior regions defined in project.py along with
66# resolutions (maximal area of per triangle) for each polygon
67#-------------------------------------------------------------------------------
68
69log.critical('Create computational domain')
70
71# Create the STS file
72log.critical( 'project.mux_data_folder=%s' % project.mux_data_folder)
73if not os.path.exists(project.event_sts + '.sts'):
74    bub.build_urs_boundary(project.mux_input_filename, project.event_sts)
75
76# Read in boundary from ordered sts file
77event_sts = create_sts_boundary(project.event_sts)
78
79# Reading the landward defined points, this incorporates the original clipping
80# polygon minus the 100m contour
81landward_boundary = read_polygon(project.landward_boundary)
82
83# Combine sts polyline with landward points
84bounding_polygon_sts = event_sts + landward_boundary
85
86# Number of boundary segments
87num_ocean_segments = len(event_sts) - 1
88# Number of landward_boundary points
89num_land_points = file_length(project.landward_boundary)
90
91# Boundary tags refer to project.landward_boundary
92# 4 points equals 5 segments start at N
93boundary_tags={'back': range(num_ocean_segments+1,
94                             num_ocean_segments+num_land_points),
95               'side': [num_ocean_segments,
96                        num_ocean_segments+num_land_points],
97               'ocean': range(num_ocean_segments)}
98
99# Build mesh and domain
100domain = create_domain_from_regions(bounding_polygon_sts,
101                                    boundary_tags=boundary_tags,
102                                    maximum_triangle_area=project.bounding_maxarea,
103                                    interior_regions=project.interior_regions,
104                                    mesh_filename=project.meshes,
105                                    use_cache=True,
106                                    verbose=True)
107log.critical(domain.statistics())
108
109# FIXME(Ole): How can we make this more automatic?
110domain.geo_reference.zone = project.zone
111
112
113domain.set_name(project.scenario_name)
114domain.set_datadir(project.output_run) 
115domain.set_minimum_storable_height(0.01)    # Don't store depth less than 1cm
116
117#-------------------------------------------------------------------------------
118# Setup initial conditions
119#-------------------------------------------------------------------------------
120
121log.critical('Setup initial conditions')
122
123# Set the initial stage in the offcoast region only
124if project.land_initial_conditions:
125    IC = Polygon_function(project.land_initial_conditions,
126                          default=project.tide,
127                          geo_reference=domain.geo_reference)
128else:
129    IC = 0
130domain.set_quantity('stage', IC, use_cache=True, verbose=True)
131domain.set_quantity('friction', project.friction) 
132domain.set_quantity('elevation', 
133                    filename=project.combined_elevation+'.pts',
134                    use_cache=True,
135                    verbose=True,
136                    alpha=project.alpha)
137
138if project.use_buildings:
139    # Add buildings from file
140    log.critical('Reading building polygons'    )
141    building_polygons, building_heights = csv2building_polygons(project.building_polygon)
142    #clipping_polygons=project.building_area_polygons)
143
144    log.critical('Creating %d building polygons' % len(building_polygons))
145    def create_polygon_function(building_polygons, geo_reference=None):
146        L = []
147        for i, key in enumerate(building_polygons):
148            if i%100==0: log.critical(i)
149            poly = building_polygons[key]
150            elev = building_heights[key]
151            L.append((poly, elev))
152           
153            buildings = Polygon_function(L, default=0.0,
154                                         geo_reference=geo_reference)
155        return buildings
156
157    buildings = cache(create_polygon_function,
158                      building_polygons,
159                      {'geo_reference': domain.geo_reference},
160                      verbose=True)
161
162    log.critical('Adding buildings')
163    domain.add_quantity('elevation',
164                        buildings,
165                        use_cache=True,
166                        verbose=True)
167
168
169#-------------------------------------------------------------------------------
170# Setup boundary conditions
171#-------------------------------------------------------------------------------
172
173log.critical('Set boundary - available tags:', domain.get_boundary_tags())
174
175Br = Reflective_boundary(domain)
176Bs = Transmissive_stage_zero_momentum_boundary(domain)
177#Bs = Dirichlet_boundary([project.tide, 0, 0])
178Bf = Field_boundary(project.event_sts+'.sts',
179                    domain,
180                    mean_stage=project.tide,
181                    time_thinning=1,
182                    default_boundary=Dirichlet_boundary([0, 0, 0]),
183                    boundary_polygon=bounding_polygon_sts,                   
184                    use_cache=True,
185                    verbose=True)
186
187domain.set_boundary({'back': Br,
188                     'side': Bs,
189                     'ocean': Bf}) 
190
191#-------------------------------------------------------------------------------
192# Evolve system through time
193#-------------------------------------------------------------------------------
194
195t0 = time.time()
196
197# Skip over the first 6000 seconds
198for t in domain.evolve(yieldstep=2000,
199                       finaltime=6000):
200    log.critical(domain.timestepping_statistics())
201    log.critical(domain.boundary_statistics(tags='ocean'))
202
203# Start detailed model
204for t in domain.evolve(yieldstep=project.yieldstep,
205                       finaltime=project.finaltime,
206                       skip_initial_step=True):
207    log.critical(domain.timestepping_statistics())
208    log.critical(domain.boundary_statistics(tags='ocean'))
209   
210log.critical('Simulation took %.2f seconds' %(time.time()-t0))
211     
Note: See TracBrowser for help on using the repository browser.