source: anuga_work/development/attenuation_near_shore/run_beach_structured.py @ 5176

Last change on this file since 5176 was 5176, checked in by steve, 16 years ago

Edge limiter needed protection from small values of h

File size: 6.9 KB
RevLine 
[5161]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:
[5176]81        yieldstep = 1.0
[5161]82        finaltime = 1600
[5176]83        finaltime = 1000
[5161]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)
[5166]125    #copy (mesh_filename,
126    #      pro_instance.outputdir + tail )
[5161]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
[5175]142
[5161]143    domain.set_timestepping_method('rk2')
[5175]144    domain.set_default_order(2)
[5176]145    domain.use_edge_limiter = True
[5175]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    domain.beta_h      = 0.0
152
153
[5161]154    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
155    domain.set_minimum_storable_height(0.001)
156    domain.set_store_vertices_uniquely(True)  # for writting to sww
157
158    #-------------------------------------------------------------------------
159    # Setup initial conditions
160    #-------------------------------------------------------------------------
161
162    domain.set_quantity('stage', 0.0)
163    domain.set_quantity('friction', friction) 
164    domain.set_quantity('elevation', elevation_function)
165
166   
167    print 'Available boundary tags', domain.get_boundary_tags()
168
169    # Create boundary function from timeseries provided in file
170    #function = file_function(project.boundary_file, domain, verbose=True)
171    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
172    Br = Reflective_boundary(domain)
173    Bd = Dirichlet_boundary([10.,0,0])
174    Bwp = Transmissive_Momentum_Set_Stage_boundary(domain,
[5176]175                   lambda t: [(1.2*sin(2*t*pi/500)), 0.0 ,0.0])
[5161]176    Bwp_velocity = Time_boundary(domain,
177                   lambda t: [(1.2*sin(2*t*pi/10)),
178                              0.24*sin(2*t*pi/10),0.0])
179    Bws = Transmissive_Momentum_Set_Stage_boundary(domain,
[5176]180                   lambda t: [1.2*sin(2*t*pi/100),
[5161]181                              0.0, 0.0])
182    #domain.set_boundary( {'wall': Br, 'wave': Bwp_velocity} )
183    domain.set_boundary( {'top': Br, 'bottom': Br , 'left' : Br , 'right' : Bws } )
184
185    #-------------------------------------------------------------------------
186    # Evolve system through time
187    #-------------------------------------------------------------------------
188    t0 = time.time()
189
190    for t in domain.evolve(yieldstep, finaltime):   
191        domain.write_time()
192    print 'That took %.2f seconds' %(time.time()-t0)
193    print 'finished'
194
195    #-------------------------------------------------------------------------
196    # Calculate gauge info
197    #-------------------------------------------------------------------------
198
199 
200    return pro_instance
201
202#-------------------------------------------------------------
203if __name__ == "__main__":
204    main( is_trial_run = False, friction=0.0,
205         outputdir_name='Velocity_wave_2nd_order')
Note: See TracBrowser for help on using the repository browser.