1 | """Script for running a dam break simulation of UQ's dam break tank. |
---|
2 | |
---|
3 | |
---|
4 | Ole Nielsen and Duncan Gray, GA - 2006 |
---|
5 | |
---|
6 | |
---|
7 | Issues |
---|
8 | If running this is hand-set-up parallel, the python files are overwritten. |
---|
9 | |
---|
10 | """ |
---|
11 | |
---|
12 | |
---|
13 | #---------------------------------------------------------------------------- |
---|
14 | # Import necessary modules |
---|
15 | #---------------------------------------------------------------------------- |
---|
16 | |
---|
17 | # Standard modules |
---|
18 | import time |
---|
19 | from time import localtime, strftime |
---|
20 | import sys |
---|
21 | from shutil import copy |
---|
22 | from os import path, sep |
---|
23 | from os.path import dirname #, basename |
---|
24 | from math import tan, radians |
---|
25 | |
---|
26 | # Related major packages |
---|
27 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
28 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
29 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
30 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
31 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \ |
---|
32 | copy_code_files |
---|
33 | |
---|
34 | |
---|
35 | # Scenario specific imports |
---|
36 | import project # Definition of file names and polygons |
---|
37 | import create_mesh |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | def main(friciton,beach_angle, toe_to_nails_distance, |
---|
42 | outputdir_name=None, is_trial_run=False): |
---|
43 | """ |
---|
44 | beach angle is the angle in degrees of the sloped section |
---|
45 | toe_to_nails_distance is the distance from the beginning if the sloped |
---|
46 | section to the beginning of the nails section |
---|
47 | """ |
---|
48 | basename = 'zz' + str(friction) |
---|
49 | if is_trial_run is True: |
---|
50 | outputdir_name += '_test' |
---|
51 | yieldstep = 0.1 |
---|
52 | finaltime = 4 |
---|
53 | else: |
---|
54 | yieldstep = 0.01 |
---|
55 | finaltime = 31 |
---|
56 | pro_instance = project.Project(['data','flumes','saman_2007'], |
---|
57 | outputdir_name=outputdir_name) |
---|
58 | mesh_filename = pro_instance.meshdir + basename + '.msh' |
---|
59 | |
---|
60 | #-------------------------------------------------------------------------- |
---|
61 | # Copy scripts to output directory and capture screen |
---|
62 | # output to file |
---|
63 | #-------------------------------------------------------------------------- |
---|
64 | |
---|
65 | # creates copy of code in output dir |
---|
66 | print "The output dir is", pro_instance.outputdir |
---|
67 | copy_code_files(pro_instance.outputdir,__file__, |
---|
68 | dirname(project.__file__) \ |
---|
69 | + sep + project.__name__+'.py') |
---|
70 | copy (pro_instance.codedir + 'run_dam.py', |
---|
71 | pro_instance.outputdir + 'run_dam' + str(friction)+ '.py') |
---|
72 | copy (pro_instance.codedir + 'create_mesh.py', |
---|
73 | pro_instance.outputdir + 'create_mesh.py') |
---|
74 | copy (pro_instance.codedir + 'project.py', |
---|
75 | pro_instance.outputdir + 'project.py') |
---|
76 | if is_trial_run is False: |
---|
77 | start_screen_catcher(pro_instance.outputdir, int(friction*100)) |
---|
78 | |
---|
79 | print 'USER: ', pro_instance.user |
---|
80 | #------------------------------------------------------------------------- |
---|
81 | # Create the triangular mesh |
---|
82 | #------------------------------------------------------------------------- |
---|
83 | |
---|
84 | #beach_angle = 15.0 |
---|
85 | #toe_to_nails_distance = .5 |
---|
86 | create_mesh.generate(mesh_filename, |
---|
87 | beach_angle, |
---|
88 | toe_to_nails_distance, |
---|
89 | is_coarse=is_trial_run) # this creates the mesh |
---|
90 | |
---|
91 | head,tail = path.split(mesh_filename) |
---|
92 | copy (mesh_filename, |
---|
93 | pro_instance.outputdir + tail ) |
---|
94 | #------------------------------------------------------------------------- |
---|
95 | # Setup computational domain |
---|
96 | #------------------------------------------------------------------------- |
---|
97 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
98 | |
---|
99 | |
---|
100 | print 'Number of triangles = ', len(domain) |
---|
101 | print 'The extent is ', domain.get_extent() |
---|
102 | print domain.statistics() |
---|
103 | |
---|
104 | |
---|
105 | domain.set_name(basename) |
---|
106 | domain.set_datadir(pro_instance.outputdir) |
---|
107 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
108 | domain.set_minimum_storable_height(0.01) |
---|
109 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
110 | |
---|
111 | |
---|
112 | def elevation_function(x,y): |
---|
113 | from Numeric import zeros, size, Float |
---|
114 | slope = create_mesh.xslope |
---|
115 | |
---|
116 | z = zeros(size(x), Float) |
---|
117 | for i in range(len(x)): |
---|
118 | if x[i] < slope: |
---|
119 | z[i] = 0.0 |
---|
120 | else: |
---|
121 | z[i] = (x[i]-slope)*tan(radians(beach_angle)) |
---|
122 | return z |
---|
123 | |
---|
124 | #------------------------------------------------------------------------- |
---|
125 | # Setup initial conditions |
---|
126 | #------------------------------------------------------------------------- |
---|
127 | |
---|
128 | domain.set_quantity('stage', elevation_function) |
---|
129 | domain.set_quantity('friction', friciton) |
---|
130 | domain.set_quantity('elevation', elevation_function) |
---|
131 | |
---|
132 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
133 | domain.set_region('dam','stage',0.30, |
---|
134 | location = 'unique vertices') |
---|
135 | |
---|
136 | Br = Reflective_boundary(domain) |
---|
137 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
138 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
139 | |
---|
140 | #------------------------------------------------------------------------- |
---|
141 | # Evolve system through time |
---|
142 | #------------------------------------------------------------------------- |
---|
143 | t0 = time.time() |
---|
144 | |
---|
145 | for t in domain.evolve(yieldstep, finaltime): |
---|
146 | domain.write_time() |
---|
147 | |
---|
148 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
149 | print 'finished' |
---|
150 | |
---|
151 | |
---|
152 | #------------------------------------------------------------------------- |
---|
153 | # Calculate gauge info |
---|
154 | #------------------------------------------------------------------------- |
---|
155 | if not is_trial_run: |
---|
156 | points = [[gate_position - 0.65,0.2], |
---|
157 | [gate_position - 0.55,0.2], |
---|
158 | [gate_position - 0.45,0.2], |
---|
159 | [gate_position - 0.35,0.2], |
---|
160 | [gate_position - 0.25,0.2] |
---|
161 | ] |
---|
162 | interpolate_sww2csv(pro_instance.outputdir + basename +".sww", |
---|
163 | points, |
---|
164 | pro_instance.outputdir + \ |
---|
165 | "depth_manning_"+str(friction)+".csv", |
---|
166 | pro_instance.outputdir + "velocity_x.csv", |
---|
167 | pro_instance.outputdir + "velocity_y.csv") |
---|
168 | |
---|
169 | return pro_instance |
---|
170 | |
---|
171 | #------------------------------------------------------------- |
---|
172 | if __name__ == "__main__": |
---|
173 | beach_angle = 3.0 |
---|
174 | toe_to_nails_distance = 0.1 |
---|
175 | for friction in [0.0,0.01]: |
---|
176 | main(friction,beach_angle, toe_to_nails_distance, |
---|
177 | is_trial_run = True, outputdir_name='testing') |
---|
178 | |
---|