"""Run a storm surge inundation scenario for Mandurah, WA, Australia using input from the third party consultant GEMS. The scenario is defined by a triangular mesh created from project.polygon, the elevation data is compiled into a pts file through build_elevation.py and a simulated storm surge is generated from GEMS data. Input: sts files (csv format time series at ocean boundary for respective event) pts file (build_elevation.py) information from project file Outputs: sww file stored in project.output_run_time_dir The export_results_all.py and get_timeseries.py is reliant on the outputs of this script Ole Nielsen and Duncan Gray, GA - 2005, Jane Sexton, Nick Bartzis, GA - 2006 Ole Nielsen, Jane Sexton and Kristy Van Putten - 2008 Nariman Habili, Leharne Fountain - 2009 """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ # Standard modules import os ##import os.path import time ##from time import localtime, strftime, gmtime # Related major packages ##from Scientific.IO.NetCDF import NetCDFFile import numpy as num from anuga.interface import create_domain_from_regions from anuga.interface import Transmissive_stage_zero_momentum_boundary from anuga.interface import Dirichlet_boundary from anuga.interface import Reflective_boundary from anuga.interface import Field_boundary from anuga.interface import create_sts_boundary ##from anuga.interface import csv2building_polygons from file_length import file_length from anuga.shallow_water.data_manager import start_screen_catcher from anuga.shallow_water.data_manager import copy_code_files ##from anuga.shallow_water.data_manager import urs2sts from anuga.utilities.polygon import read_polygon, Polygon_function # Application specific imports from setup_model import project ##import build_urs_boundary as bub # Imports for floodgates from project import floodgate_boundary, floodgate_resolution #------------------------------------------------------------------------------- # Copy scripts to time stamped output directory and capture screen # output to file. Copy script must be before screen_catcher #------------------------------------------------------------------------------- copy_code_files(project.output_run, __file__, os.path.join(os.path.dirname(project.__file__), project.__name__+'.py')) start_screen_catcher(project.output_run, 0, 1) #------------------------------------------------------------------------------- # Create the computational domain 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 #------------------------------------------------------------------------------- print 'Create computational domain' ### Create the STS file ##print 'project.mux_data_folder=%s' % project.mux_data_folder ##if not os.path.exists(project.event_sts + '.sts'): ## bub.build_urs_boundary(project.mux_input_filename, project.event_sts) ### Read in boundary from ordered sts file ##gems_boundary = create_sts_boundary(project.event_sts) #reading the GEMS boundary points gems_boundary = read_polygon(project.gems_order) ##gems_boundary = create_sts_boundary(project.event_sts) # Reading the landward defined points of the original bounding polygon landward_boundary = read_polygon(project.landward_boundary) # Combine GEMS input boundary polyline with landward points bounding_polygon_gems = gems_boundary + landward_boundary # Number of boundary segments num_ocean_segments = len(gems_boundary) - 1 # Number of landward_boundary points num_land_points = file_length(project.landward_boundary) # Boundary tags refer to project.landward_boundary # 4 points equals 5 segments start at N boundary_tags={'back': range(num_ocean_segments+1, num_ocean_segments+num_land_points), 'side': [num_ocean_segments, num_ocean_segments+num_land_points], 'ocean': range(num_ocean_segments)} # Build mesh and domain domain = create_domain_from_regions(bounding_polygon_gems, boundary_tags=boundary_tags, maximum_triangle_area=project.bounding_maxarea, interior_regions=project.interior_regions, mesh_filename=project.meshes, use_cache=False, #usually true but changed for testing verbose=True) print domain.statistics() domain.set_starttime(project.starttime) domain.set_name(project.scenario_name) domain.set_datadir(project.output_run) domain.set_minimum_storable_height(0.01) # Don't store depth less than 1cm #------------------------------------------------------------------------------- # Setup initial conditions #------------------------------------------------------------------------------- print 'Setup initial conditions' # Set the initial stage in the offcoast region only if project.land_initial_conditions: IC = Polygon_function(project.land_initial_conditions, default=project.tide, geo_reference=domain.geo_reference) else: IC = 0 domain.set_quantity('stage', IC, use_cache=True, verbose=True) domain.set_quantity('friction', project.friction) domain.set_quantity('elevation', filename=project.combined_elevation+'.pts', use_cache=True, verbose=True, alpha=project.alpha) #-------------------------- # Add storm surge gate #-------------------------- storm_gate_polygon, storm_gate_height = csv2building_polygons(project.storm_gate, floor_height=4) gate = [] for key in storm_gate_polygon: poly = storm_gate_polygon[key] elev = storm_gate_height[key] gate.append((poly, elev)) domain.add_quantity('elevation', Polygon_function(gate, geo_reference=domain.geo_reference), use_cache=True, verbose=True) #------------------------------------------------------------------------------- # Setup boundary conditions #------------------------------------------------------------------------------- print 'Set boundary - available tags:', domain.get_boundary_tags() Br = Reflective_boundary(domain) Bt = Transmissive_stage_zero_momentum_boundary(domain) Bd = Dirichlet_boundary([project.tide, 0, 0]) Bf = Field_boundary(project.event_sts+'.sts', domain, mean_stage=project.tide, time_thinning=1, default_boundary=Dirichlet_boundary([0, 0, 0]), boundary_polygon=bounding_polygon_gems, use_cache=True, verbose=True) domain.set_boundary({'back': Br, 'side': Bt, 'ocean': Bf}) #------------------------------------------------------------------------------- # Evolve system through time #------------------------------------------------------------------------------- t0 = time.time() for t in domain.evolve(yieldstep=project.yieldstep, finaltime=project.finaltime, skip_initial_step=False): print domain.timestepping_statistics() print domain.boundary_statistics(tags='ocean') print 'Simulation took %.2f seconds' % (time.time()-t0)