[3533] | 1 | """Script for running a dam break simulation of UQ's dam break tank. |
---|
[3125] | 2 | |
---|
| 3 | |
---|
[3533] | 4 | Ole Nielsen and Duncan Gray, GA - 2006 |
---|
[3125] | 5 | """ |
---|
| 6 | |
---|
| 7 | |
---|
[3178] | 8 | #---------------------------------------------------------------------------- |
---|
| 9 | # Import necessary modules |
---|
| 10 | #---------------------------------------------------------------------------- |
---|
[3125] | 11 | |
---|
| 12 | # Standard modules |
---|
| 13 | import time |
---|
| 14 | import sys |
---|
| 15 | from shutil import copy |
---|
[4007] | 16 | from os import path, sep |
---|
| 17 | from os.path import dirname #, basename |
---|
[3125] | 18 | |
---|
| 19 | # Related major packages |
---|
[3610] | 20 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
[3125] | 21 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
[3610] | 22 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
[3514] | 23 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
[4007] | 24 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \ |
---|
| 25 | copy_code_files |
---|
[3125] | 26 | |
---|
[4007] | 27 | |
---|
| 28 | # Scenario specific imports |
---|
[3125] | 29 | import project # Definition of file names and polygons |
---|
[4007] | 30 | import create_mesh |
---|
[3125] | 31 | |
---|
[3535] | 32 | |
---|
[4044] | 33 | def main(friction): |
---|
[3145] | 34 | |
---|
[4007] | 35 | #-------------------------------------------------------------------------- |
---|
| 36 | # Copy scripts to time stamped output directory and capture screen |
---|
| 37 | # output to file |
---|
| 38 | #-------------------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | # creates copy of code in output dir |
---|
| 41 | |
---|
| 42 | print "The output dir is", project.outputtimedir |
---|
| 43 | copy_code_files(project.outputtimedir,__file__, |
---|
| 44 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
[3420] | 45 | copy (project.codedir + 'create_mesh.py', |
---|
| 46 | project.outputtimedir + 'create_mesh.py') |
---|
[4007] | 47 | myid = 0 |
---|
| 48 | numprocs = 1 |
---|
[4044] | 49 | #start_screen_catcher(project.outputtimedir, myid, numprocs) |
---|
[3145] | 50 | |
---|
[4007] | 51 | print 'USER: ', project.user |
---|
[3420] | 52 | #------------------------------------------------------------------------- |
---|
| 53 | # Create the triangular mesh |
---|
| 54 | #------------------------------------------------------------------------- |
---|
[3125] | 55 | |
---|
[4044] | 56 | gate_position = 0.85 |
---|
[3421] | 57 | create_mesh.generate(project.mesh_filename, |
---|
[3446] | 58 | gate_position, |
---|
[4008] | 59 | #is_coarse=True) # this creates the mesh |
---|
| 60 | is_coarse=False) # this creates the mesh |
---|
[3125] | 61 | |
---|
[3420] | 62 | head,tail = path.split(project.mesh_filename) |
---|
| 63 | copy (project.mesh_filename, |
---|
| 64 | project.outputtimedir + tail ) |
---|
| 65 | #------------------------------------------------------------------------- |
---|
| 66 | # Setup computational domain |
---|
| 67 | #------------------------------------------------------------------------- |
---|
| 68 | domain = Domain(project.mesh_filename, use_cache = False, verbose = True) |
---|
[3125] | 69 | |
---|
| 70 | |
---|
[3420] | 71 | print 'Number of triangles = ', len(domain) |
---|
| 72 | print 'The extent is ', domain.get_extent() |
---|
| 73 | print domain.statistics() |
---|
[3125] | 74 | |
---|
[3533] | 75 | |
---|
[3420] | 76 | domain.set_name(project.basename) |
---|
| 77 | domain.set_datadir(project.outputtimedir) |
---|
| 78 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
[3642] | 79 | domain.set_minimum_storable_height(0.01) |
---|
[4033] | 80 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
[3125] | 81 | |
---|
[3420] | 82 | #------------------------------------------------------------------------- |
---|
| 83 | # Setup initial conditions |
---|
| 84 | #------------------------------------------------------------------------- |
---|
[3125] | 85 | |
---|
[3446] | 86 | slope = 0.05 |
---|
[3125] | 87 | |
---|
[3420] | 88 | def elevation_tilt(x, y): |
---|
| 89 | return x*slope |
---|
[3125] | 90 | |
---|
[3420] | 91 | domain.set_quantity('stage', elevation_tilt) |
---|
[4044] | 92 | domain.set_quantity('friction', friction) |
---|
[3420] | 93 | domain.set_quantity('elevation',elevation_tilt) |
---|
[3125] | 94 | |
---|
[3420] | 95 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
[4044] | 96 | domain.set_region('dam','stage',0.20, |
---|
[3447] | 97 | location = 'unique vertices') |
---|
[3535] | 98 | #domain.set_region(Set_region('dam','stage',0.2, |
---|
| 99 | # location = 'unique vertices')) |
---|
[3125] | 100 | |
---|
[3420] | 101 | Br = Reflective_boundary(domain) |
---|
[3535] | 102 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
[3426] | 103 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
[3125] | 104 | |
---|
[3420] | 105 | #------------------------------------------------------------------------- |
---|
| 106 | # Evolve system through time |
---|
| 107 | #------------------------------------------------------------------------- |
---|
| 108 | t0 = time.time() |
---|
[3125] | 109 | |
---|
[4044] | 110 | for t in domain.evolve(yieldstep = 0.01, finaltime = 30): |
---|
[3420] | 111 | domain.write_time() |
---|
[3125] | 112 | |
---|
[3420] | 113 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 114 | print 'finished' |
---|
[3125] | 115 | |
---|
[3446] | 116 | points = [[gate_position - 0.65,0.2], |
---|
| 117 | [gate_position - 0.55,0.2], |
---|
| 118 | [gate_position - 0.45,0.2], |
---|
| 119 | [gate_position - 0.35,0.2], |
---|
[4044] | 120 | [gate_position - 0.25,0.2] |
---|
[3421] | 121 | ] |
---|
| 122 | |
---|
| 123 | #------------------------------------------------------------------------- |
---|
[3535] | 124 | # Calculate gauge info |
---|
[3421] | 125 | #------------------------------------------------------------------------- |
---|
[3423] | 126 | interpolate_sww2csv(project.outputtimedir + project.basename +".sww", |
---|
| 127 | points, |
---|
| 128 | project.depth_filename, |
---|
[3456] | 129 | project.velocity_x_filename, |
---|
| 130 | project.velocity_y_filename) |
---|
[3421] | 131 | |
---|
[3420] | 132 | #------------------------------------------------------------- |
---|
| 133 | if __name__ == "__main__": |
---|
[4044] | 134 | main(0.000) |
---|
[3420] | 135 | |
---|