source: trunk/anuga_work/development/attenuation_near_shore/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: 6.5 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.
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_timestepping_method('rk2')
141    domain.beta_uh     = 1.5
142    domain.beta_vh     = 1.5
143    # comment out aserts in shallow_water/shallow_water_domain.py", line 402
144    # if you want to use these values
145    #domain.beta_w      = 1.5
146    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
147    domain.set_minimum_storable_height(0.001)
148    #domain.set_store_vertices_uniquely(True)  # for writting to sww
149
150    #-------------------------------------------------------------------------
151    # Setup initial conditions
152    #-------------------------------------------------------------------------
153
154    domain.set_quantity('stage', 0.0)
155    domain.set_quantity('friction', friction) 
156    domain.set_quantity('elevation', elevation_function)
157
158   
159    print 'Available boundary tags', domain.get_boundary_tags()
160
161    # Create boundary function from timeseries provided in file
162    #function = file_function(project.boundary_file, domain, verbose=True)
163    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
164    Br = Reflective_boundary(domain)
165    Bd = Dirichlet_boundary([10.,0,0])
166    Bwp = Transmissive_Momentum_Set_Stage_boundary(domain,
167                   lambda t: [(1.2*sin(2*t*pi/10)), 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#-------------------------------------------------------------
188if __name__ == "__main__":
189    main( is_trial_run = False, friction=0.0,
190         outputdir_name='Primary_wave_2nd_order_rk2_wet_betas_1.5')
Note: See TracBrowser for help on using the repository browser.