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 | THIS IS THE SEQUENTIAL VERSION |
---|
11 | |
---|
12 | Ole Nielsen and Duncan Gray, GA - 2005, Nick Bartzis and Jane Sexton, GA - 2006 |
---|
13 | """ |
---|
14 | |
---|
15 | |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | # Import necessary modules |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | |
---|
20 | |
---|
21 | # Standard modules |
---|
22 | import os, sys, time |
---|
23 | from os import sep |
---|
24 | from os.path import dirname, basename |
---|
25 | from Numeric import zeros, Float |
---|
26 | |
---|
27 | # Related major packages |
---|
28 | from anuga.pyvolution.shallow_water import Domain |
---|
29 | from anuga.pyvolution.shallow_water import Dirichlet_boundary |
---|
30 | from anuga.pyvolution.shallow_water import Time_boundary |
---|
31 | from anuga.pyvolution.shallow_water import Reflective_boundary |
---|
32 | from anuga.pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
33 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
34 | from anuga.pmesh.mesh import importUngenerateFile, Segment |
---|
35 | |
---|
36 | |
---|
37 | # Application specific imports |
---|
38 | import project |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | #-------------------------------------------------------------------------- |
---|
45 | # Create the triangular mesh based on overall clipping polygon with a |
---|
46 | # tagged boundary and interior regions defined in project.py along with |
---|
47 | # resolutions (maximal area of per triangle) for each polygon |
---|
48 | #-------------------------------------------------------------------------- |
---|
49 | |
---|
50 | |
---|
51 | print 'Generate mesh' |
---|
52 | max_area = project.base_resolution |
---|
53 | mesh = create_mesh_from_regions(project.bounding_polygon, |
---|
54 | boundary_tags=project.boundary_tags, |
---|
55 | maximum_triangle_area=max_area, |
---|
56 | interior_regions=project.interior_regions) |
---|
57 | |
---|
58 | # Add buildings |
---|
59 | # This should bind to a Reflective boundary |
---|
60 | mesh.import_ungenerate_file(project.buildings_filename, tag='wall') |
---|
61 | |
---|
62 | # Generate and write mesh to file |
---|
63 | mesh.generate_mesh(maximum_triangle_area=max_area, |
---|
64 | verbose=True) |
---|
65 | mesh.export_mesh_file(project.mesh_filename) |
---|
66 | |
---|
67 | |
---|
68 | #-------------------------------------------------------------------------- |
---|
69 | # Setup computational domain |
---|
70 | #-------------------------------------------------------------------------- |
---|
71 | |
---|
72 | domain = Domain(project.mesh_filename, use_cache = False, verbose = True) |
---|
73 | print domain.statistics() |
---|
74 | |
---|
75 | domain.set_name(project.basename) |
---|
76 | domain.set_datadir(project.outputdir) |
---|
77 | |
---|
78 | #------------------------------------------------------------------------------ |
---|
79 | # Setup initial conditions |
---|
80 | #------------------------------------------------------------------------------ |
---|
81 | |
---|
82 | domain.set_quantity('stage', project.initial_sealevel) |
---|
83 | domain.set_quantity('friction', 0.03) |
---|
84 | domain.set_quantity('elevation', |
---|
85 | filename=project.demname + '.pts', |
---|
86 | use_cache=True, |
---|
87 | verbose=True) |
---|
88 | |
---|
89 | #------------------------------------------------------------------------------ |
---|
90 | # Setup boundary conditions |
---|
91 | #------------------------------------------------------------------------------ |
---|
92 | |
---|
93 | D = Dirichlet_boundary([project.initial_sealevel, 0, 0]) |
---|
94 | R = Reflective_boundary(domain) |
---|
95 | W = Time_boundary(domain = domain, |
---|
96 | f=lambda t: [project.initial_sealevel + (60<t<480)*6, 0, 0]) |
---|
97 | |
---|
98 | domain.set_boundary({'exterior': D, |
---|
99 | 'side': D, |
---|
100 | 'wall': R, |
---|
101 | 'ocean': W, |
---|
102 | 'ghost': None}) |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | #------------------------------------------------------------------------------ |
---|
108 | # Evolve system through time |
---|
109 | #------------------------------------------------------------------------------ |
---|
110 | |
---|
111 | t0 = time.time() |
---|
112 | for t in domain.evolve(yieldstep = 1, finaltime = 1200): |
---|
113 | domain.write_time() |
---|
114 | |
---|
115 | |
---|
116 | print 'That took %.2f seconds' %(time.time()-t0) |
---|