1 | """ |
---|
2 | |
---|
3 | Script for running a breaking wave simulation of Jon Hinwoods wave tank. |
---|
4 | Note: this is based on the frinction_ua_flume_2006 structure. |
---|
5 | |
---|
6 | |
---|
7 | Duncan Gray, GA - 2007 |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | """ |
---|
12 | |
---|
13 | |
---|
14 | #---------------------------------------------------------------------------- |
---|
15 | # Import necessary modules |
---|
16 | #---------------------------------------------------------------------------- |
---|
17 | |
---|
18 | # Standard modules |
---|
19 | import time |
---|
20 | from time import localtime, strftime |
---|
21 | import sys |
---|
22 | from shutil import copy |
---|
23 | from os import path, sep |
---|
24 | from os.path import dirname #, basename |
---|
25 | from math import sin, pi |
---|
26 | |
---|
27 | # Related major packages |
---|
28 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
29 | Dirichlet_boundary, Time_boundary, \ |
---|
30 | File_boundary, \ |
---|
31 | Transmissive_Momentum_Set_Stage_boundary |
---|
32 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
33 | from anuga.abstract_2d_finite_volumes.util import copy_code_files, \ |
---|
34 | file_function |
---|
35 | |
---|
36 | from anuga.shallow_water.data_manager import start_screen_catcher |
---|
37 | |
---|
38 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\ |
---|
39 | import File_boundary_time |
---|
40 | |
---|
41 | # Scenario specific imports |
---|
42 | import project # Definition of file names and polygons |
---|
43 | import create_mesh |
---|
44 | |
---|
45 | def elevation_function(x,y): |
---|
46 | from Numeric import zeros, size, Float |
---|
47 | |
---|
48 | z = zeros(size(x), Float) |
---|
49 | for i in range(len(x)): |
---|
50 | if x[i] <= 0: |
---|
51 | # swash |
---|
52 | z[i] = -0.05*x[i] |
---|
53 | #z[i] = -30 |
---|
54 | elif x[i] <= 1000: |
---|
55 | # surf |
---|
56 | z[i] = -0.15*(x[i]**(0.5)) |
---|
57 | #z[i] = -30 |
---|
58 | else: |
---|
59 | # Nominal shoreface |
---|
60 | z[i] = -0.01888*(x[i]**(0.8)) |
---|
61 | #z[i] = -30 |
---|
62 | #>>> -0.15*(1000**0.5) |
---|
63 | #-4.7434164902525691 |
---|
64 | |
---|
65 | #>>> 0.01888*(1000**0.8) |
---|
66 | #4.7424415826900885 |
---|
67 | |
---|
68 | #>>> -0.01888*10000**0.8 |
---|
69 | #-29.922783473665834 |
---|
70 | return z |
---|
71 | |
---|
72 | def main(friction=0.01, outputdir_name=None, is_trial_run=False): |
---|
73 | basename = 'zz' + str(friction) |
---|
74 | if is_trial_run is True: |
---|
75 | outputdir_name += '_test' |
---|
76 | yieldstep = 1 |
---|
77 | finaltime = 100. |
---|
78 | maximum_triangle_area=3000 |
---|
79 | thinner=True |
---|
80 | else: |
---|
81 | yieldstep = 1. |
---|
82 | finaltime = 1600 |
---|
83 | finaltime = 100 |
---|
84 | maximum_triangle_area = 100 |
---|
85 | thinner=True |
---|
86 | |
---|
87 | |
---|
88 | pro_instance = project.Project(['results'], |
---|
89 | outputdir_name=outputdir_name, |
---|
90 | home='.') |
---|
91 | print "The output dir is", pro_instance.outputdir |
---|
92 | copy_code_files(pro_instance.outputdir,__file__, |
---|
93 | dirname(project.__file__) \ |
---|
94 | + sep + project.__name__+'.py') |
---|
95 | copy (pro_instance.codedir + 'run_beach.py', |
---|
96 | pro_instance.outputdir + 'run_beach.py') |
---|
97 | copy (pro_instance.codedir + 'create_mesh.py', |
---|
98 | pro_instance.outputdir + 'create_mesh.py') |
---|
99 | |
---|
100 | #mesh_filename = pro_instance.meshdir + basename + '.tsh' |
---|
101 | mesh_filename = pro_instance.meshdir + basename + '.msh' |
---|
102 | |
---|
103 | #-------------------------------------------------------------------------- |
---|
104 | # Copy scripts to output directory and capture screen |
---|
105 | # output to file |
---|
106 | #-------------------------------------------------------------------------- |
---|
107 | |
---|
108 | # creates copy of code in output dir |
---|
109 | if is_trial_run is False: |
---|
110 | start_screen_catcher(pro_instance.outputdir) #, rank, pypar.size()) |
---|
111 | |
---|
112 | print 'USER: ', pro_instance.user |
---|
113 | #------------------------------------------------------------------------- |
---|
114 | # Create the triangular mesh |
---|
115 | #------------------------------------------------------------------------- |
---|
116 | |
---|
117 | # this creates the mesh |
---|
118 | #gate_position = 12.0 |
---|
119 | create_mesh.generate(mesh_filename, |
---|
120 | maximum_triangle_area=maximum_triangle_area, |
---|
121 | thinner=thinner) |
---|
122 | |
---|
123 | head,tail = path.split(mesh_filename) |
---|
124 | copy (mesh_filename, |
---|
125 | pro_instance.outputdir + tail ) |
---|
126 | #------------------------------------------------------------------------- |
---|
127 | # Setup computational domain |
---|
128 | #------------------------------------------------------------------------- |
---|
129 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
130 | |
---|
131 | |
---|
132 | print 'Number of triangles = ', len(domain) |
---|
133 | print 'The extent is ', domain.get_extent() |
---|
134 | print domain.statistics() |
---|
135 | |
---|
136 | |
---|
137 | domain.set_name(basename) |
---|
138 | domain.set_datadir(pro_instance.outputdir) |
---|
139 | domain.set_default_order(2) # Use second order spatial scheme |
---|
140 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
141 | domain.set_minimum_storable_height(0.001) |
---|
142 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
143 | |
---|
144 | #------------------------------------------------------------------------- |
---|
145 | # Setup initial conditions |
---|
146 | #------------------------------------------------------------------------- |
---|
147 | |
---|
148 | domain.set_quantity('stage', 0.0) |
---|
149 | domain.set_quantity('friction', friction) |
---|
150 | domain.set_quantity('elevation', elevation_function) |
---|
151 | |
---|
152 | |
---|
153 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
154 | |
---|
155 | # Create boundary function from timeseries provided in file |
---|
156 | #function = file_function(project.boundary_file, domain, verbose=True) |
---|
157 | #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) |
---|
158 | Br = Reflective_boundary(domain) |
---|
159 | Bd = Dirichlet_boundary([10.,0,0]) |
---|
160 | Bwp = Transmissive_Momentum_Set_Stage_boundary(domain, |
---|
161 | lambda t: [(1.2*sin(2*t*pi/10)), 0.0 ,0.0]) |
---|
162 | Bwp_velocity = Time_boundary(domain, |
---|
163 | lambda t: [(1.2*sin(2*t*pi/10)), |
---|
164 | 0.24*sin(2*t*pi/10),0.0]) |
---|
165 | Bws = Transmissive_Momentum_Set_Stage_boundary(domain, |
---|
166 | lambda t: [1.2*sin(2*t*pi/10)+1.0*sin(2*t*pi/9.5), |
---|
167 | 0.0, 0.0]) |
---|
168 | domain.set_boundary( {'wall': Br, 'wave': Bwp} ) |
---|
169 | |
---|
170 | #------------------------------------------------------------------------- |
---|
171 | # Evolve system through time |
---|
172 | #------------------------------------------------------------------------- |
---|
173 | t0 = time.time() |
---|
174 | |
---|
175 | for t in domain.evolve(yieldstep, finaltime): |
---|
176 | domain.write_time() |
---|
177 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
178 | print 'finished' |
---|
179 | |
---|
180 | #------------------------------------------------------------------------- |
---|
181 | # Calculate gauge info |
---|
182 | #------------------------------------------------------------------------- |
---|
183 | |
---|
184 | |
---|
185 | return pro_instance |
---|
186 | |
---|
187 | #------------------------------------------------------------- |
---|
188 | if __name__ == "__main__": |
---|
189 | main( is_trial_run = False, friction=0.0, |
---|
190 | outputdir_name='Primary_wave_2nd_order') |
---|