[5567] | 1 | """Script for running the 3rd Long Wave Workshop Benchmark Problem 4. |
---|
| 2 | |
---|
| 3 | Bridgette Lewis and Jane Sexton, July 2008 |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | #------------------------------------------------------------------------------- |
---|
| 7 | # Import necessary modules |
---|
| 8 | #------------------------------------------------------------------------------- |
---|
| 9 | |
---|
| 10 | # Standard modules |
---|
| 11 | import os |
---|
| 12 | import time |
---|
| 13 | from shutil import copy |
---|
| 14 | from os.path import dirname, basename |
---|
| 15 | from os import mkdir, access, F_OK, sep |
---|
| 16 | import sys |
---|
[5572] | 17 | import project |
---|
[5567] | 18 | |
---|
| 19 | # Related major packages |
---|
| 20 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
| 21 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
[5572] | 22 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters |
---|
[5567] | 23 | |
---|
[5572] | 24 | myid=0 |
---|
| 25 | numprocs=1 |
---|
| 26 | print 'output_dir',project.output_run_time_dir |
---|
| 27 | copy_code_files(project.output_run_time_dir,'benchmark_problem4.py', |
---|
| 28 | 'project.py' ) |
---|
| 29 | start_screen_catcher(project.output_run_time_dir, myid, numprocs) |
---|
| 30 | |
---|
[5567] | 31 | #---------------------------------------------------------------------------- |
---|
| 32 | # Create the triangular mesh based on the problem statement |
---|
| 33 | #------------------------------------------------------------------------------- |
---|
| 34 | |
---|
| 35 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 36 | remainder_res = 250000. |
---|
| 37 | #local_res = 50000. |
---|
| 38 | #coast_res = 500. |
---|
| 39 | #interior_regions = [[project_slide.poly_syd1, local_res], |
---|
| 40 | # [project_slide.poly_coast, coast_res]] |
---|
[5633] | 41 | length = 104. #wave tank length |
---|
| 42 | width = 3.7 #wave tank width |
---|
[5568] | 43 | |
---|
| 44 | bounding_polygon = [[0,0],[length,0],[length,width],[0,width]] |
---|
[5567] | 45 | meshname = 'slide.msh' |
---|
[5568] | 46 | |
---|
[5572] | 47 | |
---|
[5567] | 48 | from caching import cache |
---|
| 49 | _ = cache(create_mesh_from_regions, |
---|
| 50 | bounding_polygon, |
---|
[5568] | 51 | {'boundary_tags': {'bottom': [0], 'right': [1], |
---|
| 52 | 'top': [2], 'left': [3]}, |
---|
[5572] | 53 | 'maximum_triangle_area': project.remainder_res, |
---|
[5567] | 54 | 'filename': meshname}, |
---|
| 55 | #'interior_regions': interior_regions}, |
---|
| 56 | verbose = True, evaluate=False) |
---|
| 57 | print 'created mesh' |
---|
| 58 | |
---|
| 59 | #------------------------------------------------------------------------------- |
---|
| 60 | # Setup computational domain |
---|
| 61 | #------------------------------------------------------------------------------- |
---|
| 62 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
| 63 | |
---|
| 64 | print 'Number of triangles = ', len(domain) |
---|
| 65 | print 'The extent is ', domain.get_extent() |
---|
| 66 | print domain.statistics() |
---|
| 67 | |
---|
[5572] | 68 | domain.set_datadir(project.output_run_time_dir) |
---|
| 69 | domain.set_name(project.sww_name) |
---|
[5567] | 70 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 71 | domain.set_minimum_storable_height(0.01) |
---|
| 72 | |
---|
| 73 | #------------------------------------------------------------------------------- |
---|
| 74 | # Setup initial conditions |
---|
| 75 | #------------------------------------------------------------------------------- |
---|
| 76 | from math import tan |
---|
[5633] | 77 | depth = 4.6 #depth of water domain; needs correction is actually slightly <4.6 |
---|
| 78 | b = 9.144 #from Synolakis paper |
---|
| 79 | def topography(x,y):#sloping intially (gradient=x/2when b<9.144) then flat (depth=4.6m) |
---|
[5568] | 80 | z = [] |
---|
| 81 | for xi in x: |
---|
| 82 | if xi < b: |
---|
| 83 | z.append(-xi/2.) |
---|
| 84 | else: |
---|
| 85 | z.append(-depth) |
---|
| 86 | #print 'hello', xi,b, z |
---|
[5567] | 87 | return z |
---|
| 88 | domain.set_quantity('stage', 0.0) |
---|
| 89 | domain.set_quantity('friction', 0.0) |
---|
| 90 | domain.set_quantity('elevation', topography, |
---|
| 91 | use_cache = True, |
---|
| 92 | verbose = True, |
---|
[5633] | 93 | alpha = 0.1 #inclination of domain from strike plane |
---|
[5567] | 94 | ) |
---|
| 95 | |
---|
| 96 | #------------------------------------------------------------------------------- |
---|
| 97 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
| 98 | #------------------------------------------------------------------------------- |
---|
| 99 | from smf import slide_tsunami |
---|
[5568] | 100 | from math import atan, degrees |
---|
[5567] | 101 | |
---|
[5633] | 102 | a = .4572 # slide height from Synolakis paper |
---|
| 103 | tsunami_source = slide_tsunami(length=0.91,#slide length |
---|
| 104 | width=0.61,#slide width |
---|
| 105 | depth=.01, # depth below surface to top of slide (delta from Synolakis paper) |
---|
[5568] | 106 | slope=degrees(atan(0.5)), |
---|
[5633] | 107 | thickness=a, #slide thickness |
---|
[5568] | 108 | x0=0.75, |
---|
[5567] | 109 | y0=width/2, |
---|
| 110 | alpha=0., |
---|
[5568] | 111 | #dx=0.001, |
---|
| 112 | domain=domain, |
---|
| 113 | verbose=True) |
---|
[5567] | 114 | |
---|
| 115 | #------------------------------------------------------------------------------- |
---|
| 116 | # Setup boundary conditions |
---|
| 117 | #------------------------------------------------------------------------------- |
---|
| 118 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 119 | |
---|
| 120 | Br = Reflective_boundary(domain) |
---|
[5568] | 121 | Bd = Dirichlet_boundary([0,0,0]) |
---|
[5567] | 122 | |
---|
[5568] | 123 | domain.set_boundary( {'top': Bd, 'bottom': Bd, 'right': Bd, 'left': Bd} ) |
---|
[5567] | 124 | |
---|
| 125 | |
---|
| 126 | #------------------------------------------------------------------------------- |
---|
| 127 | # Evolve system through time |
---|
| 128 | #------------------------------------------------------------------------------- |
---|
| 129 | import time |
---|
| 130 | from Numeric import allclose |
---|
| 131 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 132 | |
---|
| 133 | t0 = time.time() |
---|
[5572] | 134 | finaltime = 500 |
---|
| 135 | for t in domain.evolve(yieldstep = 1, finaltime = project.finaltime): |
---|
[5567] | 136 | domain.write_time() |
---|
| 137 | stagestep = domain.get_quantity('stage') |
---|
| 138 | |
---|
| 139 | if allclose(t, 1): |
---|
| 140 | slide = Quantity(domain) |
---|
| 141 | slide.set_values(tsunami_source) |
---|
| 142 | domain.set_quantity('stage', slide + stagestep) |
---|
| 143 | |
---|
| 144 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 145 | |
---|
| 146 | print 'finished' |
---|