source: anuga_work/development/Hinwood_2008/run_dam.py @ 5076

Last change on this file since 5076 was 5076, checked in by duncan, 16 years ago

Adding draft flume tank in preparation to see Hinwood

File size: 6.3 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
25
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 start_screen_catcher, \
34     copy_code_files, file_function
35from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
36     import File_boundary_time
37
38# Scenario specific imports
39import project                 # Definition of file names and polygons
40import create_mesh
41
42def elevation_function(x,y):
43    from Numeric import zeros, size, Float
44    slope = 4 ## Bit of a magic Number
45   
46    z = zeros(size(x), Float)
47    for i in range(len(x)):
48        if x[i] < slope:
49            z[i] = 0.0  #WARNING: the code in prepare_time_boundary
50                        # that calc's momentum assumes this is 0.0
51        else:
52            z[i] = (x[i]-slope)*0.1
53    return z
54
55def main(friction=0.01, outputdir_name=None, is_trial_run=False):
56    basename = 'zz' + str(friction)
57    if is_trial_run is True:
58        outputdir_name += '_test'
59        yieldstep = 0.1
60        finaltime = 15.
61        maximum_triangle_area=0.01
62    else:
63        yieldstep = 0.02
64        finaltime = 15.1
65        maximum_triangle_area=0.0001
66       
67        maximum_triangle_area=0.001
68       
69    pro_instance = project.Project(['data','flumes','Hinwood_2008'],
70                                   outputdir_name=outputdir_name,
71                                   home='.')
72    print "The output dir is", pro_instance.outputdir
73    copy_code_files(pro_instance.outputdir,__file__,
74                    dirname(project.__file__) \
75                    + sep + project.__name__+'.py')
76    copy (pro_instance.codedir + 'run_dam.py',
77          pro_instance.outputdir + 'run_dam.py')
78    copy (pro_instance.codedir + 'create_mesh.py',
79          pro_instance.outputdir + 'create_mesh.py')
80   
81    mesh_filename = pro_instance.meshdir + basename + '.msh'
82
83    #--------------------------------------------------------------------------
84    # Copy scripts to output directory and capture screen
85    # output to file
86    #--------------------------------------------------------------------------
87
88    # creates copy of code in output dir
89    if is_trial_run is False:
90        start_screen_catcher(pro_instance.outputdir, rank, pypar.size())
91
92    print 'USER:    ', pro_instance.user
93    #-------------------------------------------------------------------------
94    # Create the triangular mesh
95    #-------------------------------------------------------------------------
96
97    # this creates the mesh
98    #gate_position = 12.0
99    create_mesh.generate(mesh_filename,
100                         maximum_triangle_area=maximum_triangle_area)
101
102    head,tail = path.split(mesh_filename)
103    copy (mesh_filename,
104          pro_instance.outputdir + tail )
105    #-------------------------------------------------------------------------
106    # Setup computational domain
107    #-------------------------------------------------------------------------
108    domain = Domain(mesh_filename, use_cache = False, verbose = True)
109   
110
111    print 'Number of triangles = ', len(domain)
112    print 'The extent is ', domain.get_extent()
113    print domain.statistics()
114
115   
116    domain.set_name(basename)
117    domain.set_datadir(pro_instance.outputdir)
118    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
119    domain.set_minimum_storable_height(0.001)
120    #domain.set_store_vertices_uniquely(True)  # for writting to sww
121
122    #-------------------------------------------------------------------------
123    # Setup initial conditions
124    #-------------------------------------------------------------------------
125
126    domain.set_quantity('stage', 0.06)
127    domain.set_quantity('friction', friction) 
128    domain.set_quantity('elevation', elevation_function)
129
130   
131    print 'Available boundary tags', domain.get_boundary_tags()
132
133    # Create boundary function from timeseries provided in file
134    #function = file_function(project.boundary_file, domain, verbose=True)
135    #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
136
137    function = file_function(project.boundary_file, domain, verbose=True)
138    Br = Reflective_boundary(domain)
139    #Bd = Dirichlet_boundary([0.3,0,0])
140    Bts = Time_boundary(domain, function)
141    domain.set_boundary( {'wall': Br, 'wave': Bts} )
142
143    #-------------------------------------------------------------------------
144    # Evolve system through time
145    #-------------------------------------------------------------------------
146    t0 = time.time()
147
148    for t in domain.evolve(yieldstep, finaltime):
149   
150        domain.write_time()
151        print 'That took %.2f seconds' %(time.time()-t0)
152        print 'finished'
153
154    points = [[2.8,0.225],  #-1.8m from SWL
155              [5.1,0.225],  #0.5m from SWL
156              [6.6,0.225],  #2m from SWL
157              [6.95,0.255], #2.35m from SWL
158              [7.6,0.255],  #3m from SWL
159              [8.2,0.255],  #3.5m from SWL
160              [9.2,0.255]  #4.5m from SWL
161              ]
162
163
164    #-------------------------------------------------------------------------
165    # Calculate gauge info
166    #-------------------------------------------------------------------------
167
168    if False:
169        interpolate_sww2csv(pro_instance.outputdir + basename +".sww",
170                            points,
171                            pro_instance.outputdir + "depth_manning_"+str(friction)+".csv",
172                            pro_instance.outputdir + "velocity_x.csv",
173                            pro_instance.outputdir + "velocity_y.csv")
174 
175    return pro_instance
176
177#-------------------------------------------------------------
178if __name__ == "__main__":
179    main( is_trial_run = True,
180         outputdir_name='Hinwood_draft')
Note: See TracBrowser for help on using the repository browser.