1 | """Script for running a hypothetical inundation scenario for Gold Coast, |
---|
2 | QLD, Australia. |
---|
3 | |
---|
4 | Source data such as elevation and boundary data is assumed to be available in |
---|
5 | directories specified by project.py |
---|
6 | The output sww file is stored in project.outputtimedir |
---|
7 | |
---|
8 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
9 | the elevation data and a tsunami wave generated by s submarine mass failure. |
---|
10 | |
---|
11 | Ole Nielsen and Duncan Gray, GA - 2005 and Nick Bartzis, GA - 2006 |
---|
12 | """ |
---|
13 | |
---|
14 | #------------------------------------------------------------------------------- |
---|
15 | # Import necessary modules |
---|
16 | #------------------------------------------------------------------------------- |
---|
17 | |
---|
18 | # Standard modules |
---|
19 | import os |
---|
20 | import time |
---|
21 | from shutil import copy |
---|
22 | from os.path import dirname, basename |
---|
23 | from os import mkdir, access, F_OK, sep |
---|
24 | import sys |
---|
25 | |
---|
26 | # Related major packages |
---|
27 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary, Time_boundary |
---|
28 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
29 | from anuga.geospatial_data.geospatial_data import * |
---|
30 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
31 | |
---|
32 | # Application specific imports |
---|
33 | import project # Definition of file names and polygons |
---|
34 | |
---|
35 | #------------------------------------------------------------------------------- |
---|
36 | # Copy scripts to time stamped output directory and capture screen |
---|
37 | # output to file |
---|
38 | #------------------------------------------------------------------------------- |
---|
39 | |
---|
40 | # creates copy of code in output dir |
---|
41 | copy_code_files(project.outputtimedir,__file__,dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
42 | myid = 0 |
---|
43 | numprocs = 1 |
---|
44 | start_screen_catcher(project.outputtimedir, myid, numprocs) |
---|
45 | |
---|
46 | print 'USER: ', project.user |
---|
47 | |
---|
48 | #------------------------------------------------------------------------------- |
---|
49 | # Preparation of topographic data |
---|
50 | # |
---|
51 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
52 | #------------------------------------------------------------------------------- |
---|
53 | |
---|
54 | # filenames |
---|
55 | gc_dem_name = project.gc_dem_name |
---|
56 | meshname = project.meshname+'.msh' |
---|
57 | |
---|
58 | # creates DEM from asc data |
---|
59 | convert_dem_from_ascii2netcdf(gc_dem_name, use_cache=True, verbose=True) |
---|
60 | |
---|
61 | #creates pts file for onshore DEM |
---|
62 | dem2pts(gc_dem_name, use_cache=True, verbose=True) |
---|
63 | |
---|
64 | G = Geospatial_data(file_name = project.gc_dem_name + '.pts') |
---|
65 | |
---|
66 | G.export_points_file(project.combined_dem_name + '.pts') |
---|
67 | |
---|
68 | |
---|
69 | #---------------------------------------------------------------------------- |
---|
70 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
71 | # boundary and interior regions defined in project.py along with |
---|
72 | # resolutions (maximal area of per triangle) for each polygon |
---|
73 | #------------------------------------------------------------------------------- |
---|
74 | |
---|
75 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
76 | remainder_res = 150000. |
---|
77 | int_res = 1000. |
---|
78 | interior_regions = [[project.poly_int, int_res]] |
---|
79 | |
---|
80 | from caching import cache |
---|
81 | _ = cache(create_mesh_from_regions, |
---|
82 | project.polyAll, |
---|
83 | {'boundary_tags': {'e0': [0], 'e1': [1], 'e2': [2], 'e3': [3]}, |
---|
84 | 'maximum_triangle_area': remainder_res, |
---|
85 | 'filename': meshname, |
---|
86 | 'interior_regions': interior_regions}, |
---|
87 | verbose = True, evaluate=False) |
---|
88 | |
---|
89 | #------------------------------------------------------------------------------- |
---|
90 | # Setup computational domain |
---|
91 | #------------------------------------------------------------------------------- |
---|
92 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
93 | |
---|
94 | print 'Number of triangles = ', len(domain) |
---|
95 | print 'The extent is ', domain.get_extent() |
---|
96 | print domain.statistics() |
---|
97 | |
---|
98 | domain.set_name(project.basename) |
---|
99 | domain.set_datadir(project.outputtimedir) |
---|
100 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
101 | domain.set_minimum_storable_height(0.01) |
---|
102 | |
---|
103 | #------------------------------------------------------------------------------- |
---|
104 | # Setup initial conditions |
---|
105 | #------------------------------------------------------------------------------- |
---|
106 | |
---|
107 | tide = 0.0 |
---|
108 | domain.set_quantity('stage', tide) |
---|
109 | domain.set_quantity('friction', 0.0) |
---|
110 | domain.set_quantity('elevation', |
---|
111 | filename = project.combined_dem_name + '.pts', |
---|
112 | use_cache = True, |
---|
113 | verbose = True, |
---|
114 | alpha = 0.1 |
---|
115 | ) |
---|
116 | |
---|
117 | #------------------------------------------------------------------------------- |
---|
118 | # Setup boundary conditions |
---|
119 | #------------------------------------------------------------------------------- |
---|
120 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
121 | |
---|
122 | Br = Reflective_boundary(domain) |
---|
123 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
124 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
125 | f=lambda t: [(60<t<660)*6., 0, 0]) |
---|
126 | |
---|
127 | domain.set_boundary( {'e0': Bw, 'e1': Bd, 'e2': Bd, 'e3': Bd} ) |
---|
128 | |
---|
129 | |
---|
130 | #------------------------------------------------------------------------------- |
---|
131 | # Evolve system through time |
---|
132 | #------------------------------------------------------------------------------- |
---|
133 | import time |
---|
134 | |
---|
135 | t0 = time.time() |
---|
136 | |
---|
137 | for t in domain.evolve(yieldstep = 10, finaltime = 5000): |
---|
138 | domain.write_time() |
---|
139 | domain.write_boundary_statistics(tags = 'e0') |
---|
140 | |
---|
141 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
142 | |
---|
143 | print 'finished' |
---|