[419] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
| 3 | Specific methods pertaining to the 2D shallow water equation |
---|
| 4 | are imported from shallow_water |
---|
| 5 | for use with the generic finite volume framework |
---|
| 6 | |
---|
| 7 | A example of running this program is; |
---|
| 8 | python run_tsh.py visualise hill.tsh 0.05 1 |
---|
| 9 | """ |
---|
| 10 | |
---|
| 11 | ###################### |
---|
| 12 | # Module imports |
---|
| 13 | # |
---|
| 14 | |
---|
| 15 | import sys |
---|
| 16 | from os import sep, path |
---|
| 17 | sys.path.append('..'+sep+'pyvolution') |
---|
| 18 | |
---|
| 19 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
[2603] | 20 | Transmissive_boundary, Time_boundary |
---|
| 21 | from region import Add_value_to_region, Set_region |
---|
[419] | 22 | from mesh_factory import rectangular |
---|
[1809] | 23 | from pmesh2domain import pmesh_to_domain_instance |
---|
[419] | 24 | |
---|
| 25 | from Numeric import array |
---|
| 26 | |
---|
[885] | 27 | import time |
---|
[419] | 28 | |
---|
[924] | 29 | #from config import default_datadir |
---|
[866] | 30 | |
---|
[419] | 31 | ###################### |
---|
| 32 | # Domain |
---|
| 33 | |
---|
| 34 | import sys |
---|
| 35 | |
---|
[1152] | 36 | |
---|
| 37 | ######NEW |
---|
| 38 | def add_x_y(x, y): |
---|
| 39 | return x+y |
---|
| 40 | |
---|
| 41 | ######NEW |
---|
| 42 | |
---|
[419] | 43 | usage = "usage: %s ['visual'|'non-visual'] pmesh_file_name yieldstep finaltime" % path.basename(sys.argv[0]) |
---|
| 44 | |
---|
| 45 | if len(sys.argv) < 4: |
---|
| 46 | print usage |
---|
| 47 | else: |
---|
| 48 | if sys.argv[1][0] == "n" or sys.argv[1][0] == "N": |
---|
| 49 | visualise = False |
---|
| 50 | else: |
---|
| 51 | visualise = True |
---|
| 52 | filename = sys.argv[2] |
---|
| 53 | yieldstep = float(sys.argv[3]) |
---|
| 54 | finaltime = float(sys.argv[4]) |
---|
| 55 | |
---|
| 56 | print 'Creating domain from', filename |
---|
| 57 | domain = pmesh_to_domain_instance(filename, Domain) |
---|
| 58 | print "Number of triangles = ", len(domain) |
---|
[1809] | 59 | print "domain.geo_reference",domain.geo_reference |
---|
[419] | 60 | domain.checkpoint = False #True |
---|
[449] | 61 | domain.default_order = 1 |
---|
[419] | 62 | domain.visualise = visualise |
---|
[866] | 63 | domain.smooth = True |
---|
[925] | 64 | domain.set_datadir('.') |
---|
[419] | 65 | |
---|
| 66 | if (domain.visualise): |
---|
| 67 | domain.store = False #True #Store for visualisation purposes |
---|
| 68 | else: |
---|
| 69 | domain.store = True #True #Store for visualisation purposes |
---|
| 70 | domain.format = 'sww' #Native netcdf visualisation format |
---|
| 71 | |
---|
| 72 | file_path, filename = path.split(filename) |
---|
| 73 | filename, ext = path.splitext(filename) |
---|
| 74 | if domain.smooth is True: |
---|
| 75 | s = 'smooth' |
---|
| 76 | else: |
---|
| 77 | s = 'nonsmooth' |
---|
[421] | 78 | domain.filename = filename + '_' + s + '_ys'+ str(yieldstep) + \ |
---|
| 79 | '_ft' + str(finaltime) |
---|
[924] | 80 | print "Output being written to " + domain.get_datadir() + sep + \ |
---|
[419] | 81 | domain.filename + "." + domain.format |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | #Set friction |
---|
[449] | 85 | manning = 0.07 |
---|
[809] | 86 | inflow_stage = 10.0 |
---|
[1152] | 87 | |
---|
| 88 | ######NEW |
---|
[419] | 89 | domain.set_quantity('friction', manning) |
---|
[2352] | 90 | |
---|
| 91 | #domain.set_quantity('stage', add_x_y) |
---|
| 92 | #domain.set_quantity('elevation', |
---|
| 93 | # domain.quantities['stage'].vertex_values+ \ |
---|
| 94 | # domain.quantities['elevation'].vertex_values) |
---|
| 95 | #domain.set_quantity('stage', 0.0) |
---|
[1152] | 96 | ######NEW |
---|
[419] | 97 | |
---|
| 98 | ###################### |
---|
| 99 | # Boundary conditions |
---|
| 100 | # |
---|
| 101 | print 'Boundaries' |
---|
[718] | 102 | reflective = Reflective_boundary(domain) |
---|
[419] | 103 | Bt = Transmissive_boundary(domain) |
---|
| 104 | |
---|
| 105 | #Constant inflow |
---|
[2352] | 106 | Bd = Dirichlet_boundary(array([3, 0.0, 0.0])) |
---|
[419] | 107 | |
---|
| 108 | #Time dependent inflow |
---|
| 109 | from math import sin, pi |
---|
| 110 | Bw = Time_boundary(domain=domain, |
---|
| 111 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
| 112 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
| 116 | |
---|
| 117 | #Set boundary conditions |
---|
| 118 | |
---|
| 119 | tags = {} |
---|
| 120 | tags['left'] = Bw |
---|
[2352] | 121 | tags['1'] = Bd |
---|
| 122 | |
---|
[419] | 123 | tags['wave'] = Bd |
---|
[866] | 124 | tags['wave'] = Time_boundary(domain=domain, |
---|
| 125 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
| 126 | (0.15*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
[419] | 127 | tags['internal'] = None |
---|
| 128 | tags['levee'] = None |
---|
[718] | 129 | tags['0'] = reflective |
---|
| 130 | tags['wall'] = reflective |
---|
[809] | 131 | tags['external'] = reflective |
---|
| 132 | tags['exterior'] = reflective |
---|
[718] | 133 | tags['open'] = Bd |
---|
| 134 | tags['opening'] = None |
---|
[419] | 135 | |
---|
| 136 | domain.set_boundary(tags) |
---|
| 137 | |
---|
[718] | 138 | # region tags |
---|
| 139 | |
---|
[2352] | 140 | domain.set_region(Set_region('slow', 'friction', 20, location='unique vertices')) |
---|
| 141 | domain.set_region(Set_region('silo', 'elevation', 20, location='unique vertices')) |
---|
| 142 | domain.set_region(Set_region('wet', 'elevation', 0, location='unique vertices')) |
---|
| 143 | domain.set_region(Set_region('dry', 'elevation', 2, location='unique vertices')) |
---|
| 144 | domain.set_region(Add_value_to_region('wet', 'stage', 1.5, location='unique vertices', initial_quantity='elevation')) |
---|
| 145 | domain.set_region(Add_value_to_region('dry', 'stage', 0, location='unique vertices', initial_quantity='elevation')) |
---|
| 146 | |
---|
[419] | 147 | #print domain.quantities['elevation'].vertex_values |
---|
[774] | 148 | #print domain.quantities['stage'].vertex_values |
---|
[419] | 149 | |
---|
| 150 | domain.check_integrity() |
---|
| 151 | |
---|
| 152 | ###################### |
---|
| 153 | #Evolution |
---|
[885] | 154 | t0 = time.time() |
---|
[419] | 155 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
| 156 | domain.write_time() |
---|
| 157 | |
---|
[885] | 158 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[419] | 159 | |
---|
| 160 | |
---|