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, Add_value_to_region, File_boundary |
---|
21 | from mesh_factory import rectangular |
---|
22 | from anuga.pyvolution.pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance |
---|
23 | |
---|
24 | from Numeric import array |
---|
25 | |
---|
26 | import time |
---|
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 |
---|
51 | domain.default_order = 1 |
---|
52 | domain.visualise = visualise |
---|
53 | domain.smooth = True |
---|
54 | domain.set_datadir('.') |
---|
55 | domain.starttime = 20000 |
---|
56 | |
---|
57 | if (domain.visualise): |
---|
58 | domain.store = False #True #Store for visualisation purposes |
---|
59 | else: |
---|
60 | domain.store = True #True #Store for visualisation purposes |
---|
61 | domain.format = 'sww' #Native netcdf visualisation format |
---|
62 | |
---|
63 | file_path, filename = path.split(filename) |
---|
64 | filename, ext = path.splitext(filename) |
---|
65 | domain.set_name(filename + '_' + '_ys'+ str(yieldstep) + \ |
---|
66 | '_ft' + str(finaltime)) |
---|
67 | print "Output being written to " + domain.get_datadir() + sep + \ |
---|
68 | domain.get_name() + "." + domain.format |
---|
69 | |
---|
70 | |
---|
71 | #Set friction |
---|
72 | manning = 0.07 |
---|
73 | inflow_stage = 10.0 |
---|
74 | domain.set_quantity('friction', manning) |
---|
75 | |
---|
76 | ###################### |
---|
77 | # Boundary conditions |
---|
78 | # |
---|
79 | print 'Boundaries' |
---|
80 | reflective = Reflective_boundary(domain) |
---|
81 | Bt = Transmissive_boundary(domain) |
---|
82 | |
---|
83 | #Constant inflow |
---|
84 | Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0])) |
---|
85 | |
---|
86 | #Time dependent inflow |
---|
87 | from math import sin, pi |
---|
88 | Bw = Time_boundary(domain=domain, |
---|
89 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
90 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
91 | |
---|
92 | boundary_file = 'kermadec2.sww' |
---|
93 | |
---|
94 | Fb = File_boundary(boundary_file, domain, verbose=True) |
---|
95 | |
---|
96 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
97 | print 'The extent is ', domain.get_extent() |
---|
98 | |
---|
99 | #Set the ocean... |
---|
100 | domain.set_quantity('stage', 0.0) |
---|
101 | |
---|
102 | #Set boundary conditions |
---|
103 | |
---|
104 | tags = {} |
---|
105 | |
---|
106 | tsunami = Fb |
---|
107 | tags['w1'] = tsunami |
---|
108 | tags['w2'] = tsunami |
---|
109 | tags['w3'] = tsunami |
---|
110 | tags['w4'] = tsunami |
---|
111 | tags['w5'] = tsunami |
---|
112 | tags['w6'] = tsunami |
---|
113 | tags['w7'] = tsunami |
---|
114 | tags['wave'] = tsunami |
---|
115 | tags['external'] = tsunami |
---|
116 | tags['exterior'] = tsunami |
---|
117 | |
---|
118 | domain.set_boundary(tags) |
---|
119 | |
---|
120 | # region tags |
---|
121 | |
---|
122 | domain.check_integrity() |
---|
123 | |
---|
124 | ###################### |
---|
125 | #Evolution |
---|
126 | t0 = time.time() |
---|
127 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
128 | domain.write_time() |
---|
129 | |
---|
130 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
131 | |
---|
132 | |
---|