[5393] | 1 | """Script for running the 2004 boxing Day tsunami inundation scenario for |
---|
| 2 | Phuket, Thailand. |
---|
| 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 directory named after the scenario, i.e |
---|
| 7 | slide or fixed_wave. |
---|
| 8 | |
---|
| 9 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
| 10 | the elevation data and a tsunami wave generated by a submarine mass failure. |
---|
| 11 | |
---|
| 12 | Author: John Jakeman, The Australian National University (2008) |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | #------------------------------------------------------------------------------ |
---|
| 16 | # Import necessary modules |
---|
| 17 | #------------------------------------------------------------------------------ |
---|
| 18 | |
---|
| 19 | # Standard modules |
---|
| 20 | import os |
---|
| 21 | import time |
---|
| 22 | import sys |
---|
| 23 | from time import localtime, strftime |
---|
| 24 | |
---|
| 25 | # Related major packages |
---|
| 26 | from anuga.shallow_water import Domain |
---|
| 27 | from anuga.shallow_water import Reflective_boundary |
---|
| 28 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 29 | from anuga.shallow_water import Time_boundary |
---|
| 30 | from anuga.shallow_water import File_boundary |
---|
| 31 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 32 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, ferret2sww |
---|
| 33 | from anuga.shallow_water.data_manager import dem2pts |
---|
| 34 | from anuga.coordinate_transforms.redfearn import convert_from_latlon_to_utm |
---|
| 35 | from anuga.utilities.polygon import number_mesh_triangles |
---|
| 36 | from anuga.fit_interpolate.fit import fit_to_mesh_file |
---|
| 37 | from anuga.caching import cache |
---|
| 38 | from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance |
---|
| 39 | |
---|
| 40 | # Application specific imports |
---|
| 41 | import project # Definition of file names and polygons |
---|
| 42 | import create_boundary |
---|
| 43 | |
---|
| 44 | #------------------------------------------------------------------------------ |
---|
| 45 | # Define scenario as either slide or fixed_wave. |
---|
| 46 | #------------------------------------------------------------------------------ |
---|
| 47 | |
---|
| 48 | #scenario = 'poor_simulation' |
---|
| 49 | scenario = 'good_simulation' |
---|
| 50 | |
---|
| 51 | if os.access(scenario, os.F_OK) == 0: |
---|
| 52 | os.mkdir(scenario) |
---|
| 53 | |
---|
| 54 | timestamp = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
| 55 | basename = scenario + '_urs' |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | #------------------------------------------------------------------------------ |
---|
| 59 | # Preparation of topographic data |
---|
| 60 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 61 | #------------------------------------------------------------------------------ |
---|
| 62 | |
---|
| 63 | if scenario == 'good_simualation': |
---|
| 64 | msg = 'Must use combine_good_data to create bathymetry .pts file' |
---|
| 65 | assert os.path.exists(project.good_combined_dir_name+'.pts'), msg |
---|
| 66 | |
---|
| 67 | #------------------------------------------------------------------------------ |
---|
| 68 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
| 69 | # boundary and interior regions defined in project.py along with |
---|
| 70 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 71 | #------------------------------------------------------------------------------ |
---|
| 72 | extent_res = 10000000.0 |
---|
| 73 | contour20m_res = 50000.0 |
---|
| 74 | island_res = 5000.0 |
---|
| 75 | bay_res = 2000.0 |
---|
| 76 | patong_res = 100.0 |
---|
| 77 | |
---|
| 78 | # make polygon that contains land that does not affect result. |
---|
| 79 | |
---|
| 80 | interior_regions = [[project.patong, patong_res], |
---|
| 81 | [project.bay, bay_res], |
---|
| 82 | [project.contour20m, contour20m_res], |
---|
| 83 | [project.island_north, island_res], |
---|
| 84 | [project.island_south, island_res], |
---|
| 85 | [project.island_south2, island_res]] |
---|
| 86 | |
---|
| 87 | #for coarse run to test gauges |
---|
| 88 | extent_res = 10000000.0 |
---|
| 89 | interior_regions=None |
---|
| 90 | |
---|
| 91 | from Numeric import arange,allclose |
---|
| 92 | print 'Beware not all boundary segments that are tagged as ocean in polyline are tagged here. missing are 79,80,81,82,83,84 which are set to other ocean' |
---|
| 93 | boundary_tags={'ocean': arange(1,79).tolist(), 'otherocean': [0,89,84,83,82,81,80,79], 'land': [86, 87], 'both': [85,88]} |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | #trigs_min = number_mesh_triangles(interior_regions, create_boundary.bounding_polygon,extent_res) |
---|
| 97 | #print 'Minimum number of traingles ', trigs_min |
---|
| 98 | |
---|
| 99 | # filenames |
---|
| 100 | meshname = project.meshname + '_cloud.tsh' |
---|
| 101 | mesh_elevname = project.mesh_elevname + '_cloud.tsh' |
---|
| 102 | |
---|
| 103 | print 'start create mesh from regions' |
---|
| 104 | |
---|
| 105 | _ = cache(create_mesh_from_regions, |
---|
| 106 | create_boundary.bounding_polygon, |
---|
| 107 | {'boundary_tags': boundary_tags, |
---|
| 108 | 'maximum_triangle_area': extent_res, |
---|
| 109 | 'filename': meshname, |
---|
| 110 | 'interior_regions': interior_regions}, |
---|
| 111 | verbose = True, |
---|
| 112 | #dependencies = ['create_boundary.py'] |
---|
| 113 | dependencies = ['run_boxingday_urs.py'] |
---|
| 114 | #, evaluate=True |
---|
| 115 | ) |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | #------------------------------------------------------------------------------ |
---|
| 119 | # Setup computational domain |
---|
| 120 | #------------------------------------------------------------------------------ |
---|
| 121 | print 'Converting mesh to domain' |
---|
| 122 | |
---|
| 123 | #domain = Domain(meshname, use_cache=False, verbose=True) |
---|
| 124 | |
---|
| 125 | domain = cache(pmesh_to_domain_instance, |
---|
| 126 | (meshname, Domain), |
---|
| 127 | dependencies = [meshname]) |
---|
| 128 | |
---|
| 129 | print 'Number of triangles = ', len(domain) |
---|
| 130 | print 'The extent is ', domain.get_extent() |
---|
| 131 | print domain.statistics() |
---|
| 132 | |
---|
| 133 | domain.set_name(basename+'friction'+timestamp) |
---|
| 134 | #domain.set_name(basename) |
---|
| 135 | domain.set_datadir(scenario) |
---|
| 136 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 137 | domain.set_minimum_storable_height(0.01) |
---|
| 138 | |
---|
| 139 | domain.beta_h = 0 |
---|
| 140 | domain.tight_slope_limiters = 1 |
---|
| 141 | domain.set_default_order(2) |
---|
| 142 | print 'domain.tight_slope_limiters', domain.tight_slope_limiters |
---|
| 143 | |
---|
| 144 | domain.points_file_block_line_size = 50000 |
---|
| 145 | |
---|
| 146 | #------------------------------------------------------------------------------ |
---|
| 147 | # Setup initial conditions |
---|
| 148 | #------------------------------------------------------------------------------ |
---|
| 149 | |
---|
| 150 | tide = 0.0 |
---|
| 151 | domain.set_quantity('stage', tide) |
---|
| 152 | domain.set_quantity('friction', 0.01) |
---|
| 153 | |
---|
| 154 | if scenario == 'poor_simulation': |
---|
| 155 | domain.set_quantity('elevation', |
---|
| 156 | filename=project.poor_combined_dir_name + '.pts', |
---|
| 157 | use_cache=True, |
---|
| 158 | verbose=True, |
---|
| 159 | alpha=0.1) |
---|
| 160 | |
---|
| 161 | if scenario == 'good_simulation': |
---|
| 162 | domain.set_quantity('elevation', |
---|
| 163 | filename=project.good_combined_dir_name + '.pts', |
---|
| 164 | use_cache=True, |
---|
| 165 | verbose=True, |
---|
| 166 | alpha=0.1) |
---|
| 167 | #------------------------------------------------------------------------------ |
---|
| 168 | # Setup boundary conditions |
---|
| 169 | #------------------------------------------------------------------------------ |
---|
| 170 | boundary_urs_in='data/boxing' |
---|
| 171 | boundary_urs_out='data/urs_boundary_condition' |
---|
| 172 | print 'start urs2sww' |
---|
| 173 | # Note only need to do when an SWW file for the MOST boundary doesn't exist or the bounding polygon has changed |
---|
| 174 | |
---|
| 175 | if os.path.exists(boundary_urs_out+'.sww'): |
---|
| 176 | print 'sww boundary file already created ensure boundary polygon has not changed' |
---|
| 177 | else: |
---|
| 178 | from anuga.shallow_water.data_manager import urs_ungridded2sww |
---|
| 179 | urs_ungridded2sww(basename_in=boundary_urs_in, basename_out=boundary_urs_out, |
---|
| 180 | verbose=True, |
---|
| 181 | #mint=0, maxt=10800, |
---|
| 182 | zscale=1) |
---|
| 183 | |
---|
| 184 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 185 | Bf = File_boundary(boundary_urs_out+'.sww', |
---|
| 186 | domain, time_thinning=1, |
---|
| 187 | use_cache=True,verbose = True) |
---|
| 188 | |
---|
| 189 | Br = Reflective_boundary(domain) |
---|
| 190 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 191 | |
---|
| 192 | domain.set_boundary({'ocean': Bf, |
---|
| 193 | 'otherocean': Bd, |
---|
| 194 | 'land': Br, |
---|
| 195 | 'both': Bd}) |
---|
| 196 | |
---|
| 197 | #------------------------------------------------------------------------------ |
---|
| 198 | # Evolve system through time |
---|
| 199 | #------------------------------------------------------------------------------ |
---|
| 200 | import time |
---|
| 201 | t0 = time.time() |
---|
| 202 | |
---|
| 203 | #from Numeric import allclose |
---|
| 204 | #from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 205 | |
---|
| 206 | # Add new loop that uses larger yieldstep until wave first reaches a point of |
---|
| 207 | # the ANUGA boundary. Or find a way to clip MOST sww boundary file to only |
---|
| 208 | # start when boundary stage first becomes non-zero. |
---|
| 209 | |
---|
| 210 | for t in domain.evolve(yieldstep = 5.0, finaltime = 18000.0, |
---|
| 211 | skip_initial_step = False): |
---|
| 212 | if allclose(t,10800.0): |
---|
| 213 | print 'Changing urs file boundary to dirichlet. Urs gauges only have 3 hours of data' |
---|
| 214 | domain.set_boundary({'ocean': Bd, |
---|
| 215 | 'otherocean': Bd, |
---|
| 216 | 'land': Br, |
---|
| 217 | 'both': Bd}) |
---|
| 218 | |
---|
| 219 | domain.write_time() |
---|
| 220 | |
---|
| 221 | print 'That took %.2f seconds' %(time.time()-t0) |
---|