1 | """Script for running a tsunami inundation scenario for Southwest coast, |
---|
2 | Sri Lanka. |
---|
3 | |
---|
4 | Source data such as elevation and boundary data is assumed to be available in |
---|
5 | directories specified by project.py |
---|
6 | The output sww file is stored in directory named after the scenario, i.e |
---|
7 | slide or fixed_wave. |
---|
8 | |
---|
9 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
10 | the elevation data and a tsunami wave generated by a submarine mass failure. |
---|
11 | |
---|
12 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton and |
---|
13 | Nick Bartzis, GA - 2006 |
---|
14 | """ |
---|
15 | |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | # Import necessary modules |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | |
---|
20 | # Standard modules |
---|
21 | import os |
---|
22 | import time |
---|
23 | import sys |
---|
24 | from os.path import dirname, basename |
---|
25 | |
---|
26 | # Related major packages |
---|
27 | from anuga.shallow_water import Domain |
---|
28 | from anuga.shallow_water import Reflective_boundary |
---|
29 | from anuga.shallow_water import Dirichlet_boundary |
---|
30 | from anuga.shallow_water import Time_boundary |
---|
31 | from anuga.shallow_water import File_boundary |
---|
32 | from anuga.shallow_water import Field_boundary |
---|
33 | |
---|
34 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
35 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf |
---|
36 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
37 | from anuga.shallow_water.data_manager import dem2pts |
---|
38 | from anuga.geospatial_data.geospatial_data import * |
---|
39 | from os import sep |
---|
40 | from anuga.utilities.polygon import read_polygon, Polygon_function |
---|
41 | |
---|
42 | # Application specific imports |
---|
43 | import project # Definition of file names and polygons |
---|
44 | |
---|
45 | copy_code_files(project.output_run_time_dir,__file__, |
---|
46 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
47 | |
---|
48 | start_screen_catcher(project.output_run_time_dir) |
---|
49 | |
---|
50 | #------------------------------------------------------------------------------ |
---|
51 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
52 | # boundary and interior regions defined in project.py along with |
---|
53 | # resolutions (maximal area of per triangle) for each polygon |
---|
54 | #------------------------------------------------------------------------------ |
---|
55 | |
---|
56 | create_mesh_from_regions(project.bounding_polygon, |
---|
57 | boundary_tags={'back': [3,4,5,6], 'side': [0,2], |
---|
58 | 'ocean': [1]}, |
---|
59 | maximum_triangle_area=project.regional_res, |
---|
60 | filename=project.meshes_dir_name+'.msh', |
---|
61 | interior_regions=project.interior_regions, |
---|
62 | use_cache=False, |
---|
63 | verbose=True) |
---|
64 | |
---|
65 | |
---|
66 | #------------------------------------------------------------------------------ |
---|
67 | # Setup computational domain |
---|
68 | #------------------------------------------------------------------------------ |
---|
69 | |
---|
70 | domain = Domain(project.meshes_dir_name+'.msh', use_cache=False, verbose=True) |
---|
71 | |
---|
72 | print domain.statistics() |
---|
73 | |
---|
74 | domain.set_name(project.scenario_name) |
---|
75 | domain.set_datadir(project.output_run_time_dir) |
---|
76 | domain.set_default_order(2) # Apply second order scheme |
---|
77 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
78 | domain.set_store_vertices_uniquely(False) |
---|
79 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
80 | |
---|
81 | |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | # Setup initial conditions |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | |
---|
86 | |
---|
87 | IC = Polygon_function( [(project.poly_mainland, -1.0)], default = project.tide, |
---|
88 | geo_reference = domain.geo_reference) |
---|
89 | domain.set_quantity('stage', IC) |
---|
90 | domain.set_quantity('friction', 0.01) |
---|
91 | print'start set elevation quantity' |
---|
92 | domain.set_quantity('elevation', |
---|
93 | # filename=project.combined_dem_name + '.txt', |
---|
94 | filename=project.combined_canal_fort_dem_name + '.txt', |
---|
95 | # filename=project.combined_canal_dem_name + '.txt', |
---|
96 | # filename=project.combined_dem_name + '.pts', |
---|
97 | use_cache=True, |
---|
98 | verbose=True, |
---|
99 | alpha=0.1) |
---|
100 | print'finish set elevation quantity' |
---|
101 | #------------------------------------------------------------------------------ |
---|
102 | # Setup boundary conditions |
---|
103 | #------------------------------------------------------------------------------ |
---|
104 | |
---|
105 | #print 'Available boundary tags', domain.get_boundary_tags() |
---|
106 | |
---|
107 | Br = Reflective_boundary(domain) |
---|
108 | Bd = Dirichlet_boundary([project.tide,0,0]) |
---|
109 | |
---|
110 | Bf = Field_boundary(project.boundaries_dir_name+'.sww', |
---|
111 | domain, time_thinning=2, mean_stage=project.tide, |
---|
112 | use_cache=True, verbose=True) |
---|
113 | |
---|
114 | # 60 min square wave starting at 1 min, 50m high |
---|
115 | #if scenario == 'fixed_wave': |
---|
116 | |
---|
117 | Bw = Time_boundary(domain = domain, |
---|
118 | f=lambda t: [(60<t<300)*3, 0, 0]) |
---|
119 | |
---|
120 | domain.set_boundary({'back': Br, |
---|
121 | 'side': Bd, |
---|
122 | # 'ocean': Bw} |
---|
123 | 'ocean': Bf} |
---|
124 | ) |
---|
125 | |
---|
126 | |
---|
127 | #------------------------------------------------------------------------------ |
---|
128 | # Evolve system through time |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | |
---|
131 | t0 = time.time() |
---|
132 | |
---|
133 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
134 | |
---|
135 | for t in domain.evolve(yieldstep = 60, finaltime = 30000): |
---|
136 | domain.write_time() |
---|
137 | domain.write_boundary_statistics(tags = 'ocean') |
---|
138 | |
---|
139 | print 'That took %.2f seconds' %(time.time()-t0) |
---|