[4043] | 1 | """Script for running a dam break simulation of UQ's dam break tank. |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | Ole Nielsen and Duncan Gray, GA - 2006 |
---|
[4047] | 5 | |
---|
| 6 | |
---|
| 7 | Issues |
---|
| 8 | If running this is hand-set-up parallel, the python files are overwritten. |
---|
| 9 | |
---|
[4043] | 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 | # Related major packages |
---|
| 26 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
| 27 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
| 28 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
| 29 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
| 30 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \ |
---|
| 31 | copy_code_files |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | # Scenario specific imports |
---|
| 35 | import project # Definition of file names and polygons |
---|
| 36 | import create_mesh |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | def main(friction, outputdir_name=None, is_trial_run=False): |
---|
| 40 | basename = 'zz' + str(friction) |
---|
| 41 | if is_trial_run is True: |
---|
| 42 | outputdir_name += '_test' |
---|
| 43 | yieldstep = 1 |
---|
| 44 | finaltime = 31 |
---|
| 45 | else: |
---|
| 46 | yieldstep = 0.01 |
---|
| 47 | finaltime = 31 |
---|
| 48 | pro_instance = project.Project(['data','flumes','dam_2006'], |
---|
| 49 | outputdir_name=outputdir_name) |
---|
| 50 | mesh_filename = pro_instance.meshdir + basename + '.msh' |
---|
| 51 | |
---|
| 52 | #-------------------------------------------------------------------------- |
---|
| 53 | # Copy scripts to output directory and capture screen |
---|
| 54 | # output to file |
---|
| 55 | #-------------------------------------------------------------------------- |
---|
| 56 | |
---|
| 57 | # creates copy of code in output dir |
---|
| 58 | print "The output dir is", pro_instance.outputdir |
---|
| 59 | copy_code_files(pro_instance.outputdir,__file__, |
---|
| 60 | dirname(project.__file__) \ |
---|
| 61 | + sep + project.__name__+'.py') |
---|
[4047] | 62 | copy (pro_instance.codedir + 'run_dam.py', |
---|
| 63 | pro_instance.outputdir + 'run_dam' + str(friction)+ '.py') |
---|
[4043] | 64 | copy (pro_instance.codedir + 'create_mesh.py', |
---|
| 65 | pro_instance.outputdir + 'create_mesh.py') |
---|
| 66 | if is_trial_run is False: |
---|
| 67 | start_screen_catcher(pro_instance.outputdir, int(friction*100)) |
---|
| 68 | |
---|
| 69 | print 'USER: ', pro_instance.user |
---|
| 70 | #------------------------------------------------------------------------- |
---|
| 71 | # Create the triangular mesh |
---|
| 72 | #------------------------------------------------------------------------- |
---|
| 73 | |
---|
| 74 | gate_position = 0.85 |
---|
| 75 | create_mesh.generate(mesh_filename, |
---|
| 76 | gate_position, |
---|
| 77 | is_coarse=is_trial_run) # this creates the mesh |
---|
| 78 | |
---|
| 79 | head,tail = path.split(mesh_filename) |
---|
| 80 | copy (mesh_filename, |
---|
| 81 | pro_instance.outputdir + tail ) |
---|
| 82 | #------------------------------------------------------------------------- |
---|
| 83 | # Setup computational domain |
---|
| 84 | #------------------------------------------------------------------------- |
---|
| 85 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | print 'Number of triangles = ', len(domain) |
---|
| 89 | print 'The extent is ', domain.get_extent() |
---|
| 90 | print domain.statistics() |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | domain.set_name(basename) |
---|
| 94 | domain.set_datadir(pro_instance.outputdir) |
---|
| 95 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 96 | domain.set_minimum_storable_height(0.01) |
---|
| 97 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
| 98 | |
---|
| 99 | #------------------------------------------------------------------------- |
---|
| 100 | # Setup initial conditions |
---|
| 101 | #------------------------------------------------------------------------- |
---|
| 102 | |
---|
| 103 | slope = 0.05 |
---|
| 104 | |
---|
| 105 | def elevation_tilt(x, y): |
---|
| 106 | return x*slope |
---|
| 107 | |
---|
| 108 | domain.set_quantity('stage', elevation_tilt) |
---|
| 109 | domain.set_quantity('friction', friction) |
---|
| 110 | domain.set_quantity('elevation',elevation_tilt) |
---|
| 111 | |
---|
| 112 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 113 | domain.set_region('dam','stage',0.20, |
---|
| 114 | location = 'unique vertices') |
---|
| 115 | #domain.set_region(Set_region('dam','stage',0.2, |
---|
| 116 | # location = 'unique vertices')) |
---|
| 117 | |
---|
| 118 | Br = Reflective_boundary(domain) |
---|
| 119 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
| 120 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
| 121 | |
---|
| 122 | #------------------------------------------------------------------------- |
---|
| 123 | # Evolve system through time |
---|
| 124 | #------------------------------------------------------------------------- |
---|
| 125 | t0 = time.time() |
---|
| 126 | |
---|
| 127 | for t in domain.evolve(yieldstep, finaltime): |
---|
| 128 | domain.write_time() |
---|
| 129 | |
---|
| 130 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 131 | print 'finished' |
---|
| 132 | |
---|
| 133 | points = [[gate_position - 0.65,0.2], |
---|
| 134 | [gate_position - 0.55,0.2], |
---|
| 135 | [gate_position - 0.45,0.2], |
---|
| 136 | [gate_position - 0.35,0.2], |
---|
| 137 | [gate_position - 0.25,0.2] |
---|
| 138 | ] |
---|
| 139 | |
---|
| 140 | #------------------------------------------------------------------------- |
---|
| 141 | # Calculate gauge info |
---|
| 142 | #------------------------------------------------------------------------- |
---|
| 143 | |
---|
| 144 | interpolate_sww2csv(pro_instance.outputdir + basename +".sww", |
---|
| 145 | points, |
---|
| 146 | pro_instance.outputdir + "depth_manning_"+str(friction)+".csv", |
---|
| 147 | pro_instance.outputdir + "velocity_x.csv", |
---|
| 148 | pro_instance.outputdir + "velocity_y.csv") |
---|
| 149 | |
---|
| 150 | return pro_instance |
---|
| 151 | |
---|
| 152 | #------------------------------------------------------------- |
---|
| 153 | if __name__ == "__main__": |
---|
[4055] | 154 | for friction in [ 0.05]: |
---|
[4238] | 155 | main(friction, is_trial_run = True, outputdir_name='friction_set_A') |
---|
[4043] | 156 | |
---|
[4047] | 157 | # to do |
---|
| 158 | # .075, -0-1 |
---|
| 159 | # 0.0075 - 0-16 |
---|
| 160 | #.01, - 0-2 |
---|
| 161 | # |
---|
| 162 | #.0125, - 0-6 |
---|
| 163 | #0.015, - 0-17 |
---|
| 164 | #0.02, - 0-14 |
---|
| 165 | #$0.03]: - 0-7 |
---|
| 166 | # [0.016, - 0-11 |
---|
| 167 | #0.017, -0-8 |
---|
| 168 | #0.018, -0-9 |
---|
| 169 | #0.019]: - 0-12 |
---|
| 170 | # 0.005 - 0-20 |
---|
| 171 | # 0.02 - 4 |
---|
| 172 | # 0.016 - 8 |
---|
| 173 | # 0.017 - 9 |
---|
| 174 | # 0.018 - 1 |
---|
| 175 | # 0.019 -17 |
---|
| 176 | # calc - 7 |
---|
| 177 | # 0.0075 -12 |
---|
[4043] | 178 | |
---|
[4047] | 179 | # Let's fill some gaps |
---|
| 180 | # 0.0225 - 7 |
---|
| 181 | # 0.025 - 12 |
---|
| 182 | # 0.0275 - 6 |
---|
[4043] | 183 | #for friction in [0.0, .0025, .005, .0075, .01, .0125, 0.015, 0.02, 0.03]: |
---|
| 184 | #for friction in [0.016, 0.017, 0.018, 0.019]: |
---|
| 185 | # main(friction, is_trial_run = True, outputdir_name='friction_set') |
---|