1 | """Script for running a dam break simulation of U of Aberdeen'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 | |
---|
25 | |
---|
26 | #import pypar |
---|
27 | |
---|
28 | # Related major packages |
---|
29 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
30 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
31 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
32 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
33 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \ |
---|
34 | copy_code_files |
---|
35 | |
---|
36 | |
---|
37 | # Scenario specific imports |
---|
38 | import project # Definition of file names and polygons |
---|
39 | import create_mesh |
---|
40 | |
---|
41 | |
---|
42 | def main(friction, outputdir_name=None, is_trial_run=False): |
---|
43 | basename = 'zz' + str(friction) |
---|
44 | if is_trial_run is True: |
---|
45 | outputdir_name += '_test' |
---|
46 | yieldstep = 1 |
---|
47 | finaltime = 31 |
---|
48 | else: |
---|
49 | yieldstep = 0.01 |
---|
50 | finaltime = 31 |
---|
51 | |
---|
52 | |
---|
53 | # rank = pypar.rank() #My id |
---|
54 | # if 0 == rank: |
---|
55 | # pro_instance = project.Project(['data','flumes','dam_2006'], |
---|
56 | # outputdir_name=outputdir_name) |
---|
57 | # else: |
---|
58 | # # wait for a bit..I don't know if I need this |
---|
59 | # for i in range(500): |
---|
60 | # pass |
---|
61 | # pro_instance = project.Project(['data','flumes','dam_2006'], |
---|
62 | # outputdir_name=outputdir_name) |
---|
63 | |
---|
64 | pro_instance = project.Project(['data','flumes','dam_2006'], |
---|
65 | outputdir_name=outputdir_name) |
---|
66 | mesh_filename = pro_instance.meshdir + basename + '.msh' |
---|
67 | |
---|
68 | #-------------------------------------------------------------------------- |
---|
69 | # Copy scripts to output directory and capture screen |
---|
70 | # output to file |
---|
71 | #-------------------------------------------------------------------------- |
---|
72 | |
---|
73 | # creates copy of code in output dir |
---|
74 | print "The output dir is", pro_instance.outputdir |
---|
75 | copy_code_files(pro_instance.outputdir,__file__, |
---|
76 | dirname(project.__file__) \ |
---|
77 | + sep + project.__name__+'.py') |
---|
78 | copy (pro_instance.codedir + 'run_dam.py', |
---|
79 | pro_instance.outputdir + 'run_dam' + str(friction)+ '.py') |
---|
80 | copy (pro_instance.codedir + 'create_mesh.py', |
---|
81 | pro_instance.outputdir + 'create_mesh.py') |
---|
82 | if is_trial_run is False: |
---|
83 | start_screen_catcher(pro_instance.outputdir, int(friction*100)) |
---|
84 | |
---|
85 | print 'USER: ', pro_instance.user |
---|
86 | #------------------------------------------------------------------------- |
---|
87 | # Create the triangular mesh |
---|
88 | #------------------------------------------------------------------------- |
---|
89 | |
---|
90 | gate_position = 12.0 |
---|
91 | create_mesh.generate(mesh_filename, |
---|
92 | gate_position, |
---|
93 | is_coarse=is_trial_run) # this creates the mesh |
---|
94 | |
---|
95 | head,tail = path.split(mesh_filename) |
---|
96 | copy (mesh_filename, |
---|
97 | pro_instance.outputdir + tail ) |
---|
98 | #------------------------------------------------------------------------- |
---|
99 | # Setup computational domain |
---|
100 | #------------------------------------------------------------------------- |
---|
101 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
102 | |
---|
103 | |
---|
104 | print 'Number of triangles = ', len(domain) |
---|
105 | print 'The extent is ', domain.get_extent() |
---|
106 | print domain.statistics() |
---|
107 | |
---|
108 | |
---|
109 | domain.set_name(basename) |
---|
110 | domain.set_datadir(pro_instance.outputdir) |
---|
111 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
112 | domain.set_minimum_storable_height(0.01) |
---|
113 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
114 | |
---|
115 | #------------------------------------------------------------------------- |
---|
116 | # Setup initial conditions |
---|
117 | #------------------------------------------------------------------------- |
---|
118 | |
---|
119 | domain.set_quantity('stage', 0.0) |
---|
120 | domain.set_quantity('friction', friction) |
---|
121 | domain.set_quantity('elevation',0.0) |
---|
122 | |
---|
123 | domain.set_quantity('elevation', filename = 'elevation.xya', |
---|
124 | alpha = 10.0,verbose = True, use_cache = True) |
---|
125 | |
---|
126 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
127 | domain.set_region('dam','stage',0.6, |
---|
128 | location = 'unique vertices') |
---|
129 | #domain.set_region(Set_region('dam','stage',0.2, |
---|
130 | # location = 'unique vertices')) |
---|
131 | |
---|
132 | Br = Reflective_boundary(domain) |
---|
133 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
134 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
135 | |
---|
136 | #------------------------------------------------------------------------- |
---|
137 | # Evolve system through time |
---|
138 | #------------------------------------------------------------------------- |
---|
139 | t0 = time.time() |
---|
140 | |
---|
141 | for t in domain.evolve(yieldstep, finaltime): |
---|
142 | domain.write_time() |
---|
143 | |
---|
144 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
145 | print 'finished' |
---|
146 | |
---|
147 | points = [[2.8,0.225], #-1.8m from SWL |
---|
148 | [5.1,0.225], #0.5m from SWL |
---|
149 | [6.6,0.225], #2m from SWL |
---|
150 | [6.95,0.255], #2.35m from SWL |
---|
151 | [7.6,0.255], #3m from SWL |
---|
152 | [8.1,0.255], #3.5m from SWL |
---|
153 | [9.1,0.255] #4.5m from SWL |
---|
154 | ] |
---|
155 | |
---|
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 | |
---|
163 | #------------------------------------------------------------------------- |
---|
164 | # Calculate gauge info |
---|
165 | #------------------------------------------------------------------------- |
---|
166 | |
---|
167 | interpolate_sww2csv(pro_instance.outputdir + basename +".sww", |
---|
168 | points, |
---|
169 | pro_instance.outputdir + "depth_manning_"+str(friction)+".csv", |
---|
170 | pro_instance.outputdir + "velocity_x.csv", |
---|
171 | pro_instance.outputdir + "velocity_y.csv") |
---|
172 | |
---|
173 | return pro_instance |
---|
174 | |
---|
175 | #------------------------------------------------------------- |
---|
176 | if __name__ == "__main__": |
---|
177 | # rank = pypar.rank() #My id |
---|
178 | # size = pypar.size() #Number of MPI processes |
---|
179 | # node = pypar.get_processor_name() |
---|
180 | # frictions = [0.0, 0.01, 0.0125] |
---|
181 | # for i, friction in enumerate(frictions): |
---|
182 | # if i%size == rank: |
---|
183 | # print "I am processor %d of %d on node %s" %(rank, size, node) |
---|
184 | # #main(friction, is_trial_run = True, outputdir_name='friction_UA') |
---|
185 | |
---|
186 | frictions = [0.04] |
---|
187 | for i, friction in enumerate(frictions): |
---|
188 | main(friction, is_trial_run = False, outputdir_name='friction_UA_2') |
---|
189 | |
---|
190 | # 0.0 -15 |
---|
191 | # 0.01 - |
---|
192 | # 0.0125 -8 |
---|
193 | # 0.015 |
---|
194 | # 0.016 - 1 |
---|
195 | # 0.017 |
---|
196 | # 0.018 - 9 |
---|
197 | # 0.019 |
---|
198 | # 0.02 - 4 |
---|
199 | # 0.0225 - 1 |
---|
200 | # 0.025 - 4 |
---|
201 | # 0.0275 - 17 |
---|
202 | # 0.03 |
---|
203 | # 0.0325 - 17 |
---|
204 | # 0.035 - 10 |
---|
205 | # 0.0375 |
---|
206 | # 0.04 |
---|
207 | |
---|
208 | #Let's do it again..friction_UA_2 |
---|
209 | # 0.017 -15 |
---|
210 | # 0.02 |
---|
211 | # 0.015 -8 |
---|
212 | # 0.019 |
---|
213 | # 0.0225 -1 |
---|
214 | # 0.03 |
---|
215 | # 0.04 -9 |
---|