source: anuga_work/production/patong/run_patong.py @ 6219

Last change on this file since 6219 was 6219, checked in by ole, 15 years ago

Work on Patong - finer resolution at community and more cleanup.

File size: 7.0 KB
Line 
1"""Script for running a tsunami inundation scenario for Patong Beach, Thailand.
2
3The scenario is defined by a triangular mesh created from project.polygon,
4the elevation data is compiled into a pts file through build_patong.py
5and a simulated tsunami for the 2004 event is generated through
6an sts file from build_boundary.py.
7
8Input: sts file (build_boundary.py)
9       pts file (build_patong.py)
10       information from project file
11Outputs: sww file stored in project.output_run_time_dir
12The export_results_all.py and get_timeseries.py is reliant
13on the outputs of this script
14
15"""
16
17#------------------------------------------------------------------------------
18# Import necessary modules
19#------------------------------------------------------------------------------
20
21# Standard modules
22from os import sep
23import os
24from os.path import dirname
25import time
26
27# Related major packages
28from anuga.interface import create_domain_from_regions
29from anuga.interface import Dirichlet_boundary
30from anuga.interface import Reflective_boundary
31from anuga.interface import Field_boundary
32from anuga.interface import create_sts_boundary
33from anuga.interface import csv2building_polygons
34
35from anuga.caching import cache
36from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters
37from anuga.utilities.polygon import read_polygon
38from polygon import Polygon_function
39   
40# Application specific imports
41import project  # Definition of file names and polygons
42numprocs = 1
43myid = 0
44
45
46   
47#------------------------------------------------------------------------------
48# Copy scripts to time stamped output directory and capture screen
49# output to file
50#------------------------------------------------------------------------------
51
52#copy script must be before screen_catcher
53
54output_dir = project.output_run_time_dir
55print 'output_dir', output_dir
56
57copy_code_files(output_dir,__file__, 
58                dirname(project.__file__)+sep+ project.__name__+'.py' )
59
60start_screen_catcher(output_dir, myid, numprocs)
61
62
63#-----------------------------------------------------------------------
64# Domain definitions
65#-----------------------------------------------------------------------
66
67# Read in boundary from ordered sts file
68urs_boundary_name = os.path.join(project.boundaries_dir,
69                                 project.scenario_name)
70urs_bounding_polygon = create_sts_boundary(urs_boundary_name)
71
72# Reading the landward defined points, this incorporates the original clipping
73# polygon minus the 100m contour
74landward_bounding_polygon = read_polygon(project.landward_dir)
75
76# Combine sts polyline with landward points
77bounding_polygon = urs_bounding_polygon + landward_bounding_polygon
78
79# Counting segments
80N = len(urs_bounding_polygon)-1
81
82# boundary tags refer to project.landward 4 points equals 5 segments start at N
83boundary_tags={'back': [N+1,N+2,N+3], 'side': [N,N+4], 'ocean': range(N)}
84
85#--------------------------------------------------------------------------
86# Create the computational domain based on overall clipping polygon with
87# a tagged boundary and interior regions defined in project.py along with
88# resolutions (maximal area of per triangle) for each polygon
89#--------------------------------------------------------------------------
90
91domain = create_domain_from_regions(bounding_polygon,
92                                    boundary_tags=boundary_tags,
93                                    maximum_triangle_area=project.res_poly_all,
94                                    interior_regions=project.interior_regions,
95                                    mesh_filename=project.meshes_dir_name,
96                                    use_cache=True,
97                                    verbose=True)
98
99print domain.statistics()
100
101
102#-------------------------------------------------------------------------
103# Setup initial conditions
104#-------------------------------------------------------------------------
105print 'Setup initial conditions'
106
107# sets the initial stage in the offcoast region only
108IC = Polygon_function([(project.poly_mainland, 0)],
109                      default=project.tide,
110                      geo_reference=domain.geo_reference)
111print 'stage'
112domain.set_quantity('stage', IC,
113                    use_cache=True,
114                    verbose=True)
115print 'friction'
116domain.set_quantity('friction', project.friction)
117print 'elevation'
118domain.set_quantity('elevation', 
119                    filename=project.combined_dir_name+'.pts',
120                    use_cache=True,
121                    verbose=True,
122                    alpha=project.alpha)
123
124# Add buildings from file
125print 'Reading building polygons'   
126building_polygons, building_heights = csv2building_polygons(project.building_polygon_file)
127
128print 'Creating %d building polygons' % len(building_polygons)
129def create_polygon_function(building_polygons):
130    L = []
131    for i, key in enumerate(building_polygons):
132        if i%100==0: print i
133        poly = building_polygons[key]
134        elev = building_heights[key]
135        L.append((poly, elev))#
136
137        buildings = Polygon_function(L, default=0.0,
138                                     geo_reference=domain.geo_reference)
139    return buildings
140
141buildings = cache(create_polygon_function,
142                  building_polygons,
143                  verbose=True)
144
145print 'Add buildings'
146domain.add_quantity('elevation', buildings)
147
148
149#------------------------------------------------------
150# Distribute domain to implement parallelism !!!
151#------------------------------------------------------
152
153#  if numprocs > 1:
154#      domain=distribute(domain)
155
156#------------------------------------------------------
157# Set domain parameters
158#------------------------------------------------------
159domain.set_name(project.scenario_name)
160domain.set_datadir(output_dir)
161domain.set_default_order(2)                 # Apply second order scheme
162domain.set_minimum_storable_height(0.01)    # Don't store anything less than 1cm
163
164#-------------------------------------------------------------------------
165# Setup boundary conditions
166#-------------------------------------------------------------------------
167print 'Set boundary conditions'
168
169Br = Reflective_boundary(domain)
170Bd = Dirichlet_boundary([project.tide,0,0])
171Bf = Field_boundary(urs_boundary_name+'.sts', 
172                    domain,
173                    mean_stage= project.tide,
174                    time_thinning=project.time_thinning,
175                    default_boundary=Bd,
176                    use_cache=True,
177                    verbose=True,
178                    boundary_polygon=bounding_polygon)
179
180domain.set_boundary({'back': Br,
181                     'side': Bd,
182                     'ocean': Bf}) 
183
184
185#----------------------------------------------------------------------------
186# Evolve system through time
187#--------------------------------------------------------------------
188t0 = time.time()
189
190for t in domain.evolve(yieldstep=project.yieldstep,
191                       finaltime=project.finaltime):
192    print domain.timestepping_statistics()
193    print domain.boundary_statistics(tags='ocean')
194   
195print 'Simulation took %.2f seconds' %(time.time()-t0)
196     
197   
Note: See TracBrowser for help on using the repository browser.