1 | """Script for running a tsunami inundation scenario for Boca do Rio. |
---|
2 | Adopted from cairns files |
---|
3 | |
---|
4 | Joaquim Luis, 2007 |
---|
5 | """ |
---|
6 | |
---|
7 | #------------------------------------------------------------------------------ |
---|
8 | # Import necessary modules |
---|
9 | #------------------------------------------------------------------------------ |
---|
10 | |
---|
11 | # Standard modules |
---|
12 | import os |
---|
13 | import time |
---|
14 | import sys |
---|
15 | |
---|
16 | # Related major packages |
---|
17 | from anuga.shallow_water import Domain |
---|
18 | from anuga.shallow_water import Transmissive_boundary |
---|
19 | from anuga.shallow_water import Reflective_boundary |
---|
20 | from anuga.shallow_water import Dirichlet_boundary |
---|
21 | from anuga.shallow_water import Time_boundary |
---|
22 | from anuga.shallow_water import File_boundary |
---|
23 | from anuga.shallow_water import Field_boundary |
---|
24 | |
---|
25 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
26 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf |
---|
27 | from anuga.shallow_water.data_manager import dem2pts |
---|
28 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
29 | from anuga.abstract_2d_finite_volumes.util import file_function |
---|
30 | |
---|
31 | |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | # Define scenario as either ... |
---|
34 | #------------------------------------------------------------------------------ |
---|
35 | scenario = 'br' |
---|
36 | basename = scenario + 'source' |
---|
37 | |
---|
38 | #------------------------------------------------------------------------------ |
---|
39 | # Preparation of topographic data |
---|
40 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
41 | #------------------------------------------------------------------------------ |
---|
42 | |
---|
43 | # Filenames |
---|
44 | dem_name = 'sub_region_bat' |
---|
45 | meshname = 'sub_region.msh' |
---|
46 | |
---|
47 | # Create DEM from asc data |
---|
48 | convert_dem_from_ascii2netcdf(dem_name, use_cache=False, verbose=True) |
---|
49 | |
---|
50 | # Create pts file for onshore DEM |
---|
51 | dem2pts(dem_name, use_cache=False, verbose=True) |
---|
52 | |
---|
53 | from anuga.utilities.polygon import read_polygon, plot_polygons, \ |
---|
54 | polygon_area, is_inside_polygon |
---|
55 | |
---|
56 | ############################### |
---|
57 | # Domain definitions |
---|
58 | ############################### |
---|
59 | |
---|
60 | # bounding polygon for study area |
---|
61 | bounding_polygon = read_polygon('out_rect.csv') |
---|
62 | |
---|
63 | print 'Area of bounding polygon in km?', polygon_area(bounding_polygon)/1000000.0 |
---|
64 | |
---|
65 | ############################### |
---|
66 | # Interior region definitions |
---|
67 | ############################### |
---|
68 | |
---|
69 | # interior polygons |
---|
70 | poly_shallow = read_polygon('shallow.csv') |
---|
71 | |
---|
72 | #------------------------------------------------------------------------------ |
---|
73 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
74 | # boundary and interior regions defined in project.py along with |
---|
75 | # resolutions (maximal area of per triangle) for each polygon |
---|
76 | #------------------------------------------------------------------------------ |
---|
77 | |
---|
78 | remainder_res = 2500 |
---|
79 | shallow_res = 250 |
---|
80 | interior_regions = [[bounding_polygon, remainder_res], [poly_shallow, shallow_res]] |
---|
81 | |
---|
82 | create_mesh_from_regions(bounding_polygon, |
---|
83 | boundary_tags={'west': [0], |
---|
84 | 'south': [1], |
---|
85 | 'east': [2], |
---|
86 | 'north': [3]}, |
---|
87 | maximum_triangle_area=remainder_res, |
---|
88 | filename=meshname, |
---|
89 | interior_regions=interior_regions, |
---|
90 | use_cache=False, |
---|
91 | verbose=True) |
---|
92 | |
---|
93 | #------------------------------------------------------------------------------ |
---|
94 | # Setup computational domain |
---|
95 | #------------------------------------------------------------------------------ |
---|
96 | |
---|
97 | domain = Domain(meshname, use_cache=False, verbose=True) |
---|
98 | |
---|
99 | print 'Number of triangles = ', len(domain) |
---|
100 | print 'The extent is ', domain.get_extent() |
---|
101 | print domain.statistics() |
---|
102 | |
---|
103 | domain.set_name(basename) |
---|
104 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
105 | domain.set_minimum_storable_height(0.01) |
---|
106 | |
---|
107 | #------------------------------------------------------------------------------ |
---|
108 | # Setup initial conditions |
---|
109 | #------------------------------------------------------------------------------ |
---|
110 | |
---|
111 | tide = 0.0 |
---|
112 | domain.set_quantity('stage', tide) |
---|
113 | domain.set_quantity('friction', 0.025) |
---|
114 | domain.set_quantity('elevation', |
---|
115 | filename=dem_name + '.pts', |
---|
116 | use_cache=False, |
---|
117 | verbose=True, |
---|
118 | alpha=0.1) |
---|
119 | |
---|
120 | #------------------------------------------------------------------------------ |
---|
121 | # Setup boundary conditions |
---|
122 | #------------------------------------------------------------------------------ |
---|
123 | |
---|
124 | # Create boundary function from timeseries provided in file |
---|
125 | #function1 = file_function('mareg.tms', domain, verbose=True) |
---|
126 | |
---|
127 | # Create and assign boundary objects |
---|
128 | #Bts1 = Transmissive_Momentum_Set_Stage_boundary(domain, function1) |
---|
129 | |
---|
130 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
131 | #Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
132 | Br = Reflective_boundary(domain) |
---|
133 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
134 | Bf = Field_boundary('br_swan.sww', |
---|
135 | domain, time_thinning=1, mean_stage=tide, |
---|
136 | use_cache=False, verbose=True) |
---|
137 | |
---|
138 | #Boundary condition for sww feed at the east boundary |
---|
139 | domain.set_boundary({'west': Br,'south':Bf,'east': Br,'north': Br}) |
---|
140 | |
---|
141 | #------------------------------------------------------------------------------ |
---|
142 | # Evolve system through time |
---|
143 | #------------------------------------------------------------------------------ |
---|
144 | |
---|
145 | import time |
---|
146 | t0 = time.time() |
---|
147 | |
---|
148 | from Numeric import allclose |
---|
149 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
150 | |
---|
151 | |
---|
152 | # save every 1sec leading up to wave approaching land |
---|
153 | for t in domain.evolve(yieldstep = 1, finaltime = 960): |
---|
154 | domain.write_time() |
---|
155 | domain.write_boundary_statistics(tags = 'east') |
---|
156 | |
---|
157 | print 'That took %.2f seconds' %(time.time()-t0) |
---|