-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenarioA.py
168 lines (144 loc) · 6.19 KB
/
scenarioA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""Simple for running tsunami inundation scenario in Purworejo, Indonesia, using ANUGA
Prepared by febri fahmi <febrifahmi.hakim@tum.de>, 2015, based on ANUGA examples scripts.
(c) Geoscience Australia
"""
#------------------------------------------------------------------------------
# Import necessary modules
#------------------------------------------------------------------------------
# standard module
import os
import time
import sys
# related important module
import anuga
# application specific import
import project # project.py consists of definition of file names and so on
time00 = time.time()
#------------------------------------------------------------------------------
# Preparation of topographic data
# Convert ASC 2 DEM 2 PTS using source data and store result in source data
#------------------------------------------------------------------------------
# unzip .asc file from zip file
import zipfile as zf
path_to_data_dir = 'C:/anuga/thesis/pwrj_initcond/'
if project.verbose: print 'Reading ASC from pwrjdem.zip'
zf.ZipFile(path_to_data_dir+project.name_stem+'.zip').extract(project.name_stem+'.asc')
zf.ZipFile(path_to_data_dir+project.name_stem+'.zip').extract(project.name_stem+'.prj')
# building DEM from ASC data
anuga.asc2dem(project.name_stem+'.asc', use_cache=project.cache, verbose=project.verbose)
# create PTS file from onshore DEM
anuga.dem2pts(project.name_stem+'.dem', use_cache=project.cache, verbose=project.verbose)
#------------------------------------------------------------------------------
# Create the triangular mesh and domain based on overall clipping
# polygons with a tagged boundary and interior regions as defined
# in project.py
#------------------------------------------------------------------------------
domain = anuga.create_domain_from_regions(project.bounding_polygon,
boundary_tags={'east': [0],
'bottom_ocean': [1],
'west': [2],
'onshore': [3]},
maximum_triangle_area=project.default_res,
mesh_filename=project.meshname,
interior_regions=project.interior_regions,
use_cache=project.cache,
verbose=project.verbose)
# Print some stats about mesh and domain
print 'Number of triangles = ', len(domain)
print 'The extent is ', domain.get_extent()
print domain.statistics()
#------------------------------------------------------------------------------
# Setup parameters of computational domain
#------------------------------------------------------------------------------
domain.set_name('pwrj_' + project.scenario) # Name of sww file
domain.set_datadir('.') # Store sww output here
domain.set_minimum_storable_height(0.01) # Store only depth > 1cm
domain.set_flow_algorithm('DE0')
#------------------------------------------------------------------------------
# Setup initial condition
#------------------------------------------------------------------------------
tide = project.tide
domain.set_quantity('stage', tide)
domain.set_quantity('friction', 0.0 )
domain.set_quantity('elevation',
filename=project.name_stem + '.pts',
use_cache=project.cache,
verbose=project.verbose,
alpha=0.1)
time01 = time.time()
print 'That took %.2f seconds to fit data' %(time01-time00)
if project.just_fitting:
import sys
sys.exit()
#------------------------------------------------------------------------------
# Setup information for slide scenario
#------------------------------------------------------------------------------
if project.scenario == 'slide':
# Function for submarine slide
tsunami_source = anuga.slide_tsunami(length=35000.0,
depth=project.slide_depth,
slope=6.0,
thickness=500.0,
x0=project.slide_origin[0],
y0=project.slide_origin[1],
alpha=0.0,
domain=domain,
verbose=project.verbose)
#------------------------------------------------------------------------------
# Setup boundary condition
#------------------------------------------------------------------------------
print 'Available boundary tags', domain.get_boundary_tags()
Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level
Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary
if project.scenario == 'fixed_wave':
# Huge 10.94m wave starting after 60 seconds and lasting 60 minutes.
Bw = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
domain=domain,
function=lambda t: [(60<t<3660)*10.94, 0, 0])
Bt = anuga.Time_boundary(
domain=domain,
function=lambda t: [(60<t<3660)*11, 0, 0],
default_boundary=None,
verbose=False)
domain.set_boundary({'bottom_ocean': Bd,
'west': Bs,
'onshore': Bw,
'east': Bs})
if project.scenario == 'slide':
# Boundary conditions for slide scenario
domain.set_boundary({'bottom_ocean': Bw,
'west': Bs,
'onshore': Bd,
'east': Bs})
#------------------------------------------------------------------------------
# Evolve system through time
#------------------------------------------------------------------------------
import time
t0 = time.time()
from numpy import allclose
# slide tsunami
if project.scenario == 'slide':
# Initial run without any event
for t in domain.evolve(yieldstep=10, finaltime=60):
print domain.timestepping_statistics()
print domain.boundary_statistics(tags='bottom_ocean')
# Add slide to water surface
if allclose(t, 60):
domain.add_quantity('stage', tsunami_source)
# Continue propagating wave
for t in domain.evolve(yieldstep=10, finaltime=5000,
skip_initial_step=True):
print domain.timestepping_statistics()
print domain.boundary_statistics(tags='bottom_ocean')
# fixed wave
if project.scenario == 'fixed_wave':
# Save every two mins leading up to wave approaching land
for t in domain.evolve(yieldstep=2*60, finaltime=5000):
print domain.timestepping_statistics()
print domain.boundary_statistics(tags='bottom_ocean')
# Save every 30 secs as wave starts inundating ashore
for t in domain.evolve(yieldstep=60*0.5, finaltime=10000,
skip_initial_step=True):
print domain.timestepping_statistics()
print domain.boundary_statistics(tags='bottom_ocean')
print 'That took %.2f seconds' %(time.time()-t0)