"""Script for running the 2004 boxing Day tsunami inundation scenario for Phuket, Thailand. Source data such as elevation and boundary data is assumed to be available in directories specified by project.py The output sww file is stored in directory named after the scenario, i.e slide or fixed_wave. The scenario is defined by a triangular mesh created from project.polygon, the elevation data and a tsunami wave generated by a submarine mass failure. Author: John Jakeman, The Australian National University (2008) """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ # Standard modules import os import time import sys from time import localtime, strftime # Related major packages from anuga.shallow_water import Domain from anuga.shallow_water import Reflective_boundary from anuga.shallow_water import Dirichlet_boundary from anuga.shallow_water import Time_boundary from anuga.shallow_water import File_boundary from anuga.pmesh.mesh_interface import create_mesh_from_regions from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, ferret2sww from anuga.shallow_water.data_manager import dem2pts from anuga.coordinate_transforms.redfearn import convert_from_latlon_to_utm from anuga.utilities.polygon import number_mesh_triangles from anuga.fit_interpolate.fit import fit_to_mesh_file from anuga.caching import cache from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance # Application specific imports import project # Definition of file names and polygons #------------------------------------------------------------------------------ # Define scenario as either slide or fixed_wave. #------------------------------------------------------------------------------ #scenario = 'poor_simulation' scenario = 'good_simulation' if os.access(scenario, os.F_OK) == 0: os.mkdir(scenario) timestamp = strftime('%Y%m%d_%H%M%S',localtime()) basename = scenario[:4] + '_urs' #------------------------------------------------------------------------------ # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------ if scenario == 'good_simualation': msg = 'Must use combine_good_data to create bathymetry .pts file' assert os.path.exists(project.good_combined_dir_name+'.pts'), msg #------------------------------------------------------------------------------ # Create the triangular mesh based on overall clipping polygon with a tagged # boundary and interior regions defined in project.py along with # resolutions (maximal area of per triangle) for each polygon #------------------------------------------------------------------------------ extent_res = 1000000.0 contour20m_res = 50000.0 island_res = 5000.0 bay_res = 2000.0 patong_res = 400.0 # make polygon that contains land that does not affect result. interior_regions = [[project.patong, patong_res], [project.bay, bay_res], [project.contour20m, contour20m_res]]#, #[project.island_north, island_res], #[project.island_south, island_res], #[project.island_south2, island_res]] #for coarse run to test gauges #extent_res = 10000000.0 #interior_regions=None from Numeric import arange,allclose boundary_tags={'ocean': arange(0,41).tolist(), 'otherocean': [41,44], 'land': [42,43]} #trigs_min = number_mesh_triangles(interior_regions, project.bounding_polygon,extent_res) #print 'Minimum number of traingles ', trigs_min # filenames meshname = project.meshname + '_cloud.tsh' mesh_elevname = project.mesh_elevname + '_cloud.tsh' print 'start create mesh from regions' _ = cache(create_mesh_from_regions, project.bounding_polygon, {'boundary_tags': boundary_tags, 'maximum_triangle_area': extent_res, 'filename': meshname, 'interior_regions': interior_regions}, verbose = True, #dependencies = ['project.py'] dependencies = ['run_boxingday_urs.py'] #, evaluate=True ) #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ print 'Converting mesh to domain' #domain = Domain(meshname, use_cache=False, verbose=True) domain = cache(pmesh_to_domain_instance, (meshname, Domain), dependencies = [meshname]) print 'Number of triangles = ', len(domain) print 'The extent is ', domain.get_extent() print domain.statistics() domain.set_name(basename+timestamp) #domain.set_name(basename) domain.set_datadir(scenario) domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) domain.set_minimum_storable_height(0.01) domain.beta_h = 0 domain.tight_slope_limiters = 1 domain.set_default_order(2) print 'domain.tight_slope_limiters', domain.tight_slope_limiters domain.points_file_block_line_size = 50000 #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ tide = 0.0 domain.set_quantity('stage', tide) domain.set_quantity('friction', 0.01) if scenario == 'poor_simulation': domain.set_quantity('elevation', filename=project.poor_combined_dir_name + '.pts', use_cache=True, verbose=True, alpha=0.1) if scenario == 'good_simulation': domain.set_quantity('elevation', filename=project.good_combined_dir_name + '.pts', use_cache=True, verbose=True, alpha=0.1) #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------ boundary_urs_in='data/boxing' boundary_urs_out='data/urs_boundary_condition' print 'start urs2sww' # Note only need to do when an SWW file for the MOST boundary doesn't exist or the bounding polygon has changed if os.path.exists(boundary_urs_out+'.sww'): print 'sww boundary file already created ensure boundary polygon has not changed' else: from anuga.shallow_water.data_manager import urs_ungridded2sww urs_ungridded2sww(basename_in=boundary_urs_in, basename_out=boundary_urs_out, verbose=True, #mint=0, maxt=10800, zscale=1) print 'Available boundary tags', domain.get_boundary_tags() Bf = File_boundary(boundary_urs_out+'.sww', domain, time_thinning=1, use_cache=True,verbose = True) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([tide,0,0]) domain.set_boundary({'ocean': Bf, 'otherocean': Bd, 'land': Br, 'both': Bd}) #------------------------------------------------------------------------------ # Evolve system through time #------------------------------------------------------------------------------ import time t0 = time.time() #from Numeric import allclose #from anuga.abstract_2d_finite_volumes.quantity import Quantity # Add new loop that uses larger yieldstep until wave first reaches a point of # the ANUGA boundary. Or find a way to clip MOST sww boundary file to only # start when boundary stage first becomes non-zero. for t in domain.evolve(yieldstep = 20.0, finaltime = 18000.0, skip_initial_step = False): if allclose(t,10800.0): print 'Changing urs file boundary to dirichlet. Urs gauges only have 3 hours of data' domain.set_boundary({'ocean': Bd, 'otherocean': Bd, 'land': Br, 'both': Bd}) domain.write_time() print 'That took %.2f seconds' %(time.time()-t0)