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

Last change on this file since 6225 was 6225, checked in by ole, 16 years ago

Work on Patong w buildings

File size: 7.3 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                    alpha=project.alpha,                   
121                    use_cache=True,
122                    verbose=True)
123
124
125# Add buildings from file
126print 'Reading building polygons'   
127building_polygons, building_heights = csv2building_polygons(project.building_polygon_file)
128                                                            #clipping_polygons=project.building_area_polygons)
129
130print 'Creating %d building polygons' % len(building_polygons)
131def create_polygon_function(building_polygons, geo_reference=None):
132    L = []
133    for i, key in enumerate(building_polygons):
134        if i%100==0: print i
135        poly = building_polygons[key]
136        elev = building_heights[key]
137        L.append((poly, elev))
138
139        buildings = Polygon_function(L, default=0.0,
140                                     geo_reference=geo_reference)
141    return buildings
142
143buildings = cache(create_polygon_function,
144                  building_polygons,
145                  {'geo_reference': domain.geo_reference},
146                  verbose=True)
147
148print 'Adding buildings'
149domain.add_quantity('elevation',
150                    buildings,
151                    use_cache=False, # FIXME(OLE): This seems to pickup the stage IC??
152                    verbose=True)
153
154
155
156#------------------------------------------------------
157# Distribute domain to implement parallelism !!!
158#------------------------------------------------------
159
160#  if numprocs > 1:
161#      domain=distribute(domain)
162
163#------------------------------------------------------
164# Set domain parameters
165#------------------------------------------------------
166domain.set_name(project.scenario_name)
167domain.set_datadir(output_dir)
168domain.set_default_order(2)                 # Apply second order scheme
169domain.set_minimum_storable_height(0.01)    # Don't store anything less than 1cm
170
171#-------------------------------------------------------------------------
172# Setup boundary conditions
173#-------------------------------------------------------------------------
174print 'Set boundary conditions'
175
176Br = Reflective_boundary(domain)
177Bd = Dirichlet_boundary([project.tide,0,0])
178Bf = Field_boundary(urs_boundary_name+'.sts', 
179                    domain,
180                    mean_stage= project.tide,
181                    time_thinning=project.time_thinning,
182                    default_boundary=Bd,
183                    use_cache=True,
184                    verbose=True,
185                    boundary_polygon=bounding_polygon)
186
187domain.set_boundary({'back': Br,
188                     'side': Bd,
189                     'ocean': Bf}) 
190
191
192#----------------------------------------------------------------------------
193# Evolve system through time
194#--------------------------------------------------------------------
195t0 = time.time()
196
197for t in domain.evolve(yieldstep=project.yieldstep,
198                       finaltime=project.finaltime):
199    print domain.timestepping_statistics()
200    print domain.boundary_statistics(tags='ocean')
201   
202print 'Simulation took %.2f seconds' %(time.time()-t0)
203     
204   
Note: See TracBrowser for help on using the repository browser.