source: trunk/anuga_validation/automated_validation_tests/patong_beach_validation/run_model.py @ 7877

Last change on this file since 7877 was 7877, checked in by hudson, 14 years ago

Moved all development files into trunk.

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