[5076] | 1 | """ |
---|
| 2 | |
---|
| 3 | Script for running a breaking wave simulation of Jon Hinwoods wave tank. |
---|
| 4 | Note: this is based on the frinction_ua_flume_2006 structure. |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | Duncan Gray, GA - 2007 |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | """ |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | #---------------------------------------------------------------------------- |
---|
| 15 | # Import necessary modules |
---|
| 16 | #---------------------------------------------------------------------------- |
---|
| 17 | |
---|
| 18 | # Standard modules |
---|
| 19 | import time |
---|
| 20 | from time import localtime, strftime |
---|
| 21 | import sys |
---|
| 22 | from shutil import copy |
---|
| 23 | from os import path, sep |
---|
| 24 | from os.path import dirname #, basename |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | # Related major packages |
---|
| 28 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
| 29 | Dirichlet_boundary, Time_boundary, \ |
---|
| 30 | File_boundary, \ |
---|
| 31 | Transmissive_Momentum_Set_Stage_boundary |
---|
| 32 | from anuga.fit_interpolate.interpolate import interpolate_sww2csv |
---|
| 33 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \ |
---|
| 34 | copy_code_files, file_function |
---|
| 35 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\ |
---|
| 36 | import File_boundary_time |
---|
| 37 | |
---|
| 38 | # Scenario specific imports |
---|
| 39 | import project # Definition of file names and polygons |
---|
| 40 | import create_mesh |
---|
| 41 | |
---|
| 42 | def elevation_function(x,y): |
---|
| 43 | from Numeric import zeros, size, Float |
---|
[5092] | 44 | |
---|
| 45 | xslope = create_mesh.xslope #4 ## Bit of a magic Number |
---|
| 46 | print "xslope",xslope |
---|
[5076] | 47 | z = zeros(size(x), Float) |
---|
| 48 | for i in range(len(x)): |
---|
[5092] | 49 | if x[i] < xslope: |
---|
[5076] | 50 | z[i] = 0.0 #WARNING: the code in prepare_time_boundary |
---|
| 51 | # that calc's momentum assumes this is 0.0 |
---|
| 52 | else: |
---|
[5092] | 53 | z[i] = (x[i]-xslope)*(1./16.) |
---|
[5076] | 54 | return z |
---|
| 55 | |
---|
| 56 | def main(friction=0.01, outputdir_name=None, is_trial_run=False): |
---|
| 57 | basename = 'zz' + str(friction) |
---|
| 58 | if is_trial_run is True: |
---|
| 59 | outputdir_name += '_test' |
---|
| 60 | yieldstep = 0.1 |
---|
| 61 | finaltime = 15. |
---|
| 62 | maximum_triangle_area=0.01 |
---|
| 63 | else: |
---|
| 64 | yieldstep = 0.02 |
---|
| 65 | finaltime = 15.1 |
---|
| 66 | maximum_triangle_area=0.0001 |
---|
| 67 | |
---|
| 68 | maximum_triangle_area=0.001 |
---|
| 69 | |
---|
| 70 | pro_instance = project.Project(['data','flumes','Hinwood_2008'], |
---|
| 71 | outputdir_name=outputdir_name, |
---|
| 72 | home='.') |
---|
| 73 | print "The output dir is", pro_instance.outputdir |
---|
| 74 | copy_code_files(pro_instance.outputdir,__file__, |
---|
| 75 | dirname(project.__file__) \ |
---|
| 76 | + sep + project.__name__+'.py') |
---|
| 77 | copy (pro_instance.codedir + 'run_dam.py', |
---|
| 78 | pro_instance.outputdir + 'run_dam.py') |
---|
| 79 | copy (pro_instance.codedir + 'create_mesh.py', |
---|
| 80 | pro_instance.outputdir + 'create_mesh.py') |
---|
| 81 | |
---|
| 82 | mesh_filename = pro_instance.meshdir + basename + '.msh' |
---|
| 83 | |
---|
| 84 | #-------------------------------------------------------------------------- |
---|
| 85 | # Copy scripts to output directory and capture screen |
---|
| 86 | # output to file |
---|
| 87 | #-------------------------------------------------------------------------- |
---|
| 88 | |
---|
| 89 | # creates copy of code in output dir |
---|
| 90 | if is_trial_run is False: |
---|
| 91 | start_screen_catcher(pro_instance.outputdir, rank, pypar.size()) |
---|
| 92 | |
---|
| 93 | print 'USER: ', pro_instance.user |
---|
| 94 | #------------------------------------------------------------------------- |
---|
| 95 | # Create the triangular mesh |
---|
| 96 | #------------------------------------------------------------------------- |
---|
| 97 | |
---|
| 98 | # this creates the mesh |
---|
| 99 | #gate_position = 12.0 |
---|
| 100 | create_mesh.generate(mesh_filename, |
---|
| 101 | maximum_triangle_area=maximum_triangle_area) |
---|
| 102 | |
---|
| 103 | head,tail = path.split(mesh_filename) |
---|
| 104 | copy (mesh_filename, |
---|
| 105 | pro_instance.outputdir + tail ) |
---|
| 106 | #------------------------------------------------------------------------- |
---|
| 107 | # Setup computational domain |
---|
| 108 | #------------------------------------------------------------------------- |
---|
| 109 | domain = Domain(mesh_filename, use_cache = False, verbose = True) |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | print 'Number of triangles = ', len(domain) |
---|
| 113 | print 'The extent is ', domain.get_extent() |
---|
| 114 | print domain.statistics() |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | domain.set_name(basename) |
---|
| 118 | domain.set_datadir(pro_instance.outputdir) |
---|
| 119 | domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) |
---|
| 120 | domain.set_minimum_storable_height(0.001) |
---|
| 121 | #domain.set_store_vertices_uniquely(True) # for writting to sww |
---|
| 122 | |
---|
| 123 | #------------------------------------------------------------------------- |
---|
| 124 | # Setup initial conditions |
---|
| 125 | #------------------------------------------------------------------------- |
---|
| 126 | |
---|
[5092] | 127 | domain.set_quantity('stage', 0.4) |
---|
[5076] | 128 | domain.set_quantity('friction', friction) |
---|
| 129 | domain.set_quantity('elevation', elevation_function) |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | print 'Available boundary tags', domain.get_boundary_tags() |
---|
| 133 | |
---|
| 134 | # Create boundary function from timeseries provided in file |
---|
| 135 | #function = file_function(project.boundary_file, domain, verbose=True) |
---|
| 136 | #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) |
---|
| 137 | |
---|
| 138 | function = file_function(project.boundary_file, domain, verbose=True) |
---|
| 139 | Br = Reflective_boundary(domain) |
---|
| 140 | #Bd = Dirichlet_boundary([0.3,0,0]) |
---|
| 141 | Bts = Time_boundary(domain, function) |
---|
| 142 | domain.set_boundary( {'wall': Br, 'wave': Bts} ) |
---|
| 143 | |
---|
| 144 | #------------------------------------------------------------------------- |
---|
| 145 | # Evolve system through time |
---|
| 146 | #------------------------------------------------------------------------- |
---|
| 147 | t0 = time.time() |
---|
| 148 | |
---|
[5078] | 149 | for t in domain.evolve(yieldstep, finaltime): |
---|
[5076] | 150 | domain.write_time() |
---|
[5078] | 151 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 152 | print 'finished' |
---|
[5076] | 153 | |
---|
[5092] | 154 | points = [[2.8,0.5], #-1.8m from SWL |
---|
| 155 | [5.1,0.5], #0.5m from SWL |
---|
| 156 | [6.6,0.5], #2m from SWL |
---|
| 157 | [6.95,0.5], #2.35m from SWL |
---|
| 158 | [7.6,0.5], #3m from SWL |
---|
| 159 | [8.2,0.5], #3.5m from SWL |
---|
| 160 | [9.2,0.5] #4.5m from SWL |
---|
[5076] | 161 | ] |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | #------------------------------------------------------------------------- |
---|
| 165 | # Calculate gauge info |
---|
| 166 | #------------------------------------------------------------------------- |
---|
| 167 | |
---|
| 168 | if False: |
---|
| 169 | interpolate_sww2csv(pro_instance.outputdir + basename +".sww", |
---|
| 170 | points, |
---|
| 171 | pro_instance.outputdir + "depth_manning_"+str(friction)+".csv", |
---|
| 172 | pro_instance.outputdir + "velocity_x.csv", |
---|
| 173 | pro_instance.outputdir + "velocity_y.csv") |
---|
| 174 | |
---|
| 175 | return pro_instance |
---|
| 176 | |
---|
| 177 | #------------------------------------------------------------- |
---|
| 178 | if __name__ == "__main__": |
---|
| 179 | main( is_trial_run = True, |
---|
[5092] | 180 | outputdir_name='Hinwood_low_stage_low_velocity_draft') |
---|