[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 |
---|
| 17 | |
---|
| 18 | # Related major packages |
---|
| 19 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary |
---|
| 20 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
| 21 | |
---|
| 22 | #---------------------------------------------------------------------------- |
---|
| 23 | # Create the triangular mesh based on the problem statement |
---|
| 24 | #------------------------------------------------------------------------------- |
---|
| 25 | |
---|
| 26 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
| 27 | remainder_res = 250000. |
---|
| 28 | #local_res = 50000. |
---|
| 29 | #coast_res = 500. |
---|
| 30 | #interior_regions = [[project_slide.poly_syd1, local_res], |
---|
| 31 | # [project_slide.poly_coast, coast_res]] |
---|
| 32 | length = 10. |
---|
| 33 | width = 10. |
---|
| 34 | depth = 10. |
---|
| 35 | bounding_polygon = [[0,width],[0,0],[length,0],[length,width]] |
---|
| 36 | meshname = 'slide.msh' |
---|
| 37 | from caching import cache |
---|
| 38 | _ = cache(create_mesh_from_regions, |
---|
| 39 | bounding_polygon, |
---|
| 40 | {'boundary_tags': {'top': [0], 'left': [1], |
---|
| 41 | 'bottom': [2], 'right': [3]}, |
---|
| 42 | 'maximum_triangle_area': remainder_res, |
---|
| 43 | 'filename': meshname}, |
---|
| 44 | #'interior_regions': interior_regions}, |
---|
| 45 | verbose = True, evaluate=False) |
---|
| 46 | print 'created mesh' |
---|
| 47 | |
---|
| 48 | #------------------------------------------------------------------------------- |
---|
| 49 | # Setup computational domain |
---|
| 50 | #------------------------------------------------------------------------------- |
---|
| 51 | domain = Domain(meshname, use_cache = True, verbose = True) |
---|
| 52 | |
---|
| 53 | print 'Number of triangles = ', len(domain) |
---|
| 54 | print 'The extent is ', domain.get_extent() |
---|
| 55 | print domain.statistics() |
---|
| 56 | |
---|
| 57 | domain.set_name('slide') |
---|
| 58 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 59 | domain.set_minimum_storable_height(0.01) |
---|
| 60 | |
---|
| 61 | #------------------------------------------------------------------------------- |
---|
| 62 | # Setup initial conditions |
---|
| 63 | #------------------------------------------------------------------------------- |
---|
| 64 | from math import tan |
---|
| 65 | def topography(x,y): |
---|
| 66 | z = -depth + tan(0.5)*x |
---|
| 67 | return z |
---|
| 68 | domain.set_quantity('stage', 0.0) |
---|
| 69 | domain.set_quantity('friction', 0.0) |
---|
| 70 | domain.set_quantity('elevation', topography, |
---|
| 71 | use_cache = True, |
---|
| 72 | verbose = True, |
---|
| 73 | alpha = 0.1 |
---|
| 74 | ) |
---|
| 75 | |
---|
| 76 | #------------------------------------------------------------------------------- |
---|
| 77 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
| 78 | #------------------------------------------------------------------------------- |
---|
| 79 | from smf import slide_tsunami |
---|
| 80 | |
---|
| 81 | tsunami_source = slide_tsunami(length=2., |
---|
| 82 | width=1., |
---|
| 83 | depth=1., |
---|
| 84 | slope=45, |
---|
| 85 | thickness=0.1, |
---|
| 86 | x0=length/2, |
---|
| 87 | y0=width/2, |
---|
| 88 | alpha=0., |
---|
| 89 | #dx=0.001, |
---|
| 90 | domain=domain) |
---|
| 91 | #verbose=True) |
---|
| 92 | |
---|
| 93 | #------------------------------------------------------------------------------- |
---|
| 94 | # Setup boundary conditions |
---|
| 95 | #------------------------------------------------------------------------------- |
---|
| 96 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 97 | |
---|
| 98 | Br = Reflective_boundary(domain) |
---|
| 99 | Bd = Dirichlet_boundary([tide,0,0]) |
---|
| 100 | |
---|
| 101 | domain.set_boundary( {'e0': Bd, 'e1': Bd, 'e2': Bd, 'e3': Bd} ) |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | #------------------------------------------------------------------------------- |
---|
| 105 | # Evolve system through time |
---|
| 106 | #------------------------------------------------------------------------------- |
---|
| 107 | import time |
---|
| 108 | from Numeric import allclose |
---|
| 109 | from anuga.abstract_2d_finite_volumes.quantity import Quantity |
---|
| 110 | |
---|
| 111 | t0 = time.time() |
---|
| 112 | |
---|
| 113 | for t in domain.evolve(yieldstep = 1, finaltime = 10): |
---|
| 114 | domain.write_time() |
---|
| 115 | stagestep = domain.get_quantity('stage') |
---|
| 116 | |
---|
| 117 | if allclose(t, 1): |
---|
| 118 | slide = Quantity(domain) |
---|
| 119 | slide.set_values(tsunami_source) |
---|
| 120 | domain.set_quantity('stage', slide + stagestep) |
---|
| 121 | |
---|
| 122 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 123 | |
---|
| 124 | print 'finished' |
---|