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 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
8 | numerical vector named conserved_quantities. |
---|
9 | """ |
---|
10 | |
---|
11 | ###################### |
---|
12 | # Module imports |
---|
13 | # |
---|
14 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
15 | Transmissive_boundary, Time_boundary, Constant_height, Weir |
---|
16 | |
---|
17 | from mesh_factory import rectangular |
---|
18 | from pmesh2domain import pmesh_to_domain |
---|
19 | |
---|
20 | from Numeric import array |
---|
21 | |
---|
22 | ###################### |
---|
23 | # Domain |
---|
24 | |
---|
25 | import sys |
---|
26 | if len(sys.argv) > 1: |
---|
27 | filename = sys.argv[1] |
---|
28 | else: |
---|
29 | filename = 'weir_domain_refined.tsh' |
---|
30 | |
---|
31 | print 'Creating domain from', filename |
---|
32 | points, vertices, boundary = pmesh_to_domain(filename) |
---|
33 | domain = Domain(points, vertices, boundary) |
---|
34 | print "Number of triangles = ", len(domain) |
---|
35 | |
---|
36 | domain.store = False #True |
---|
37 | domain.format = 'sww' |
---|
38 | domain.filename = 'weir' |
---|
39 | domain.checkpoint = False #True |
---|
40 | domain.visualise = True #False |
---|
41 | domain.default_order = 2 |
---|
42 | |
---|
43 | #Set bed-slope and friction |
---|
44 | inflow_stage = 0.15 |
---|
45 | manning = 0.07 |
---|
46 | W = Weir(inflow_stage) |
---|
47 | |
---|
48 | print 'Field values' |
---|
49 | |
---|
50 | domain.set_quantity('elevation', W) |
---|
51 | domain.set_quantity('friction', manning) |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | ###################### |
---|
56 | # Boundary conditions |
---|
57 | # |
---|
58 | print 'Boundaries' |
---|
59 | Br = Reflective_boundary(domain) |
---|
60 | Bt = Transmissive_boundary(domain) |
---|
61 | |
---|
62 | #Constant inflow |
---|
63 | Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0])) |
---|
64 | |
---|
65 | #Time dependent inflow |
---|
66 | from math import sin, pi |
---|
67 | Bw = Time_boundary(domain=domain, |
---|
68 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
69 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
70 | |
---|
71 | |
---|
72 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
73 | |
---|
74 | #Set boundary conditions |
---|
75 | domain.set_boundary({'left': Bw, '0': Br}) |
---|
76 | |
---|
77 | ###################### |
---|
78 | #Initial condition |
---|
79 | print 'Initial condition' |
---|
80 | domain.set_quantity('level', Constant_height(W, 0.)) |
---|
81 | domain.check_integrity() |
---|
82 | |
---|
83 | ###################### |
---|
84 | #Evolution |
---|
85 | for t in domain.evolve(yieldstep = 0.01, finaltime = 5): |
---|
86 | domain.write_time() |
---|
87 | |
---|
88 | print 'Done' |
---|
89 | |
---|
90 | |
---|