[4925] | 1 | """Script for running a tsunami inundation scenario for Boca do Rio. |
---|
| 2 | Adopted from cairns files |
---|
| 3 | |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | #------------------------------------------------------------------------------ |
---|
| 7 | # Import necessary modules |
---|
| 8 | #------------------------------------------------------------------------------ |
---|
| 9 | |
---|
| 10 | # Standard modules |
---|
| 11 | import os |
---|
| 12 | import time |
---|
| 13 | import sys |
---|
| 14 | |
---|
| 15 | # Related major packages |
---|
| 16 | from anuga.shallow_water import Domain |
---|
| 17 | from anuga.shallow_water import Transmissive_boundary |
---|
| 18 | from anuga.shallow_water import Reflective_boundary |
---|
| 19 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 20 | from anuga.shallow_water import Time_boundary |
---|
| 21 | from anuga.shallow_water import File_boundary |
---|
| 22 | from anuga.shallow_water import Field_boundary |
---|
| 23 | |
---|
| 24 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 25 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf |
---|
| 26 | from anuga.shallow_water.data_manager import dem2pts |
---|
| 27 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
| 28 | from anuga.abstract_2d_finite_volumes.util import file_function |
---|
| 29 | |
---|
[4939] | 30 | from anuga.caching import cache |
---|
| 31 | from anuga.utilities.polygon import read_polygon, plot_polygons, \ |
---|
| 32 | polygon_area, is_inside_polygon |
---|
[4925] | 33 | |
---|
| 34 | #------------------------------------------------------------------------------ |
---|
| 35 | # Define scenario as either ... |
---|
| 36 | #------------------------------------------------------------------------------ |
---|
| 37 | scenario = 'br' |
---|
| 38 | |
---|
| 39 | if os.access(scenario, os.F_OK) == 0: |
---|
| 40 | os.mkdir(scenario) |
---|
| 41 | basename = scenario + 'source' |
---|
| 42 | |
---|
[4939] | 43 | #------------------ |
---|
| 44 | # Initial condition |
---|
| 45 | #------------------ |
---|
| 46 | tide = 0.0 |
---|
| 47 | |
---|
| 48 | |
---|
[4925] | 49 | #------------------------------------------------------------------------------ |
---|
| 50 | # Preparation of topographic data |
---|
| 51 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 52 | #------------------------------------------------------------------------------ |
---|
| 53 | |
---|
| 54 | # Filenames |
---|
| 55 | #dem_name = 'sub_region_bat' |
---|
| 56 | #meshname = 'sub_region.msh' |
---|
| 57 | dem_name = 'bocarra' |
---|
| 58 | meshname = 'bocarra.msh' |
---|
| 59 | |
---|
| 60 | |
---|
[4939] | 61 | #--------- |
---|
| 62 | # Polygons |
---|
| 63 | #--------- |
---|
[4925] | 64 | |
---|
| 65 | # bounding polygon for study area |
---|
| 66 | bounding_polygon = read_polygon('out_bocarra.csv') |
---|
| 67 | |
---|
| 68 | print 'Area of bounding polygon in km?', polygon_area(bounding_polygon)/1000000.0 |
---|
| 69 | |
---|
| 70 | # interior polygons |
---|
| 71 | #poly_midle = read_polygon('midle_rect.csv') |
---|
| 72 | poly_shallow = read_polygon('shallow.csv') |
---|
| 73 | |
---|
| 74 | |
---|
[4939] | 75 | #------------ |
---|
| 76 | # Resolutions |
---|
| 77 | #------------ |
---|
[4925] | 78 | remainder_res = 2000 |
---|
| 79 | midle_res = 3500 |
---|
| 80 | shallow_res = 100 |
---|
| 81 | |
---|
[4939] | 82 | interior_regions = [[poly_shallow, shallow_res]] |
---|
[4925] | 83 | |
---|
[4939] | 84 | def setup_domain(tide, |
---|
| 85 | bounding_polygon, |
---|
| 86 | remainder_res, |
---|
| 87 | interior_regions, |
---|
| 88 | mesh_filename, |
---|
| 89 | points_filename): |
---|
| 90 | """Set up domain except boundary conditions |
---|
| 91 | This function is defined in order to cache it. |
---|
| 92 | """ |
---|
[4925] | 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
[4939] | 98 | create_mesh_from_regions(bounding_polygon, |
---|
| 99 | boundary_tags={'west': [0], |
---|
| 100 | 'north': [1], |
---|
| 101 | 'east': [2], |
---|
| 102 | 'south': [3]}, |
---|
| 103 | maximum_triangle_area=remainder_res, |
---|
| 104 | filename=mesh_filename, |
---|
| 105 | interior_regions=interior_regions, |
---|
| 106 | use_cache=False, |
---|
| 107 | verbose=True) |
---|
[4925] | 108 | |
---|
[4939] | 109 | #-------------------------------------------------------------------------- |
---|
| 110 | # Setup computational domain |
---|
| 111 | #-------------------------------------------------------------------------- |
---|
| 112 | |
---|
| 113 | domain = Domain(mesh_filename, |
---|
| 114 | use_cache=False, |
---|
| 115 | verbose=True) |
---|
| 116 | |
---|
| 117 | print 'Number of triangles = ', len(domain) |
---|
| 118 | print 'The extent is ', domain.get_extent() |
---|
| 119 | print domain.statistics() |
---|
| 120 | |
---|
| 121 | domain.set_name(basename) |
---|
| 122 | domain.set_datadir(scenario) |
---|
| 123 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 124 | domain.set_minimum_storable_height(0.05) |
---|
| 125 | |
---|
| 126 | #-------------------------------------------------------------------------- |
---|
| 127 | # Setup initial conditions |
---|
| 128 | #-------------------------------------------------------------------------- |
---|
| 129 | |
---|
| 130 | domain.set_quantity('stage', tide) |
---|
| 131 | domain.set_quantity('friction', 0.025) |
---|
| 132 | domain.set_quantity('elevation', |
---|
| 133 | filename=points_filename, |
---|
| 134 | use_cache=False, |
---|
| 135 | verbose=True) |
---|
| 136 | |
---|
| 137 | return domain |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | #-------------------------------- |
---|
| 141 | # Call (and cache) setup function |
---|
| 142 | #-------------------------------- |
---|
| 143 | |
---|
| 144 | # Run set_up domain without caching |
---|
| 145 | #domain = setup_domain(tide, bounding_polygon, poly_shallow, |
---|
| 146 | # remainder_res, midle_res, shallow_res, |
---|
| 147 | # meshname, |
---|
| 148 | # dem_name + '.pts') |
---|
| 149 | |
---|
| 150 | # Run set_up domain with caching |
---|
| 151 | domain = cache(setup_domain, |
---|
| 152 | (tide, |
---|
| 153 | bounding_polygon, |
---|
| 154 | remainder_res, |
---|
| 155 | interior_regions, |
---|
| 156 | meshname, |
---|
| 157 | dem_name + '.pts'), |
---|
| 158 | #dependencies = |
---|
| 159 | verbose=True) |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | |
---|
[4925] | 163 | #------------------------------------------------------------------------------ |
---|
| 164 | # Setup boundary conditions |
---|
| 165 | #------------------------------------------------------------------------------ |
---|
| 166 | |
---|
| 167 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 168 | Br = Reflective_boundary(domain) |
---|
| 169 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 170 | Bf = Field_boundary('swan_tsu_stageLand.sww', domain, time_thinning=1, mean_stage=tide, |
---|
| 171 | use_cache=True, verbose=True) |
---|
| 172 | |
---|
[4939] | 173 | # Boundary condition for sww feed at the east boundary |
---|
[4925] | 174 | domain.set_boundary({'west': Bf,'south':Bf,'east': Br,'north': Br}) |
---|
[4939] | 175 | |
---|
[4925] | 176 | |
---|
| 177 | #------------------------------------------------------------------------------ |
---|
| 178 | # Evolve system through time |
---|
| 179 | #------------------------------------------------------------------------------ |
---|
| 180 | |
---|
| 181 | import time |
---|
| 182 | t0 = time.time() |
---|
| 183 | |
---|
| 184 | from Numeric import allclose |
---|
| 185 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 186 | |
---|
[4939] | 187 | # Save every 1 sec leading up to wave approaching land |
---|
[4925] | 188 | for t in domain.evolve(yieldstep = 10, finaltime = 90): |
---|
| 189 | domain.write_time() |
---|
| 190 | domain.write_boundary_statistics(tags = ['west','south']) |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | print 'That took %.2f seconds' %(time.time()-t0) |
---|