[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 |
---|
[3533] | 16 | from os import path |
---|
[3125] | 17 | |
---|
| 18 | # Related major packages |
---|
[3610] | 19 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
[3125] | 20 | Dirichlet_boundary, Time_boundary, File_boundary |
---|
[3610] | 21 | from anuga.abstract_2d_finite_volumes.util import Screen_Catcher |
---|
| 22 | from anuga.abstract_2d_finite_volumes.region import Set_region |
---|
[3514] | 23 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
[3423] | 24 | import create_mesh |
---|
[3125] | 25 | |
---|
| 26 | # Application specific imports |
---|
| 27 | import project # Definition of file names and polygons |
---|
| 28 | |
---|
[3535] | 29 | |
---|
[3420] | 30 | def main(): |
---|
| 31 | #------------------------------------------------------------------------- |
---|
| 32 | # Setup archiving of simulations |
---|
| 33 | #------------------------------------------------------------------------- |
---|
[3145] | 34 | |
---|
[3420] | 35 | copy (project.codedirname, project.outputtimedir + 'project.py') |
---|
| 36 | copy (project.codedir + 'run_dam.py', project.outputtimedir + 'run_dam.py') |
---|
| 37 | copy (project.codedir + 'create_mesh.py', |
---|
| 38 | project.outputtimedir + 'create_mesh.py') |
---|
| 39 | print'output dir', project.outputtimedir |
---|
[3145] | 40 | |
---|
[3423] | 41 | #FIXME this isn't working |
---|
[3420] | 42 | #normal screen output is stored in |
---|
| 43 | screen_output_name = project.outputtimedir + "screen_output.txt" |
---|
| 44 | screen_error_name = project.outputtimedir + "screen_error.txt" |
---|
[3125] | 45 | |
---|
[3420] | 46 | #------------------------------------------------------------------------- |
---|
| 47 | # Create the triangular mesh |
---|
| 48 | #------------------------------------------------------------------------- |
---|
[3125] | 49 | |
---|
[3446] | 50 | gate_position = 0.85 |
---|
[3421] | 51 | create_mesh.generate(project.mesh_filename, |
---|
[3446] | 52 | gate_position, |
---|
[3543] | 53 | #is_course=True) # this creates the mesh |
---|
| 54 | is_course=False) # this creates the mesh |
---|
[3125] | 55 | |
---|
[3420] | 56 | head,tail = path.split(project.mesh_filename) |
---|
| 57 | copy (project.mesh_filename, |
---|
| 58 | project.outputtimedir + tail ) |
---|
| 59 | #------------------------------------------------------------------------- |
---|
| 60 | # Setup computational domain |
---|
| 61 | #------------------------------------------------------------------------- |
---|
| 62 | domain = Domain(project.mesh_filename, use_cache = False, verbose = True) |
---|
[3125] | 63 | |
---|
| 64 | |
---|
[3420] | 65 | print 'Number of triangles = ', len(domain) |
---|
| 66 | print 'The extent is ', domain.get_extent() |
---|
| 67 | print domain.statistics() |
---|
[3125] | 68 | |
---|
[3533] | 69 | |
---|
[3420] | 70 | domain.set_name(project.basename) |
---|
| 71 | domain.set_datadir(project.outputtimedir) |
---|
| 72 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
[3533] | 73 | domain.set_minimum_sww_depth(0.01) |
---|
[3535] | 74 | domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
[3125] | 75 | |
---|
[3420] | 76 | #------------------------------------------------------------------------- |
---|
| 77 | # Setup initial conditions |
---|
| 78 | #------------------------------------------------------------------------- |
---|
[3125] | 79 | |
---|
[3446] | 80 | slope = 0.05 |
---|
[3125] | 81 | |
---|
[3420] | 82 | def elevation_tilt(x, y): |
---|
| 83 | return x*slope |
---|
[3125] | 84 | |
---|
[3420] | 85 | domain.set_quantity('stage', elevation_tilt) |
---|
| 86 | domain.set_quantity('friction', 0.03) |
---|
| 87 | domain.set_quantity('elevation',elevation_tilt) |
---|
[3125] | 88 | |
---|
[3420] | 89 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
[3447] | 90 | domain.set_region('dam','stage',0.2, |
---|
| 91 | location = 'unique vertices') |
---|
[3535] | 92 | #domain.set_region(Set_region('dam','stage',0.2, |
---|
| 93 | # location = 'unique vertices')) |
---|
[3125] | 94 | |
---|
[3420] | 95 | Br = Reflective_boundary(domain) |
---|
[3535] | 96 | Bd = Dirichlet_boundary([0,0,0]) # to drain the water out. |
---|
[3426] | 97 | domain.set_boundary( {'wall': Br, 'edge': Bd} ) |
---|
[3125] | 98 | |
---|
[3420] | 99 | #------------------------------------------------------------------------- |
---|
| 100 | # Evolve system through time |
---|
| 101 | #------------------------------------------------------------------------- |
---|
| 102 | t0 = time.time() |
---|
[3125] | 103 | |
---|
[3428] | 104 | for t in domain.evolve(yieldstep = 0.1, finaltime = 25): |
---|
[3420] | 105 | domain.write_time() |
---|
[3125] | 106 | |
---|
[3420] | 107 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 108 | print 'finished' |
---|
[3125] | 109 | |
---|
[3446] | 110 | points = [[gate_position - 0.65,0.2], |
---|
| 111 | [gate_position - 0.55,0.2], |
---|
| 112 | [gate_position - 0.45,0.2], |
---|
| 113 | [gate_position - 0.35,0.2], |
---|
| 114 | [gate_position - 0.25,0.2], |
---|
| 115 | [0.55,0.2] |
---|
[3421] | 116 | ] |
---|
| 117 | |
---|
| 118 | #------------------------------------------------------------------------- |
---|
[3535] | 119 | # Calculate gauge info |
---|
[3421] | 120 | #------------------------------------------------------------------------- |
---|
[3423] | 121 | interpolate_sww2csv(project.outputtimedir + project.basename +".sww", |
---|
| 122 | points, |
---|
| 123 | project.depth_filename, |
---|
[3456] | 124 | project.velocity_x_filename, |
---|
| 125 | project.velocity_y_filename) |
---|
[3421] | 126 | |
---|
[3420] | 127 | #------------------------------------------------------------- |
---|
| 128 | if __name__ == "__main__": |
---|
| 129 | main() |
---|
| 130 | |
---|