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