source: trunk/anuga_work/development/attenuation_near_shore/run_beach_structured.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: 6.9 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
35
36from anuga.shallow_water.data_manager import start_screen_catcher
37
38from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
39     import File_boundary_time
40
41# Scenario specific imports
42import project                 # Definition of file names and polygons
43import create_mesh
44
45def 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
72def 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.0
82        finaltime = 1600
83        finaltime = 1000
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        pass
111        #start_screen_catcher(pro_instance.outputdir) #, rank, pypar.size())
112
113    print 'USER:    ', pro_instance.user
114    #-------------------------------------------------------------------------
115    # Create the triangular mesh
116    #-------------------------------------------------------------------------
117
118    # this creates the mesh
119    #gate_position = 12.0
120    #create_mesh.generate(mesh_filename,
121    #                     maximum_triangle_area=maximum_triangle_area,
122    #                     thinner=thinner)
123
124    head,tail = path.split(mesh_filename)
125    #copy (mesh_filename,
126    #      pro_instance.outputdir + tail )
127    #-------------------------------------------------------------------------
128    # Setup computational domain
129    #-------------------------------------------------------------------------
130    #domain = Domain(mesh_filename, use_cache = False, verbose = True)
131    domain = create_mesh.generate_structured()
132   
133
134    print 'Number of triangles = ', len(domain)
135    print 'The extent is ', domain.get_extent()
136    print domain.statistics()
137
138   
139    domain.set_name(basename)
140    domain.set_datadir(pro_instance.outputdir)
141    domain.set_default_order(2) # Use second order spatial scheme
142
143    domain.set_timestepping_method('rk2')
144    domain.set_default_order(2)
145    domain.use_edge_limiter = True
146    domain.tight_slope_limiters = True
147   
148    domain.beta_w      = 0.6
149    domain.beta_uh     = 0.6
150    domain.beta_vh     = 0.6
151
152    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
153    domain.set_minimum_storable_height(0.001)
154    domain.set_store_vertices_uniquely(True)  # for writting to sww
155
156    #-------------------------------------------------------------------------
157    # Setup initial conditions
158    #-------------------------------------------------------------------------
159
160    domain.set_quantity('stage', 0.0)
161    domain.set_quantity('friction', friction) 
162    domain.set_quantity('elevation', elevation_function)
163
164   
165    print 'Available boundary tags', domain.get_boundary_tags()
166
167    # Create boundary function from timeseries provided in file
168    #function = file_function(project.boundary_file, domain, verbose=True)
169    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
170    Br = Reflective_boundary(domain)
171    Bd = Dirichlet_boundary([10.,0,0])
172    Bwp = Transmissive_Momentum_Set_Stage_boundary(domain,
173                   lambda t: [(1.2*sin(2*t*pi/500)), 0.0 ,0.0])
174    Bwp_velocity = Time_boundary(domain,
175                   lambda t: [(1.2*sin(2*t*pi/10)),
176                              0.24*sin(2*t*pi/10),0.0])
177    Bws = Transmissive_Momentum_Set_Stage_boundary(domain,
178                   lambda t: [1.2*sin(2*t*pi/100),
179                              0.0, 0.0])
180    #domain.set_boundary( {'wall': Br, 'wave': Bwp_velocity} )
181    domain.set_boundary( {'top': Br, 'bottom': Br , 'left' : Br , 'right' : Bws } )
182
183    #-------------------------------------------------------------------------
184    # Evolve system through time
185    #-------------------------------------------------------------------------
186    t0 = time.time()
187
188    for t in domain.evolve(yieldstep, finaltime):   
189        domain.write_time()
190    print 'That took %.2f seconds' %(time.time()-t0)
191    print 'finished'
192
193    #-------------------------------------------------------------------------
194    # Calculate gauge info
195    #-------------------------------------------------------------------------
196
197 
198    return pro_instance
199
200#-------------------------------------------------------------
201if __name__ == "__main__":
202    main( is_trial_run = False, friction=0.0,
203         outputdir_name='Velocity_wave_2nd_order')
Note: See TracBrowser for help on using the repository browser.