1 | """Script for running a tsunami inundation scenario for Cairns, QLD 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 directory named after the scenario, i.e |
---|
6 | slide or fixed_wave. |
---|
7 | |
---|
8 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
9 | the elevation data and a tsunami wave generated by a submarine mass failure. |
---|
10 | |
---|
11 | Geoscience Australia, 2004-present |
---|
12 | |
---|
13 | This has remained unchanged aside from the parallelism added, the resource statistics |
---|
14 | and the output directories, its also been scaled down so it runs faster(in project.py) |
---|
15 | """ |
---|
16 | |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | # Import necessary modules |
---|
19 | #------------------------------------------------------------------------------ |
---|
20 | # Standard modules |
---|
21 | import os |
---|
22 | import time |
---|
23 | import sys |
---|
24 | import anuga |
---|
25 | from anuga_parallel import distribute, myid, numprocs |
---|
26 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
27 | from anuga.utilities import log |
---|
28 | |
---|
29 | |
---|
30 | # Application specific imports |
---|
31 | import project # Definition of file names and polygons |
---|
32 | |
---|
33 | |
---|
34 | # set up variables for the correct output directories |
---|
35 | home = os.getenv('INUNDATIONHOME') |
---|
36 | scenariodirV = add_directories(home, ["data","mem_time_test", "parallel", |
---|
37 | "cairns", "parrallel-" + str(numprocs) +"-"+str(myid)]) |
---|
38 | scenariodir = add_directories(home, ["data","mem_time_test", "parallel", |
---|
39 | "cairns"]) |
---|
40 | |
---|
41 | h = 'CAIRNS.msh' |
---|
42 | file_pathh = os.path.join(scenariodirV, h) |
---|
43 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
44 | log._setup = False |
---|
45 | |
---|
46 | log.timingInfo(msg=('numberofcpus,'+str(numprocs))) #write the variable to be measured to file |
---|
47 | log.timingInfo(msg=('myid,'+str(myid))) #write the variable to be measured to file |
---|
48 | |
---|
49 | log.timingInfo(msg=('beforetime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
50 | |
---|
51 | log.resource_usage_timing(prefix = 'beforesimulation')#get memory statistics at this point |
---|
52 | #------------------------------------------------------------------------------ |
---|
53 | # Preparation of topographic data |
---|
54 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
55 | #------------------------------------------------------------------------------ |
---|
56 | # Create DEM from asc data |
---|
57 | anuga.asc2dem(os.path.join(scenariodir, 'cairns.asc'), use_cache=True, verbose=True) |
---|
58 | |
---|
59 | # Create pts file for onshore DEM |
---|
60 | anuga.dem2pts(os.path.join(scenariodir,'cairns.dem'), use_cache=True, verbose=True) |
---|
61 | |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | # Create the triangular mesh and domain based on |
---|
64 | # overall clipping polygon with a tagged |
---|
65 | # boundary and interior regions as defined in project.py |
---|
66 | # (in serial, so the set up only runs once) |
---|
67 | #------------------------------------------------------------------------------ |
---|
68 | if myid == 0: |
---|
69 | domain = anuga.create_domain_from_regions(project.bounding_polygon, |
---|
70 | boundary_tags={'top': [0], |
---|
71 | 'ocean_east': [1], |
---|
72 | 'bottom': [2], |
---|
73 | 'onshore': [3]}, |
---|
74 | maximum_triangle_area=project.default_res, |
---|
75 | mesh_filename=file_pathh, |
---|
76 | interior_regions=project.interior_regions, |
---|
77 | use_cache=True, |
---|
78 | verbose=True) |
---|
79 | |
---|
80 | # Print some stats about mesh and domain |
---|
81 | print 'Number of triangles = ', len(domain) |
---|
82 | print 'The extent is ', domain.get_extent() |
---|
83 | print domain.statistics() |
---|
84 | else: |
---|
85 | domain = None |
---|
86 | |
---|
87 | log.resource_usage_timing(prefix = 'aftermesh')#get memory statistics at this point |
---|
88 | log.timingInfo(msg=('aftermeshtime,'+str(log.TimeStamp()))) #get the time at the beginning of the simulation |
---|
89 | |
---|
90 | #parallel |
---|
91 | domain = distribute(domain) |
---|
92 | |
---|
93 | #------------------------------------------------------------------------------ |
---|
94 | # Setup parameters of computational domain |
---|
95 | #------------------------------------------------------------------------------ |
---|
96 | domain.set_name('cairns_' + project.scenario) # Name of sww file |
---|
97 | domain.set_datadir(scenariodirV) # Store sww output here |
---|
98 | domain.set_minimum_storable_height(0.01) # Store only depth > 1cm |
---|
99 | |
---|
100 | #------------------------------------------------------------------------------ |
---|
101 | # Setup initial conditions |
---|
102 | #------------------------------------------------------------------------------ |
---|
103 | |
---|
104 | tide = 0.0 |
---|
105 | domain.set_quantity('stage', tide) |
---|
106 | domain.set_quantity('friction', 0.0) |
---|
107 | domain.set_quantity('elevation', |
---|
108 | filename=os.path.join(scenariodir, 'cairns.pts'), |
---|
109 | use_cache=True, |
---|
110 | verbose=True, |
---|
111 | alpha=0.1) |
---|
112 | log.resource_usage_timing(prefix='afterinitialconditions') #get memory statistics at this point |
---|
113 | |
---|
114 | #------------------------------------------------------------------------------ |
---|
115 | # Setup information for slide scenario (to be applied 1 min into simulation |
---|
116 | #------------------------------------------------------------------------------ |
---|
117 | if project.scenario == 'slide': |
---|
118 | # Function for submarine slide |
---|
119 | tsunami_source = anuga.slide_tsunami(length=35000.0, |
---|
120 | depth=project.slide_depth, |
---|
121 | slope=6.0, |
---|
122 | thickness=500.0, |
---|
123 | x0=project.slide_origin[0], |
---|
124 | y0=project.slide_origin[1], |
---|
125 | alpha=0.0, |
---|
126 | domain=domain, |
---|
127 | verbose=True) |
---|
128 | |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | # Setup boundary conditions |
---|
131 | #------------------------------------------------------------------------------ |
---|
132 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
133 | |
---|
134 | Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level |
---|
135 | Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary |
---|
136 | |
---|
137 | if project.scenario == 'fixed_wave': |
---|
138 | # Huge 50m wave starting after 60 seconds and lasting 1 hour. |
---|
139 | Bw = anuga.Time_boundary(domain=domain, |
---|
140 | function=lambda t: [(60<t<3660)*50, 0, 0]) |
---|
141 | domain.set_boundary({'ocean_east': Bw, |
---|
142 | 'bottom': Bs, |
---|
143 | 'onshore': Bd, |
---|
144 | 'top': Bs}) |
---|
145 | |
---|
146 | if project.scenario == 'slide': |
---|
147 | # Boundary conditions for slide scenario |
---|
148 | domain.set_boundary({'ocean_east': Bd, |
---|
149 | 'bottom': Bd, |
---|
150 | 'onshore': Bd, |
---|
151 | 'top': Bd}) |
---|
152 | log.resource_usage_timing(prefix='afterboundary') #get memory statistics at this point |
---|
153 | #------------------------------------------------------------------------------ |
---|
154 | # Evolve system through time |
---|
155 | #------------------------------------------------------------------------------ |
---|
156 | import time |
---|
157 | t0 = time.time() |
---|
158 | |
---|
159 | from numpy import allclose |
---|
160 | |
---|
161 | if project.scenario == 'slide': |
---|
162 | # Initial run without any event |
---|
163 | for t in domain.evolve(yieldstep=2000, finaltime=2000): |
---|
164 | print domain.timestepping_statistics() |
---|
165 | print domain.boundary_statistics(tags='ocean_east') |
---|
166 | |
---|
167 | # Add slide to water surface |
---|
168 | if allclose(t, 60): |
---|
169 | domain.add_quantity('stage', tsunami_source) |
---|
170 | |
---|
171 | # Continue propagating wave |
---|
172 | for t in domain.evolve(yieldstep=2000, finaltime=2000, |
---|
173 | skip_initial_step=True): |
---|
174 | print domain.timestepping_statistics() |
---|
175 | print domain.boundary_statistics(tags='ocean_east') |
---|
176 | |
---|
177 | if project.scenario == 'fixed_wave': |
---|
178 | # Save every two mins leading up to wave approaching land |
---|
179 | for t in domain.evolve(yieldstep=2000, finaltime=2000): |
---|
180 | print domain.timestepping_statistics() |
---|
181 | print domain.boundary_statistics(tags='ocean_east') |
---|
182 | |
---|
183 | # Save every 30 secs as wave starts inundating ashore |
---|
184 | for t in domain.evolve(yieldstep=2000, finaltime=2000, |
---|
185 | skip_initial_step=True): |
---|
186 | print domain.timestepping_statistics() |
---|
187 | print domain.boundary_statistics(tags='ocean_east') |
---|
188 | |
---|
189 | |
---|
190 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
191 | |
---|
192 | log.resource_usage_timing(prefix='aftersimulation') #get memory statistics at this point |
---|
193 | log.timingInfo(msg=('aftertime,'+str(log.TimeStamp()))) #get the time at the end of the simulation |
---|
194 | |
---|