[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 | |
---|
| 43 | |
---|
| 44 | #------------------------------------------------------------------------------ |
---|
| 45 | # Define scenario as either slide or fixed_wave. |
---|
| 46 | #------------------------------------------------------------------------------ |
---|
| 47 | |
---|
[5483] | 48 | #scenario = 'poor_simulation' |
---|
| 49 | scenario = 'good_simulation' |
---|
[5393] | 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()) |
---|
[5401] | 55 | basename = scenario[:4] + '_polyline' |
---|
[5672] | 56 | tide = project.tide |
---|
[5393] | 57 | |
---|
| 58 | |
---|
| 59 | #------------------------------------------------------------------------------ |
---|
| 60 | # Preparation of topographic data |
---|
| 61 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 62 | #------------------------------------------------------------------------------ |
---|
| 63 | |
---|
| 64 | if scenario == 'good_simualation': |
---|
| 65 | msg = 'Must use combine_good_data to create bathymetry .pts file' |
---|
| 66 | assert os.path.exists(project.good_combined_dir_name+'.pts'), msg |
---|
| 67 | |
---|
| 68 | #------------------------------------------------------------------------------ |
---|
| 69 | # Create the triangular mesh based on overall clipping polygon with a tagged |
---|
| 70 | # boundary and interior regions defined in project.py along with |
---|
| 71 | # resolutions (maximal area of per triangle) for each polygon |
---|
| 72 | #------------------------------------------------------------------------------ |
---|
[5401] | 73 | extent_res = 1000000.0 |
---|
[5393] | 74 | contour20m_res = 50000.0 |
---|
| 75 | island_res = 5000.0 |
---|
| 76 | bay_res = 2000.0 |
---|
[5401] | 77 | patong_res = 400.0 |
---|
[5393] | 78 | |
---|
| 79 | |
---|
| 80 | # make polygon that contains land that does not affect result. |
---|
| 81 | |
---|
| 82 | interior_regions = [[project.patong, patong_res], |
---|
| 83 | [project.bay, bay_res], |
---|
[5401] | 84 | [project.contour20m, contour20m_res]]#, |
---|
| 85 | #[project.island_north, island_res], |
---|
| 86 | #[project.island_south, island_res], |
---|
| 87 | #[project.island_south2, island_res]] |
---|
[5393] | 88 | |
---|
| 89 | |
---|
| 90 | #for coarse run to test gauges |
---|
[5401] | 91 | #extent_res = 10000000.0 |
---|
| 92 | #interior_regions=None |
---|
[5393] | 93 | |
---|
| 94 | from Numeric import arange,allclose |
---|
[5458] | 95 | #This needs to be done by the user. Not easy at the moment |
---|
[5401] | 96 | boundary_tags={'ocean': arange(0,41).tolist(), 'otherocean': [41,44], 'land': [42,43]} |
---|
[5393] | 97 | |
---|
[5401] | 98 | #trigs_min = number_mesh_triangles(interior_regions, project.bounding_polygon,extent_res) |
---|
[5393] | 99 | #print 'Minimum number of traingles ', trigs_min |
---|
| 100 | |
---|
| 101 | # filenames |
---|
| 102 | meshname = project.meshname + '_polyline.tsh' |
---|
| 103 | mesh_elevname = project.mesh_elevname + '_polyline.tsh' |
---|
| 104 | |
---|
| 105 | print 'start create mesh from regions' |
---|
| 106 | |
---|
| 107 | _ = cache(create_mesh_from_regions, |
---|
[5401] | 108 | project.bounding_polygon, |
---|
[5393] | 109 | {'boundary_tags': boundary_tags, |
---|
| 110 | 'maximum_triangle_area': extent_res, |
---|
| 111 | 'filename': meshname, |
---|
| 112 | 'interior_regions': interior_regions}, |
---|
| 113 | verbose = True, |
---|
[5401] | 114 | dependencies = ['project.py'] |
---|
[5393] | 115 | #, evaluate=True |
---|
| 116 | ) |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | #------------------------------------------------------------------------------ |
---|
| 120 | # Setup computational domain |
---|
| 121 | #------------------------------------------------------------------------------ |
---|
| 122 | print 'Converting mesh to domain' |
---|
| 123 | |
---|
| 124 | #domain = Domain(meshname, use_cache=False, verbose=True) |
---|
| 125 | |
---|
| 126 | domain = cache(pmesh_to_domain_instance, |
---|
| 127 | (meshname, Domain), |
---|
| 128 | dependencies = [meshname]) |
---|
| 129 | |
---|
| 130 | print 'The extent is ', domain.get_extent() |
---|
| 131 | print domain.statistics() |
---|
| 132 | |
---|
[5672] | 133 | domain.set_name(basename+timestamp+'_'+str(tide)) |
---|
[5393] | 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 | |
---|
[5601] | 139 | domain.tight_slope_limiters = True |
---|
[5393] | 140 | domain.set_default_order(2) |
---|
| 141 | print 'domain.tight_slope_limiters', domain.tight_slope_limiters |
---|
| 142 | |
---|
| 143 | domain.points_file_block_line_size = 50000 |
---|
| 144 | |
---|
| 145 | #------------------------------------------------------------------------------ |
---|
| 146 | # Setup initial conditions |
---|
| 147 | #------------------------------------------------------------------------------ |
---|
| 148 | |
---|
| 149 | domain.set_quantity('stage', tide) |
---|
| 150 | domain.set_quantity('friction', 0.01) |
---|
| 151 | |
---|
| 152 | if scenario == 'poor_simulation': |
---|
| 153 | domain.set_quantity('elevation', |
---|
| 154 | filename=project.poor_combined_dir_name + '.pts', |
---|
| 155 | use_cache=True, |
---|
| 156 | verbose=True, |
---|
| 157 | alpha=0.1) |
---|
| 158 | |
---|
| 159 | if scenario == 'good_simulation': |
---|
| 160 | domain.set_quantity('elevation', |
---|
| 161 | filename=project.good_combined_dir_name + '.pts', |
---|
| 162 | use_cache=True, |
---|
[5547] | 163 | verbose=True) |
---|
| 164 | #alpha=0.1) |
---|
| 165 | |
---|
[5393] | 166 | #------------------------------------------------------------------------------ |
---|
| 167 | # Setup boundary conditions |
---|
| 168 | #------------------------------------------------------------------------------ |
---|
[5401] | 169 | boundary_urs_out=project.base_name |
---|
[5393] | 170 | |
---|
| 171 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 172 | Bf = File_boundary(boundary_urs_out+'.sts', |
---|
| 173 | domain, time_thinning=1, |
---|
[5547] | 174 | use_cache=True, |
---|
| 175 | verbose = True, |
---|
| 176 | boundary_polygon=project.bounding_polygon) |
---|
[5393] | 177 | |
---|
| 178 | Br = Reflective_boundary(domain) |
---|
| 179 | Bd = Dirichlet_boundary([tide,0.0,0.0]) |
---|
| 180 | |
---|
| 181 | domain.set_boundary({'ocean': Bf, |
---|
| 182 | 'otherocean': Bd, |
---|
| 183 | 'land': Br, |
---|
| 184 | 'both': Bd}) |
---|
| 185 | |
---|
| 186 | #------------------------------------------------------------------------------ |
---|
| 187 | # Evolve system through time |
---|
| 188 | #------------------------------------------------------------------------------ |
---|
| 189 | import time |
---|
| 190 | t0 = time.time() |
---|
| 191 | |
---|
| 192 | #from Numeric import allclose |
---|
| 193 | #from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 194 | |
---|
| 195 | # Add new loop that uses larger yieldstep until wave first reaches a point of |
---|
| 196 | # the ANUGA boundary. Or find a way to clip MOST sww boundary file to only |
---|
| 197 | # start when boundary stage first becomes non-zero. |
---|
| 198 | |
---|
[5401] | 199 | for t in domain.evolve(yieldstep = 20.0, finaltime = 18000.0, |
---|
[5393] | 200 | skip_initial_step = False): |
---|
| 201 | if allclose(t,10800.0): |
---|
| 202 | print 'Changing urs file boundary to dirichlet. Urs gauges only have 3 hours of data' |
---|
| 203 | domain.set_boundary({'ocean': Bd, |
---|
| 204 | 'otherocean': Bd, |
---|
| 205 | 'land': Br, |
---|
| 206 | 'both': Bd}) |
---|
| 207 | |
---|
| 208 | domain.write_time() |
---|
| 209 | |
---|
| 210 | print 'That took %.2f seconds' %(time.time()-t0) |
---|