1 | """Script for running a dam break simulation of UQ's dam break tank, |
---|
2 | focusing on a friction comparison. |
---|
3 | |
---|
4 | The simulation will |
---|
5 | form part of the ANUGA validation paper. |
---|
6 | |
---|
7 | Ole Nielsen and Duncan Gray, GA - 2006 |
---|
8 | |
---|
9 | |
---|
10 | Issues |
---|
11 | If running this is hand-set-up parallel, the python files are overwritten. |
---|
12 | |
---|
13 | """ |
---|
14 | |
---|
15 | |
---|
16 | #---------------------------------------------------------------------------- |
---|
17 | # Import necessary modules |
---|
18 | #---------------------------------------------------------------------------- |
---|
19 | |
---|
20 | # Standard modules |
---|
21 | import time |
---|
22 | from time import localtime, strftime |
---|
23 | import sys |
---|
24 | from shutil import copy |
---|
25 | from os import path, sep |
---|
26 | from os.path import dirname #, basename |
---|
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.shallow_water.data_manager 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, is_trial_run=False): |
---|
43 | if is_trial_run is True: |
---|
44 | add = '_test' |
---|
45 | yieldstep = 1 |
---|
46 | finaltime = 31 |
---|
47 | else: |
---|
48 | add = '' |
---|
49 | yieldstep = 0.01 |
---|
50 | finaltime = 31 |
---|
51 | basename = 'zz' + add + str(friction) |
---|
52 | |
---|
53 | mesh_filename = project.mesh_filename + add + '.msh' |
---|
54 | |
---|
55 | #-------------------------------------------------------------------------- |
---|
56 | # Copy scripts to output directory and capture screen |
---|
57 | # output to file |
---|
58 | #-------------------------------------------------------------------------- |
---|
59 | |
---|
60 | |
---|
61 | if is_trial_run is False: |
---|
62 | start_screen_catcher('.', int(friction*100)) |
---|
63 | |
---|
64 | #------------------------------------------------------------------------- |
---|
65 | # Create the triangular mesh |
---|
66 | #------------------------------------------------------------------------- |
---|
67 | |
---|
68 | gate_position = 0.85 |
---|
69 | create_mesh.generate(mesh_filename, |
---|
70 | gate_position, |
---|
71 | is_coarse=is_trial_run) # this creates the mesh |
---|
72 | |
---|
73 | #------------------------------------------------------------------------- |
---|
74 | # Setup computational domain |
---|
75 | #------------------------------------------------------------------------- |
---|
76 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
77 | |
---|
78 | |
---|
79 | print 'Number of triangles = ', len(domain) |
---|
80 | print 'The extent is ', domain.get_extent() |
---|
81 | print domain.statistics() |
---|
82 | |
---|
83 | |
---|
84 | domain.set_name(basename) |
---|
85 | domain.set_datadir('.') |
---|
86 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
87 | domain.set_minimum_storable_height(0.01) |
---|
88 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
89 | |
---|
90 | #------------------------------------------------------------------------- |
---|
91 | # Setup initial conditions |
---|
92 | #------------------------------------------------------------------------- |
---|
93 | |
---|
94 | slope = 0.05 |
---|
95 | |
---|
96 | def elevation_tilt(x, y): |
---|
97 | return x*slope |
---|
98 | |
---|
99 | domain.set_quantity('stage', elevation_tilt) |
---|
100 | domain.set_quantity('friction', friction) |
---|
101 | domain.set_quantity('elevation',elevation_tilt) |
---|
102 | |
---|
103 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
104 | domain.set_region('dam','stage',0.20, |
---|
105 | location = 'unique vertices') |
---|
106 | |
---|
107 | Br = Reflective_boundary(domain) |
---|
108 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
109 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
110 | |
---|
111 | #------------------------------------------------------------------------- |
---|
112 | # Evolve system through time |
---|
113 | #------------------------------------------------------------------------- |
---|
114 | t0 = time.time() |
---|
115 | |
---|
116 | for t in domain.evolve(yieldstep, finaltime): |
---|
117 | domain.write_time() |
---|
118 | |
---|
119 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
120 | print 'finished' |
---|
121 | |
---|
122 | points = [[gate_position - 0.65,0.2], |
---|
123 | [gate_position - 0.55,0.2], |
---|
124 | [gate_position - 0.45,0.2], |
---|
125 | [gate_position - 0.35,0.2], |
---|
126 | [gate_position - 0.25,0.2] |
---|
127 | ] |
---|
128 | |
---|
129 | #------------------------------------------------------------------------- |
---|
130 | # Calculate gauge info |
---|
131 | #------------------------------------------------------------------------- |
---|
132 | |
---|
133 | interpolate_sww2csv(basename +".sww", |
---|
134 | points, |
---|
135 | basename + "_depth.csv", |
---|
136 | basename + "_velocity_x.csv", |
---|
137 | basename + "_velocity_y.csv") |
---|
138 | |
---|
139 | |
---|
140 | #------------------------------------------------------------- |
---|
141 | if __name__ == "__main__": |
---|
142 | for friction in [ 0.0, 0.01]: |
---|
143 | main(friction, is_trial_run = False) |
---|
144 | |
---|