[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,\ |
---|
[718] | 20 | Transmissive_boundary, Time_boundary, Set_region, Add_value_to_region |
---|
[419] | 21 | from mesh_factory import rectangular |
---|
| 22 | from pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance |
---|
| 23 | |
---|
| 24 | from Numeric import array |
---|
| 25 | |
---|
| 26 | from config import data_dir |
---|
| 27 | |
---|
| 28 | ###################### |
---|
| 29 | # Domain |
---|
| 30 | |
---|
| 31 | import sys |
---|
| 32 | |
---|
| 33 | usage = "usage: %s ['visual'|'non-visual'] pmesh_file_name yieldstep finaltime" % path.basename(sys.argv[0]) |
---|
| 34 | |
---|
| 35 | if len(sys.argv) < 4: |
---|
| 36 | print usage |
---|
| 37 | else: |
---|
| 38 | if sys.argv[1][0] == "n" or sys.argv[1][0] == "N": |
---|
| 39 | visualise = False |
---|
| 40 | else: |
---|
| 41 | visualise = True |
---|
| 42 | filename = sys.argv[2] |
---|
| 43 | yieldstep = float(sys.argv[3]) |
---|
| 44 | finaltime = float(sys.argv[4]) |
---|
| 45 | |
---|
| 46 | print 'Creating domain from', filename |
---|
| 47 | domain = pmesh_to_domain_instance(filename, Domain) |
---|
| 48 | print "Number of triangles = ", len(domain) |
---|
| 49 | |
---|
| 50 | domain.checkpoint = False #True |
---|
[449] | 51 | domain.default_order = 1 |
---|
[419] | 52 | domain.visualise = visualise |
---|
| 53 | |
---|
| 54 | if (domain.visualise): |
---|
| 55 | domain.store = False #True #Store for visualisation purposes |
---|
| 56 | else: |
---|
| 57 | domain.store = True #True #Store for visualisation purposes |
---|
| 58 | domain.format = 'sww' #Native netcdf visualisation format |
---|
| 59 | |
---|
| 60 | file_path, filename = path.split(filename) |
---|
| 61 | filename, ext = path.splitext(filename) |
---|
| 62 | if domain.smooth is True: |
---|
| 63 | s = 'smooth' |
---|
| 64 | else: |
---|
| 65 | s = 'nonsmooth' |
---|
[421] | 66 | domain.filename = filename + '_' + s + '_ys'+ str(yieldstep) + \ |
---|
| 67 | '_ft' + str(finaltime) |
---|
[419] | 68 | print "Output being written to " + data_dir + sep + \ |
---|
| 69 | domain.filename + "." + domain.format |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | #Set friction |
---|
[449] | 73 | manning = 0.07 |
---|
[514] | 74 | inflow_stage = 20.0 |
---|
[419] | 75 | domain.set_quantity('friction', manning) |
---|
| 76 | |
---|
| 77 | ###################### |
---|
| 78 | # Boundary conditions |
---|
| 79 | # |
---|
| 80 | print 'Boundaries' |
---|
[718] | 81 | reflective = Reflective_boundary(domain) |
---|
[419] | 82 | Bt = Transmissive_boundary(domain) |
---|
| 83 | |
---|
| 84 | #Constant inflow |
---|
[718] | 85 | Bd = Dirichlet_boundary(array([7, 0.0, 0.0])) |
---|
[419] | 86 | |
---|
| 87 | #Time dependent inflow |
---|
| 88 | from math import sin, pi |
---|
| 89 | Bw = Time_boundary(domain=domain, |
---|
| 90 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
| 91 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
| 95 | |
---|
| 96 | #Set boundary conditions |
---|
| 97 | |
---|
| 98 | tags = {} |
---|
| 99 | tags['left'] = Bw |
---|
| 100 | tags['1'] = Time_boundary(domain=domain, |
---|
| 101 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
| 102 | (0.15*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
| 103 | tags['wave'] = Bd |
---|
| 104 | tags['internal'] = None |
---|
| 105 | tags['levee'] = None |
---|
[718] | 106 | tags['0'] = reflective |
---|
| 107 | tags['wall'] = reflective |
---|
| 108 | tags['external'] = reflective |
---|
| 109 | tags['open'] = Bd |
---|
| 110 | tags['opening'] = None |
---|
[419] | 111 | |
---|
| 112 | domain.set_boundary(tags) |
---|
| 113 | |
---|
[718] | 114 | # region tags |
---|
| 115 | #domain.set_region(Set_region('mound', 'elevation', 100, location='unique vertices')) |
---|
| 116 | domain.set_region(Add_value_to_region('mound', 'elevation', 100, location='unique vertices', initial_quantity='elevation')) |
---|
| 117 | domain.set_region(Add_value_to_region('reservoir', 'level', 100.0,initial_quantity='elevation')) |
---|
| 118 | |
---|
[419] | 119 | #print domain.quantities['elevation'].vertex_values |
---|
| 120 | #print domain.quantities['level'].vertex_values |
---|
| 121 | |
---|
| 122 | domain.check_integrity() |
---|
| 123 | |
---|
| 124 | ###################### |
---|
| 125 | #Evolution |
---|
| 126 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
| 127 | domain.write_time() |
---|
| 128 | |
---|
| 129 | print 'Done' |
---|
| 130 | |
---|
| 131 | |
---|