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 |
---|
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 | scenariodir = add_directories(home, ["data", "mem_time_test", "parallel", "cairns"]) |
---|
37 | h = 'CAIRNS.msh' |
---|
38 | file_pathh = os.path.join(scenariodir, h) |
---|
39 | store ='store.txt' |
---|
40 | file_path_store = os.path.join(scenariodir, store) |
---|
41 | scenariodirV = add_directories(home, ["data","mem_time_test", "parallel", |
---|
42 | "cairns", "parrallel-" + str(numprocs) +"-"+str(myid)]) |
---|
43 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
44 | log._setup = False |
---|
45 | |
---|
46 | |
---|
47 | log.resource_usage_timing(prefix = 'BeforeSimulation')#get memory statistics at this point |
---|
48 | #------------------------------------------------------------------------------ |
---|
49 | # Preparation of topographic data |
---|
50 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
51 | #------------------------------------------------------------------------------ |
---|
52 | # Create DEM from asc data |
---|
53 | anuga.asc2dem(os.path.join(scenariodir, 'cairns.asc'), use_cache=True, verbose=True) |
---|
54 | |
---|
55 | # Create pts file for onshore DEM |
---|
56 | anuga.dem2pts(os.path.join(scenariodir,'cairns.dem'), use_cache=True, verbose=True) |
---|
57 | |
---|
58 | #------------------------------------------------------------------------------ |
---|
59 | # Create the triangular mesh and domain based on |
---|
60 | # overall clipping polygon with a tagged |
---|
61 | # boundary and interior regions as defined in project.py |
---|
62 | # (in serial, so the set up only runs once) |
---|
63 | #------------------------------------------------------------------------------ |
---|
64 | if myid == 0: |
---|
65 | domain = anuga.create_domain_from_regions(project.bounding_polygon, |
---|
66 | boundary_tags={'top': [0], |
---|
67 | 'ocean_east': [1], |
---|
68 | 'bottom': [2], |
---|
69 | 'onshore': [3]}, |
---|
70 | maximum_triangle_area=project.default_res, |
---|
71 | mesh_filename=file_pathh, |
---|
72 | interior_regions=project.interior_regions, |
---|
73 | use_cache=True, |
---|
74 | verbose=True) |
---|
75 | |
---|
76 | # Print some stats about mesh and domain |
---|
77 | print 'Number of triangles = ', len(domain) |
---|
78 | print 'The extent is ', domain.get_extent() |
---|
79 | print domain.statistics() |
---|
80 | else: |
---|
81 | domain = None |
---|
82 | |
---|
83 | log.resource_usage_timing(prefix = 'AfterMesh')#get memory statistics at this point |
---|
84 | |
---|
85 | #parallel |
---|
86 | domain = distribute(domain) |
---|
87 | |
---|
88 | #------------------------------------------------------------------------------ |
---|
89 | # Setup parameters of computational domain |
---|
90 | #------------------------------------------------------------------------------ |
---|
91 | domain.set_name('cairns_' + project.scenario) # Name of sww file |
---|
92 | domain.set_datadir(scenariodirV) # Store sww output here |
---|
93 | domain.set_minimum_storable_height(0.01) # Store only depth > 1cm |
---|
94 | |
---|
95 | #------------------------------------------------------------------------------ |
---|
96 | # Setup initial conditions |
---|
97 | #------------------------------------------------------------------------------ |
---|
98 | |
---|
99 | tide = 0.0 |
---|
100 | domain.set_quantity('stage', tide) |
---|
101 | domain.set_quantity('friction', 0.0) |
---|
102 | domain.set_quantity('elevation', |
---|
103 | filename=os.path.join(scenariodir, 'cairns.pts'), |
---|
104 | use_cache=True, |
---|
105 | verbose=True, |
---|
106 | alpha=0.1) |
---|
107 | log.resource_usage_timing(prefix='afterinitialconditions') #get memory statistics at this point |
---|
108 | |
---|
109 | #------------------------------------------------------------------------------ |
---|
110 | # Setup information for slide scenario (to be applied 1 min into simulation |
---|
111 | #------------------------------------------------------------------------------ |
---|
112 | if project.scenario == 'slide': |
---|
113 | # Function for submarine slide |
---|
114 | tsunami_source = anuga.slide_tsunami(length=35000.0, |
---|
115 | depth=project.slide_depth, |
---|
116 | slope=6.0, |
---|
117 | thickness=500.0, |
---|
118 | x0=project.slide_origin[0], |
---|
119 | y0=project.slide_origin[1], |
---|
120 | alpha=0.0, |
---|
121 | domain=domain, |
---|
122 | verbose=True) |
---|
123 | |
---|
124 | #------------------------------------------------------------------------------ |
---|
125 | # Setup boundary conditions |
---|
126 | #------------------------------------------------------------------------------ |
---|
127 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
128 | |
---|
129 | Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level |
---|
130 | Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary |
---|
131 | |
---|
132 | if project.scenario == 'fixed_wave': |
---|
133 | # Huge 50m wave starting after 60 seconds and lasting 1 hour. |
---|
134 | Bw = anuga.Time_boundary(domain=domain, |
---|
135 | function=lambda t: [(60<t<3660)*50, 0, 0]) |
---|
136 | domain.set_boundary({'ocean_east': Bw, |
---|
137 | 'bottom': Bs, |
---|
138 | 'onshore': Bd, |
---|
139 | 'top': Bs}) |
---|
140 | |
---|
141 | if project.scenario == 'slide': |
---|
142 | # Boundary conditions for slide scenario |
---|
143 | domain.set_boundary({'ocean_east': Bd, |
---|
144 | 'bottom': Bd, |
---|
145 | 'onshore': Bd, |
---|
146 | 'top': Bd}) |
---|
147 | log.resource_usage_timing(prefix='afterboundary') #get memory statistics at this point |
---|
148 | #------------------------------------------------------------------------------ |
---|
149 | # Evolve system through time |
---|
150 | #------------------------------------------------------------------------------ |
---|
151 | import time |
---|
152 | t0 = time.time() |
---|
153 | |
---|
154 | from numpy import allclose |
---|
155 | |
---|
156 | if project.scenario == 'slide': |
---|
157 | # Initial run without any event |
---|
158 | for t in domain.evolve(yieldstep=10, finaltime=60): |
---|
159 | print domain.timestepping_statistics() |
---|
160 | print domain.boundary_statistics(tags='ocean_east') |
---|
161 | |
---|
162 | # Add slide to water surface |
---|
163 | if allclose(t, 60): |
---|
164 | domain.add_quantity('stage', tsunami_source) |
---|
165 | |
---|
166 | # Continue propagating wave |
---|
167 | for t in domain.evolve(yieldstep=10, finaltime=5000, |
---|
168 | skip_initial_step=True): |
---|
169 | print domain.timestepping_statistics() |
---|
170 | print domain.boundary_statistics(tags='ocean_east') |
---|
171 | |
---|
172 | if project.scenario == 'fixed_wave': |
---|
173 | # Save every two mins leading up to wave approaching land |
---|
174 | for t in domain.evolve(yieldstep=120, finaltime=2000): |
---|
175 | print domain.timestepping_statistics() |
---|
176 | print domain.boundary_statistics(tags='ocean_east') |
---|
177 | |
---|
178 | # Save every 30 secs as wave starts inundating ashore |
---|
179 | for t in domain.evolve(yieldstep=10, finaltime=100, |
---|
180 | skip_initial_step=True): |
---|
181 | print domain.timestepping_statistics() |
---|
182 | print domain.boundary_statistics(tags='ocean_east') |
---|
183 | |
---|
184 | |
---|
185 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
186 | |
---|
187 | log.resource_usage_timing(prefix='aftersimulation') #get memory statistics at this point |
---|