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 | |
---|
11 | |
---|
12 | #---------------------------------------------------------------------------- |
---|
13 | # Import necessary modules |
---|
14 | #---------------------------------------------------------------------------- |
---|
15 | |
---|
16 | # Standard modules |
---|
17 | import time |
---|
18 | from time import localtime, strftime |
---|
19 | import sys |
---|
20 | from shutil import copy |
---|
21 | from os import path, sep |
---|
22 | from os.path import dirname #, basename |
---|
23 | |
---|
24 | # Related major packages |
---|
25 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
26 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
27 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
28 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
29 | from anuga.shallow_water.data_manager import start_screen_catcher, \ |
---|
30 | copy_code_files |
---|
31 | |
---|
32 | |
---|
33 | # Scenario specific imports |
---|
34 | import project # Definition of file names and polygons |
---|
35 | import create_mesh |
---|
36 | |
---|
37 | |
---|
38 | def main(friction, is_trial_run=False): |
---|
39 | if is_trial_run is True: |
---|
40 | add = '_test' |
---|
41 | yieldstep = 1 |
---|
42 | finaltime = 31 |
---|
43 | else: |
---|
44 | add = '' |
---|
45 | yieldstep = 0.01 |
---|
46 | finaltime = 31 |
---|
47 | basename = 'zz' + add + str(friction) |
---|
48 | |
---|
49 | mesh_filename = project.mesh_filename + add + '.msh' |
---|
50 | |
---|
51 | #-------------------------------------------------------------------------- |
---|
52 | # Copy scripts to output directory and capture screen |
---|
53 | # output to file |
---|
54 | #-------------------------------------------------------------------------- |
---|
55 | |
---|
56 | |
---|
57 | if is_trial_run is False: |
---|
58 | start_screen_catcher('.', int(friction*100)) |
---|
59 | |
---|
60 | #------------------------------------------------------------------------- |
---|
61 | # Create the triangular mesh |
---|
62 | #------------------------------------------------------------------------- |
---|
63 | |
---|
64 | gate_position = 0.85 |
---|
65 | create_mesh.generate(mesh_filename, |
---|
66 | gate_position, |
---|
67 | is_coarse=is_trial_run) # this creates the mesh |
---|
68 | |
---|
69 | #------------------------------------------------------------------------- |
---|
70 | # Setup computational domain |
---|
71 | #------------------------------------------------------------------------- |
---|
72 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
73 | |
---|
74 | |
---|
75 | print 'Number of triangles = ', len(domain) |
---|
76 | print 'The extent is ', domain.get_extent() |
---|
77 | print domain.statistics() |
---|
78 | |
---|
79 | |
---|
80 | domain.set_name(basename) |
---|
81 | domain.set_datadir('.') |
---|
82 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
83 | domain.set_minimum_storable_height(0.01) |
---|
84 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
85 | |
---|
86 | #------------------------------------------------------------------------- |
---|
87 | # Setup initial conditions |
---|
88 | #------------------------------------------------------------------------- |
---|
89 | |
---|
90 | slope = 0.05 |
---|
91 | |
---|
92 | def elevation_tilt(x, y): |
---|
93 | return x*slope |
---|
94 | |
---|
95 | domain.set_quantity('stage', elevation_tilt) |
---|
96 | domain.set_quantity('friction', friction) |
---|
97 | domain.set_quantity('elevation',elevation_tilt) |
---|
98 | |
---|
99 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
100 | domain.set_region('dam','stage',0.20, |
---|
101 | location = 'unique vertices') |
---|
102 | |
---|
103 | Br = Reflective_boundary(domain) |
---|
104 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
105 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
106 | |
---|
107 | #------------------------------------------------------------------------- |
---|
108 | # Evolve system through time |
---|
109 | #------------------------------------------------------------------------- |
---|
110 | t0 = time.time() |
---|
111 | |
---|
112 | for t in domain.evolve(yieldstep, finaltime): |
---|
113 | domain.write_time() |
---|
114 | |
---|
115 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
116 | print 'finished' |
---|
117 | |
---|
118 | points = [[gate_position - 0.65,0.2], |
---|
119 | [gate_position - 0.55,0.2], |
---|
120 | [gate_position - 0.45,0.2], |
---|
121 | [gate_position - 0.35,0.2], |
---|
122 | [gate_position - 0.25,0.2] |
---|
123 | ] |
---|
124 | |
---|
125 | #------------------------------------------------------------------------- |
---|
126 | # Calculate gauge info |
---|
127 | #------------------------------------------------------------------------- |
---|
128 | |
---|
129 | interpolate_sww2csv(basename +".sww", |
---|
130 | points, |
---|
131 | basename + "_depth.csv", |
---|
132 | basename + "_velocity_x.csv", |
---|
133 | basename + "_velocity_y.csv") |
---|
134 | |
---|
135 | |
---|
136 | #------------------------------------------------------------- |
---|
137 | if __name__ == "__main__": |
---|
138 | for friction in [ 0.0, 0.01]: |
---|
139 | main(friction, is_trial_run = False) |
---|
140 | |
---|