1 | """Script for running a tsunami inundation scenario for Flagstaff pt, |
---|
2 | Wollongong harbour, NSW, Australia. |
---|
3 | |
---|
4 | Source data such as elevation and boundary data is assumed to be available in |
---|
5 | directories specified by project.py |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a hypothetical boundary condition. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005, Nick Bartzis and Jane Sexton, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | |
---|
14 | #------------------------------------------------------------------------------ |
---|
15 | # Import necessary modules |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | |
---|
18 | |
---|
19 | # Standard modules |
---|
20 | import os, sys, time |
---|
21 | from os import sep |
---|
22 | from os.path import dirname, basename |
---|
23 | |
---|
24 | # Related major packages |
---|
25 | from pyvolution.shallow_water import Domain |
---|
26 | from pyvolution.shallow_water import Dirichlet_boundary |
---|
27 | from pyvolution.shallow_water import Time_boundary |
---|
28 | from pyvolution.shallow_water import Reflective_boundary |
---|
29 | from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
30 | from pmesh.mesh_interface import create_mesh_from_regions |
---|
31 | from pmesh.mesh import importUngenerateFile, Segment |
---|
32 | |
---|
33 | # Application specific imports |
---|
34 | import project |
---|
35 | |
---|
36 | |
---|
37 | #------------------------------------------------------------------------------ |
---|
38 | # Preparation of topographic data |
---|
39 | # |
---|
40 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
41 | #------------------------------------------------------------------------------ |
---|
42 | |
---|
43 | # Create DEM from asc data |
---|
44 | convert_dem_from_ascii2netcdf(project.demname, use_cache=True, verbose=True) |
---|
45 | |
---|
46 | # Create pts file from DEM |
---|
47 | dem2pts(project.demname, |
---|
48 | easting_min=project.xllcorner, |
---|
49 | easting_max=project.xurcorner, |
---|
50 | northing_min=project.yllcorner, |
---|
51 | northing_max= project.yurcorner, |
---|
52 | use_cache=True, |
---|
53 | verbose=True) |
---|
54 | |
---|
55 | |
---|
56 | #------------------------------------------------------------------------------ |
---|
57 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
58 | # boundary and interior regions defined in project.py along with |
---|
59 | # resolutions (maximal area of per triangle) for each polygon |
---|
60 | #------------------------------------------------------------------------------ |
---|
61 | |
---|
62 | # Generate basic mesh |
---|
63 | mesh = create_mesh_from_regions(project.bounding_polygon, |
---|
64 | boundary_tags=project.boundary_tags, |
---|
65 | maximum_triangle_area=project.base_resolution, |
---|
66 | interior_regions=project.interior_regions) |
---|
67 | |
---|
68 | # Add buildings |
---|
69 | dict = importUngenerateFile(project.buildings_filename) |
---|
70 | Segment.set_default_tag('wall') # This should bind to a Reflective boundary |
---|
71 | mesh.addVertsSegs(dict) |
---|
72 | |
---|
73 | # Generate and write mesh to file |
---|
74 | mesh.generate_mesh(maximum_triangle_area=project.base_resolution, |
---|
75 | verbose=True) |
---|
76 | |
---|
77 | mesh.export_mesh_file(project.mesh_filename) |
---|
78 | |
---|
79 | |
---|
80 | #------------------------------------------------------------------------------ |
---|
81 | # Setup computational domain |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | |
---|
84 | domain = Domain(project.mesh_filename, use_cache = False, verbose = True) |
---|
85 | print domain.statistics() |
---|
86 | |
---|
87 | domain.set_name(project.basename) |
---|
88 | domain.set_datadir(project.outputdir) |
---|
89 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
90 | |
---|
91 | |
---|
92 | #------------------------------------------------------------------------------ |
---|
93 | # Setup initial conditions |
---|
94 | #------------------------------------------------------------------------------ |
---|
95 | |
---|
96 | domain.set_quantity('stage', project.initial_sealevel) |
---|
97 | domain.set_quantity('friction', 0.03) |
---|
98 | domain.set_quantity('elevation', |
---|
99 | filename=project.demname + '.pts', |
---|
100 | use_cache=True, |
---|
101 | verbose=True) |
---|
102 | |
---|
103 | |
---|
104 | #------------------------------------------------------------------------------ |
---|
105 | # Setup boundary conditions |
---|
106 | #------------------------------------------------------------------------------ |
---|
107 | |
---|
108 | D = Dirichlet_boundary([project.initial_sealevel, 0, 0]) |
---|
109 | R = Reflective_boundary(domain) |
---|
110 | W = Time_boundary(domain = domain, |
---|
111 | f=lambda t: [project.initial_sealevel + (60<t<480)*6, 0, 0]) |
---|
112 | |
---|
113 | domain.set_boundary({'exterior': D, |
---|
114 | 'side': D, |
---|
115 | 'wall': R, |
---|
116 | 'ocean': W}) |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | #------------------------------------------------------------------------------ |
---|
121 | # Evolve system through time |
---|
122 | #------------------------------------------------------------------------------ |
---|
123 | |
---|
124 | t0 = time.time() |
---|
125 | for t in domain.evolve(yieldstep = 1, finaltime = 1200): |
---|
126 | domain.write_time() |
---|
127 | domain.write_boundary_statistics(tags = 'ocean') |
---|
128 | |
---|
129 | print 'That took %.2f seconds' %(time.time()-t0) |
---|