"""Script for running tsunami inundation scenario for Dampier, WA, Australia. 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 project.output_run_time_dir The scenario is defined by a triangular mesh created from project.polygon, the elevation data and a simulated submarine landslide. Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ # Standard modules from os import sep, mkdir, access, F_OK from os.path import dirname, basename from shutil import copy import time import sys # Related major packages from anuga.shallow_water import Domain from anuga.shallow_water import Dirichlet_boundary, File_boundary, Reflective_boundary from anuga.shallow_water import Field_boundary from Numeric import allclose from anuga.pmesh.mesh_interface import create_mesh_from_regions from anuga.geospatial_data.geospatial_data import * from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files from anuga_parallel.parallel_api import distribute, numprocs, myid, barrier from anuga.utilities.polygon import plot_polygons, polygon_area from anuga_parallel.parallel_abstraction import get_processor_name # Application specific imports import project # Definition of file names and polygons #------------------------------------------------------------------------------ # Copy scripts to time stamped output directory and capture screen # output to file #------------------------------------------------------------------------------ if myid == 0: copy_code_files(project.output_run_time_dir,__file__, dirname(project.__file__)+sep+ project.__name__+'.py' ) barrier() start_screen_catcher(project.output_run_time_dir, myid, numprocs) # filenames boundaries_name = project.scenario meshes_dir_name = project.meshes_dir_name+'.msh' boundaries_dir_name = project.boundaries_dir_name tide = project.tide # creates copy of code in output dir print "Processor Name:",get_processor_name() print 'USER: ', project.user print 'min triangles', project.trigs_min, print 'Note: This is generally about 20% less than the final amount' #-------------------------------------------------------------------------- # 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 #-------------------------------------------------------------------------- if myid == 0: print 'start create mesh from regions' create_mesh_from_regions(project.poly_all, # boundary_tags={'back': [1, 2], 'side': [0,3], # 'ocean': [4, 5, 6]}, boundary_tags={'back': [1, 2], 'side': [0,3], 'ocean': [4]}, maximum_triangle_area=project.res_poly_all, interior_regions=project.interior_regions, filename=meshes_dir_name, use_cache=False, verbose=True) # to sync all processors are ready barrier() #------------------------------------------------------------------------- # Setup computational domain #------------------------------------------------------------------------- print 'Setup computational domain' #domain = Domain(meshes_time_dir_name, use_cache=True, verbose=True) domain = Domain(meshes_dir_name, use_cache=False, verbose=True) print domain.statistics() #------------------------------------------------------------------------- # Setup initial conditions #------------------------------------------------------------------------- if myid == 0: print 'Setup initial conditions' from polygon import Polygon_function #following sets the stage/water to be offcoast only IC = Polygon_function( [(project.poly_mainland, -1.0)], default = tide, geo_reference = domain.geo_reference) domain.set_quantity('stage', IC) #combined_time_dir_name = project.topographies_dir+build_time+project.combined_name print 'Start Set quantity' print 'project.combined_dir_name_unclipped1',project.combined_dir_name_unclipped1+'.txt' domain.set_quantity('elevation', # filename = project.combined_dir_name+'.txt', filename = project.combined_dir_name_unclipped1+'.txt', # filename = project.combined_smaller_name_dir+'.xya', use_cache = True, verbose = True, alpha = 0.1) print 'Finished Set quantity' barrier() #------------------------------------------------------ # Distribute domain to implement parallelism !!! #------------------------------------------------------ if numprocs > 1: domain=distribute(domain) #------------------------------------------------------ # Set domain parameters #------------------------------------------------------ domain.set_name(project.scenario_name) domain.set_datadir(project.output_run_time_dir) domain.set_default_order(2) # Apply second order scheme domain.set_minimum_storable_height(0.01) # Don't store anything less than 1cm domain.set_store_vertices_uniquely(False) domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) #------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------- print 'Available boundary tags', domain.get_boundary_tags() print 'Reading Boundary file' print 'domain id', id(domain) #Bf = File_boundary(boundaries_dir_name + '.sww', # domain, time_thinning=12, use_cache=True, verbose=True) Bf = Field_boundary(boundaries_dir_name + '.sww', domain, time_thinning=1, mean_stage=tide, use_cache=True, verbose=True) print 'finished reading boundary file' Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([tide,0,0]) Bo = Dirichlet_boundary([tide+5.0,0,0]) print'set_boundary' domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bf}) # 'ocean': Bd}) print'finish set boundary' #---------------------------------------------------------------------------- # Evolve system through time #---------------------------------------------------------------------------- t0 = time.time() for t in domain.evolve(yieldstep = 60, finaltime = 30000): domain.write_time() domain.write_boundary_statistics(tags = 'ocean') # if allclose(t, 120): # domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bo}) # if allclose(t, 1020): # domain.set_boundary({'back': Br, 'side': Bd, 'ocean': Bd}) print 'That took %.2f seconds' %(time.time()-t0)