source: trunk/anuga_work/development/near_shore_PMD/run_beach.py @ 7884

Last change on this file since 7884 was 5442, checked in by ole, 16 years ago

Retired h-limiter and beta_h as per ticket:194.
All unit tests and validation tests pass.

File size: 9.2 KB
Line 
1"""
2
3Script for running a breaking wave simulation of Jon Hinwoods wave tank.
4Note: this is based on the frinction_ua_flume_2006 structure.
5
6
7Duncan Gray, GA - 2007
8
9
10
11"""
12
13
14#----------------------------------------------------------------------------
15# Import necessary modules
16#----------------------------------------------------------------------------
17
18# Standard modules
19import time
20from time import localtime, strftime
21import sys
22from shutil import copy
23from os import path, sep
24from os.path import dirname  #, basename
25from math import sin, pi
26
27# Related major packages
28from anuga.shallow_water import Domain, Reflective_boundary, \
29                            Dirichlet_boundary,  Time_boundary, \
30                            File_boundary, \
31                            Transmissive_Momentum_Set_Stage_boundary
32from anuga.fit_interpolate.interpolate import interpolate_sww2csv
33from anuga.abstract_2d_finite_volumes.util import copy_code_files, \
34     file_function
35from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
36 
37
38from anuga.shallow_water.data_manager import start_screen_catcher
39
40from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
41     import File_boundary_time
42
43# Scenario specific imports
44import project                 # Definition of file names and polygons
45import create_mesh
46
47def elevation_function(x,y):
48    from Numeric import zeros, size, Float
49
50    z = zeros(size(x), Float)
51    for i in range(len(x)):
52        if x[i] <= 0:
53            # swash
54            z[i] = -0.05*x[i] 
55            #z[i] = -30
56        elif x[i] <= 1000:
57            # surf
58            z[i] = -0.15*(x[i]**(0.5))
59            #z[i] = -30
60        else:
61            # Nominal shoreface
62            z[i] = -0.01888*(x[i]**(0.8))
63            #z[i] = -30
64            #>>> -0.15*(1000**0.5)
65            #-4.7434164902525691
66
67            #>>> 0.01888*(1000**0.8)
68            #4.7424415826900885
69
70            #>>> -0.01888*10000**0.8
71            #-29.922783473665834
72    return z
73
74def main(friction=0.01, outputdir_name=None,
75         is_structured=False,
76         is_trial_run=False):
77
78    # Structured mesh variables
79    dx = 1.0
80    dy = dx
81    L = 2080.
82    W = dx
83    outputdir_name += '_dx' + str(dx)
84   
85    basename = 'dx_' + str(dx)
86    if is_trial_run is True:
87        outputdir_name += '_test'
88        yieldstep = 1
89        finaltime = 200.
90        maximum_triangle_area=3000
91        thinner=True
92    else:
93        yieldstep = 1.
94        finaltime = 1700 #1600
95        maximum_triangle_area = 100
96        thinner=True
97       
98       
99    pro_instance = project.Project(['data','near_shore_PMD'],
100                                   outputdir_name=outputdir_name)
101    print "The output dir is", pro_instance.outputdir
102    copy_code_files(pro_instance.outputdir,__file__,
103                    dirname(project.__file__) \
104                    + sep + project.__name__+'.py')
105    copy (pro_instance.codedir + 'run_beach.py',
106          pro_instance.outputdir + 'run_beach.py')
107    copy (pro_instance.codedir + 'create_mesh.py',
108          pro_instance.outputdir + 'create_mesh.py')
109   
110    #mesh_filename = pro_instance.meshdir + basename + '.tsh'
111    mesh_filename = pro_instance.meshdir + basename + '.msh'
112
113    #--------------------------------------------------------------------------
114    # Copy scripts to output directory and capture screen
115    # output to file
116    #--------------------------------------------------------------------------
117
118    # creates copy of code in output dir
119    if is_trial_run is False:
120        start_screen_catcher(pro_instance.outputdir) #, rank, pypar.size())
121
122    print 'USER:    ', pro_instance.user
123    #-------------------------------------------------------------------------
124    # Create the triangular mesh
125    #-------------------------------------------------------------------------
126
127    # this creates the mesh
128    #gate_position = 12.0
129    if is_structured is True:
130
131        # Original struc mesh values
132        # dx = 10.
133        # dy = dx
134        # L = 2080.
135        # W = dx
136       
137        # structured mesh
138        points, vertices, boundary = rectangular_cross(
139            int(L/dx), int(W/dy), L, W, (-80.0, -W*0.5))
140
141        domain = Domain(points, vertices, boundary) 
142    else:
143        create_mesh.generate(mesh_filename,
144                             maximum_triangle_area=maximum_triangle_area,
145                             thinner=thinner)
146
147        head,tail = path.split(mesh_filename)
148        copy (mesh_filename,
149              pro_instance.outputdir + tail )
150        domain = Domain(mesh_filename, use_cache = False, verbose = True)
151        domain = Domain(points, vertices, boundary) 
152    #-------------------------------------------------------------------------
153    # Setup computational domain
154    #-------------------------------------------------------------------------
155   
156
157    print 'Number of triangles = ', len(domain)
158    print 'The extent is ', domain.get_extent()
159    print domain.statistics()
160
161   
162    domain.set_name(basename)
163    domain.set_datadir(pro_instance.outputdir)
164    domain.set_default_order(2) # Use second order spatial scheme
165    domain.set_timestepping_method('rk2')
166    domain.set_default_order(2)
167    domain.use_edge_limiter = True
168    domain.tight_slope_limiters = True
169   
170    domain.beta_w      = 0.6
171    domain.beta_uh     = 0.6
172    domain.beta_vh     = 0.6
173
174    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
175    domain.set_minimum_storable_height(0.001)
176    #domain.set_store_vertices_uniquely(True)  # for writting to sww
177
178    #-------------------------------------------------------------------------
179    # Setup initial conditions
180    #-------------------------------------------------------------------------
181
182    domain.set_quantity('stage', 0.0)
183    domain.set_quantity('friction', friction) 
184    domain.set_quantity('elevation', elevation_function)
185
186   
187    print 'Available boundary tags', domain.get_boundary_tags()
188
189    # Create boundary function from timeseries provided in file
190    #function = file_function(project.boundary_file, domain, verbose=True)
191    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
192    Br = Reflective_boundary(domain)
193    Bd = Dirichlet_boundary([10.,0,0])
194
195   
196    def wave_func(t):
197        if t < 100:
198            wave = [(1.2*t/100.0*sin(2*t*pi/10)), 0.0 ,0.0]
199        else:
200            wave = [(1.2*sin(2*t*pi/10)), 0.0 ,0.0]           
201        return wave
202   
203    Bwp = Transmissive_Momentum_Set_Stage_boundary(domain,
204                   wave_func)
205    Bwp_velocity = Time_boundary(domain,
206                   lambda t: [(1.2*sin(2*t*pi/10)),
207                              0.24*sin(2*t*pi/10),0.0])
208    Bws = Transmissive_Momentum_Set_Stage_boundary(domain,
209                   lambda t: [1.2*sin(2*t*pi/10)+1.0*sin(2*t*pi/9.5),
210                              0.0, 0.0])
211   
212    if is_structured is True:
213        domain.set_boundary( {'top': Br,
214                              'bottom': Br ,
215                              'left' : Br ,
216                              'right' : Bwp} )
217    else:
218        domain.set_boundary( {'wall': Br, 'wave': Bwp} )
219
220
221    #-------------------------------------------------------------------------
222    # Evolve system through time
223    #-------------------------------------------------------------------------
224    t0 = time.time()
225
226    for t in domain.evolve(yieldstep, finaltime):   
227        domain.write_time()
228       
229    print 'That took %.2f seconds' %(time.time()-t0)
230    print 'finished'
231
232    points = [[-2,0.0], 
233              [0,0.0], 
234              [1,0.0], 
235              [2,0.0], 
236              [3,0.0], 
237              [4,0.0], 
238              [5,0.0], 
239              [6,0.0], 
240              [7,0.0], 
241              [8,0.0], 
242              [9,0.0],   
243              [10,0.0], 
244              [11,0.0], 
245              [12,0.0], 
246              [13,0.0],   
247              [14,0.0], 
248              [15,0.0], 
249              [16,0.0], 
250              [17,0.0], 
251              [18,0.0],   
252              [1980,0.0], 
253              [1981,0.0], 
254              [1982,0.0], 
255              [1983,0.0], 
256              [1984,0.0], 
257              [1985,0.0], 
258              [1986,0.0], 
259              [1987,0.0], 
260              [1988,0.0], 
261              [1989,0.0],   
262              [1990,0.0], 
263              [1991,0.0], 
264              [1992,0.0], 
265              [1993,0.0],   
266              [1994,0.0], 
267              [1995,0.0], 
268              [1996,0.0], 
269              [1997,0.0], 
270              [1998,0.0], 
271              ]
272
273
274    #-------------------------------------------------------------------------
275    # Calculate gauge info
276    #-------------------------------------------------------------------------
277
278    if True:
279        interpolate_sww2csv(pro_instance.outputdir + basename +".sww",
280                            points,
281                            pro_instance.outputdir + "depth_dx_"+str(dx)+".csv",
282                            pro_instance.outputdir + "velocity_x_dx_"+str(dx)+".csv",
283                            pro_instance.outputdir + "velocity_y_dx_"+str(dx)+".csv")
284 
285    return pro_instance
286
287#-------------------------------------------------------------
288if __name__ == "__main__":
289    main(
290        is_trial_run=False,
291        friction=0.0,
292        is_structured=True,
293        outputdir_name='structured_many_points')
Note: See TracBrowser for help on using the repository browser.