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 | import project |
---|
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 |
---|
22 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files,store_parameters |
---|
23 | |
---|
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 | |
---|
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]] |
---|
41 | length = 104. #wave tank length |
---|
42 | width = 3.7 #wave tank width |
---|
43 | |
---|
44 | bounding_polygon = [[0,0],[length,0],[length,width],[0,width]] |
---|
45 | meshname = 'slide.msh' |
---|
46 | |
---|
47 | |
---|
48 | from caching import cache |
---|
49 | _ = cache(create_mesh_from_regions, |
---|
50 | bounding_polygon, |
---|
51 | {'boundary_tags': {'bottom': [0], 'right': [1], |
---|
52 | 'top': [2], 'left': [3]}, |
---|
53 | 'maximum_triangle_area': project.remainder_res, |
---|
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 | |
---|
68 | domain.set_datadir(project.output_run_time_dir) |
---|
69 | domain.set_name(project.sww_name) |
---|
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 |
---|
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) |
---|
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 |
---|
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, |
---|
93 | alpha = 0.1 #inclination of domain from strike plane |
---|
94 | ) |
---|
95 | |
---|
96 | #------------------------------------------------------------------------------- |
---|
97 | # Set up scenario (tsunami_source is a callable object used with set_quantity) |
---|
98 | #------------------------------------------------------------------------------- |
---|
99 | from smf import slide_tsunami |
---|
100 | from math import atan, degrees |
---|
101 | |
---|
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) |
---|
106 | slope=degrees(atan(0.5)), |
---|
107 | thickness=a, #slide thickness |
---|
108 | x0=0.75, |
---|
109 | y0=width/2, |
---|
110 | alpha=0., |
---|
111 | #dx=0.001, |
---|
112 | domain=domain, |
---|
113 | verbose=True) |
---|
114 | |
---|
115 | #------------------------------------------------------------------------------- |
---|
116 | # Setup boundary conditions |
---|
117 | #------------------------------------------------------------------------------- |
---|
118 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
119 | |
---|
120 | Br = Reflective_boundary(domain) |
---|
121 | Bd = Dirichlet_boundary([0,0,0]) |
---|
122 | |
---|
123 | domain.set_boundary( {'top': Bd, 'bottom': Bd, 'right': Bd, 'left': Bd} ) |
---|
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() |
---|
134 | finaltime = 500 |
---|
135 | for t in domain.evolve(yieldstep = 1, finaltime = project.finaltime): |
---|
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' |
---|