1 | """Script for running tsunami inundation scenario for Dampier, WA, Australia. |
---|
2 | |
---|
3 | Source data such as elevation and boundary data is assumed to be available in |
---|
4 | directories specified by project.py |
---|
5 | The output sww file is stored in project.output_run_time_dir |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a simulated submarine landslide. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | # Import necessary modules |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | |
---|
17 | # Standard modules |
---|
18 | from os import sep |
---|
19 | from os.path import dirname, basename |
---|
20 | from os import mkdir, access, F_OK |
---|
21 | from shutil import copy |
---|
22 | import time |
---|
23 | import sys |
---|
24 | |
---|
25 | |
---|
26 | # Related major packages |
---|
27 | from anuga.shallow_water import Domain |
---|
28 | from anuga.shallow_water import Dirichlet_boundary |
---|
29 | from anuga.shallow_water import File_boundary |
---|
30 | from anuga.shallow_water import Reflective_boundary |
---|
31 | |
---|
32 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
33 | |
---|
34 | from anuga.geospatial_data.geospatial_data import * |
---|
35 | from anuga.abstract_2d_finite_volumes.util import Screen_Catcher |
---|
36 | |
---|
37 | # Application specific imports |
---|
38 | import project # Definition of file names and polygons |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | #------------------------------------------------------------------------------ |
---|
43 | # Copy scripts to time stamped output directory and capture screen |
---|
44 | # output to file |
---|
45 | #------------------------------------------------------------------------------ |
---|
46 | |
---|
47 | # filenames |
---|
48 | |
---|
49 | build_time = '20061025_113524_build' |
---|
50 | boundaries_name = project.boundaries_name |
---|
51 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
52 | #source_dir = project.boundarydir |
---|
53 | boundaries_time_dir_name = project.boundaries_dir + build_time + sep + boundaries_name |
---|
54 | |
---|
55 | #from anuga.shallow_water.data_manager import urs2sww |
---|
56 | |
---|
57 | # creates copy of code in output dir if dir doesn't exist |
---|
58 | if access(project.output_run_time_dir,F_OK) == 0: |
---|
59 | print 'project.output_run_time_dir',dirname(project.output_run_time_dir) |
---|
60 | mkdir (project.output_run_time_dir,0777) |
---|
61 | copy (dirname(project.__file__) +sep+ project.__name__+'.py', |
---|
62 | project.output_run_time_dir + project.__name__+'.py') |
---|
63 | copy (__file__, project.output_run_time_dir + basename(__file__)) |
---|
64 | print 'project.output_run_time_dir',project.output_run_time_dir |
---|
65 | |
---|
66 | #normal screen output is stored in |
---|
67 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
68 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
69 | |
---|
70 | #used to catch screen output to file |
---|
71 | sys.stdout = Screen_Catcher(screen_output_name) |
---|
72 | sys.stderr = Screen_Catcher(screen_error_name) |
---|
73 | |
---|
74 | print 'USER: ', project.user |
---|
75 | |
---|
76 | #-------------------------------------------------------------------------- |
---|
77 | # Create the triangular mesh based on overall clipping polygon with a |
---|
78 | # tagged |
---|
79 | # boundary and interior regions defined in project.py along with |
---|
80 | # resolutions (maximal area of per triangle) for each polygon |
---|
81 | #-------------------------------------------------------------------------- |
---|
82 | |
---|
83 | interior_regions = [#[project.karratha_polygon, 25000], |
---|
84 | #[project.dampier_polygon, 2000], |
---|
85 | #[project.refinery_polygon, 2000], |
---|
86 | #[project.point_polygon, 2000]] |
---|
87 | #[project.cipma_polygon, 20000]] |
---|
88 | [project.cipma_polygon, 50000]] # Caused memory error? |
---|
89 | |
---|
90 | #--------------------------- |
---|
91 | # this is check that no interior polygon is outside the bounding poly |
---|
92 | #------------------------------ |
---|
93 | |
---|
94 | """ |
---|
95 | count = 0 |
---|
96 | for i in range(len(interior_regions)): |
---|
97 | region = interior_regions[i] |
---|
98 | interior_polygon = region[0] |
---|
99 | if len(inside_polygon(interior_polygon, bounding_polygon, |
---|
100 | closed = True, verbose = False)) <> len(interior_polygon): |
---|
101 | print 'WARNING: interior polygon %d is outside bounding polygon' %(i) |
---|
102 | count += 1 |
---|
103 | |
---|
104 | if count == 0: |
---|
105 | print 'interior regions OK' |
---|
106 | else: |
---|
107 | print 'check out your interior polygons' |
---|
108 | print 'check %s in production directory' %figname |
---|
109 | import sys; sys.exit() |
---|
110 | """ |
---|
111 | #------------------------------------- |
---|
112 | |
---|
113 | print 'start create mesh from regions' |
---|
114 | meshes_dir_name = project.meshes_dir_name + '.msh' |
---|
115 | create_mesh_from_regions(project.bounding_polygon, |
---|
116 | boundary_tags={'back': [7, 8], 'side': [0, 6], |
---|
117 | 'ocean': [1, 2, 3, 4, 5]}, |
---|
118 | maximum_triangle_area=300000, |
---|
119 | interior_regions=interior_regions, |
---|
120 | filename=meshes_dir_name, |
---|
121 | use_cache=True, |
---|
122 | verbose=True) |
---|
123 | |
---|
124 | #------------------------------------------------------------------------- |
---|
125 | # Setup computational domain |
---|
126 | #------------------------------------------------------------------------- |
---|
127 | print 'Setup computational domain' |
---|
128 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
129 | print domain.statistics() |
---|
130 | domain.set_name(project.scenario_name) |
---|
131 | domain.set_datadir(project.output_run_time_dir) |
---|
132 | domain.set_default_order(2) |
---|
133 | domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | #------------------------------------------------------------------------- |
---|
138 | # Setup initial conditions |
---|
139 | #------------------------------------------------------------------------- |
---|
140 | tide = 2.4 |
---|
141 | domain.set_quantity('stage', tide) |
---|
142 | domain.set_quantity('friction', 0.0) |
---|
143 | #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name |
---|
144 | domain.set_quantity('elevation', |
---|
145 | filename = project.topographies_dir + build_time + sep + project.combined_name + '.pts', |
---|
146 | use_cache = True, |
---|
147 | verbose = True, |
---|
148 | alpha = 0.1) |
---|
149 | |
---|
150 | |
---|
151 | #------------------------------------------------------------------------- |
---|
152 | # Setup boundary conditions |
---|
153 | #------------------------------------------------------------------------- |
---|
154 | |
---|
155 | |
---|
156 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
157 | |
---|
158 | |
---|
159 | Bf = File_boundary(boundaries_time_dir_name + '.sww', |
---|
160 | domain, verbose = True) |
---|
161 | #Bf = File_boundary(source_dir + project.boundary_scenario_name + '.sww', |
---|
162 | # domain, verbose = True) |
---|
163 | Br = Reflective_boundary(domain) |
---|
164 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
165 | domain.set_boundary({'back': Br, |
---|
166 | 'side': Bd, |
---|
167 | 'ocean': Bf}) |
---|
168 | |
---|
169 | #---------------------------------------------------------------------------- |
---|
170 | # Evolve system through time |
---|
171 | #---------------------------------------------------------------------------- |
---|
172 | import time |
---|
173 | t0 = time.time() |
---|
174 | |
---|
175 | for t in domain.evolve(yieldstep = 120, finaltime = 28800): |
---|
176 | domain.write_time() |
---|
177 | domain.write_boundary_statistics(tags = 'ocean') |
---|
178 | |
---|
179 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
180 | |
---|