1 | """Script for running tsunami inundation scenario for Karratha, 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.outputtimedir |
---|
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 | # FIXME - parallel library not yet ready (16/10/2006) |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | # Import necessary modules |
---|
19 | #------------------------------------------------------------------------------ |
---|
20 | |
---|
21 | # Standard modules |
---|
22 | from os import sep |
---|
23 | from os.path import dirname, basename |
---|
24 | from os import mkdir, access, F_OK |
---|
25 | from shutil import copy |
---|
26 | import time |
---|
27 | import sys |
---|
28 | |
---|
29 | |
---|
30 | # Related major packages |
---|
31 | from anuga.shallow_water import Domain |
---|
32 | from anuga.shallow_water import Dirichlet_boundary |
---|
33 | from anuga.shallow_water import File_boundary |
---|
34 | from anuga.shallow_water import Reflective_boundary |
---|
35 | |
---|
36 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
37 | |
---|
38 | from anuga.geospatial_data.geospatial_data import * |
---|
39 | |
---|
40 | # Application specific imports |
---|
41 | import project # Definition of file names and polygons |
---|
42 | |
---|
43 | from anuga_parallel.parallel_api import distribute, myid, numprocs |
---|
44 | |
---|
45 | #------------------------------------------------------------------------------ |
---|
46 | # Copy scripts to time stamped output directory and capture screen |
---|
47 | # output to file |
---|
48 | #------------------------------------------------------------------------------ |
---|
49 | |
---|
50 | # filenames |
---|
51 | meshname = project.meshname+'.msh' |
---|
52 | source_dir = project.boundarydir |
---|
53 | |
---|
54 | if myid == 0: |
---|
55 | # creates copy of code in output dir if dir doesn't exist |
---|
56 | if access(project.outputtimedir,F_OK) == 0: |
---|
57 | mkdir (project.outputtimedir) |
---|
58 | copy (dirname(project.__file__) +sep+ project.__name__+'.py', |
---|
59 | project.outputtimedir + project.__name__+'.py') |
---|
60 | copy (__file__, project.outputtimedir + basename(__file__)) |
---|
61 | print 'project.outputtimedir',project.outputtimedir |
---|
62 | |
---|
63 | |
---|
64 | #-------------------------------------------------------------------------- |
---|
65 | # Create the triangular mesh based on overall clipping polygon with a |
---|
66 | # tagged |
---|
67 | # boundary and interior regions defined in project.py along with |
---|
68 | # resolutions (maximal area of per triangle) for each polygon |
---|
69 | #-------------------------------------------------------------------------- |
---|
70 | |
---|
71 | |
---|
72 | print 'start create mesh from regions' |
---|
73 | from caching import cache |
---|
74 | meshname = project.meshname + '_%d.msh' %myid |
---|
75 | _ = cache(create_mesh_from_regions, |
---|
76 | project.bounding_polygon, |
---|
77 | {'boundary_tags': {'back': [7, 8], 'side': [0, 6], |
---|
78 | 'ocean': [1, 2, 3, 4, 5]}, |
---|
79 | 'maximum_triangle_area': 200000, |
---|
80 | 'filename': meshname}, |
---|
81 | verbose = True, |
---|
82 | evaluate = False) |
---|
83 | |
---|
84 | #------------------------------------------------------------------------- |
---|
85 | # Setup computational domain |
---|
86 | #------------------------------------------------------------------------- |
---|
87 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
88 | print domain.statistics() |
---|
89 | domain.set_name(project.basename) |
---|
90 | domain.set_datadir(project.outputtimedir) |
---|
91 | |
---|
92 | |
---|
93 | #------------------------------------------------------------------------- |
---|
94 | # Setup initial conditions |
---|
95 | #------------------------------------------------------------------------- |
---|
96 | tide = 0. |
---|
97 | domain.set_quantity('stage', tide) |
---|
98 | domain.set_quantity('friction', 0.0) |
---|
99 | domain.set_quantity('elevation', |
---|
100 | filename = project.datadir + project.basename + '.pts', |
---|
101 | use_cache = False, |
---|
102 | verbose = True, |
---|
103 | alpha = 0.1) |
---|
104 | |
---|
105 | #------------------------------------------------------------------------- |
---|
106 | # Setup boundary conditions |
---|
107 | #------------------------------------------------------------------------- |
---|
108 | |
---|
109 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
110 | #Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
111 | # domain, verbose = True) |
---|
112 | Br = Reflective_boundary(domain) |
---|
113 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
114 | domain.set_boundary({'back': Br, |
---|
115 | 'side': Bd, |
---|
116 | 'ocean': None}) # Bind this one later |
---|
117 | else: |
---|
118 | domain = None |
---|
119 | |
---|
120 | |
---|
121 | #-------------------------------------------------------------------------- |
---|
122 | # Create the parallel domain |
---|
123 | #-------------------------------------------------------------------------- |
---|
124 | if numprocs > 1: |
---|
125 | domain = distribute(domain, verbose=True) |
---|
126 | |
---|
127 | # Set those boundaries that can't be communicated automatically |
---|
128 | # FIXME: There is a problem with the parallel domain. |
---|
129 | # It seems that boundaries are outside coverage. |
---|
130 | # |
---|
131 | # We get |
---|
132 | # |
---|
133 | #------------------------------------------------ |
---|
134 | #Interpolation_function (spatio-temporal) statistics: |
---|
135 | # Extent: |
---|
136 | # x in [-60494.651593, 149593.652382], len(x) == 56 |
---|
137 | # y in [-74198.017534, 184623.446077], len(y) == 56 |
---|
138 | # t in [0.000000, 28610.000000], len(t) == 145 |
---|
139 | # Quantities: |
---|
140 | # stage in [-1.797799, 1.644574] |
---|
141 | # xmomentum in [-33.219473, 21.571094] |
---|
142 | # ymomentum in [-32.775090, 73.761256] |
---|
143 | # Interpolation points (xi, eta): number of points == 411 |
---|
144 | # xi in [-420467.297166, -368252.119852] |
---|
145 | # eta in [-7652664.149808, -7605199.504709] |
---|
146 | # Interpolated quantities (over all timesteps): |
---|
147 | # stage at interpolation points in [inf, inf] |
---|
148 | # xmomentum at interpolation points in [inf, inf] |
---|
149 | # ymomentum at interpolation points in [inf, inf] |
---|
150 | #------------------------------------------------ |
---|
151 | # |
---|
152 | #Instead of |
---|
153 | # |
---|
154 | #------------------------------------------------ |
---|
155 | #Interpolation_function (spatio-temporal) statistics: |
---|
156 | # Extent: |
---|
157 | # x in [-60494.651593, 149593.652382], len(x) == 56 |
---|
158 | # y in [-74198.017534, 184623.446077], len(y) == 56 |
---|
159 | # t in [0.000000, 28610.000000], len(t) == 145 |
---|
160 | # Quantities: |
---|
161 | # stage in [-1.797799, 1.644574] |
---|
162 | # xmomentum in [-33.219473, 21.571094] |
---|
163 | # ymomentum in [-32.775090, 73.761256] |
---|
164 | # Interpolation points (xi, eta): number of points == 503 |
---|
165 | # xi in [4747.280215, 96909.729282] |
---|
166 | # eta in [9240.613414, 83183.465791] |
---|
167 | # Interpolated quantities (over all timesteps): |
---|
168 | # stage at interpolation points in [-0.909515, 1.331521] |
---|
169 | # xmomentum at interpolation points in [-17.054914, 17.110528] |
---|
170 | # ymomentum at interpolation points in [-24.691402, 16.625063] |
---|
171 | #------------------------------------------------ |
---|
172 | |
---|
173 | |
---|
174 | Bf = File_boundary(source_dir + project.boundary_basename + '.sww', |
---|
175 | domain, verbose = True) |
---|
176 | domain.set_boundary({'ocean': Bf}) |
---|
177 | |
---|
178 | |
---|
179 | #---------------------------------------------------------------------------- |
---|
180 | # Evolve system through time |
---|
181 | #---------------------------------------------------------------------------- |
---|
182 | import time |
---|
183 | t0 = time.time() |
---|
184 | |
---|
185 | for t in domain.evolve(yieldstep = 60, finaltime = 28600): |
---|
186 | domain.write_time() |
---|
187 | domain.write_boundary_statistics(tags = 'ocean') |
---|
188 | |
---|
189 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
190 | |
---|