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 | domain_list = pmesh_to_domain(filename) |
---|
33 | vertex_coordinates = domain_list[0] |
---|
34 | volumes = domain_list[1] |
---|
35 | marker_dict = domain_list[2] |
---|
36 | vertex_quantity_dict = domain_list[3] |
---|
37 | |
---|
38 | domain = Domain(vertex_coordinates, volumes, marker_dict) |
---|
39 | print "Number of triangles = ", len(domain) |
---|
40 | |
---|
41 | domain.store = False #True |
---|
42 | domain.format = 'sww' |
---|
43 | domain.filename = 'weir' |
---|
44 | domain.checkpoint = False #True |
---|
45 | domain.visualise = True #False |
---|
46 | domain.default_order = 2 |
---|
47 | |
---|
48 | #Set bed-slope and friction |
---|
49 | inflow_stage = 0.15 |
---|
50 | manning = 0.07 |
---|
51 | W = Weir(inflow_stage) |
---|
52 | |
---|
53 | print 'Field values' |
---|
54 | |
---|
55 | domain.set_quantity('elevation', W) |
---|
56 | domain.set_quantity('friction', manning) |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | ###################### |
---|
61 | # Boundary conditions |
---|
62 | # |
---|
63 | print 'Boundaries' |
---|
64 | Br = Reflective_boundary(domain) |
---|
65 | Bt = Transmissive_boundary(domain) |
---|
66 | |
---|
67 | #Constant inflow |
---|
68 | Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0])) |
---|
69 | |
---|
70 | #Time dependent inflow |
---|
71 | from math import sin, pi |
---|
72 | Bw = Time_boundary(domain=domain, |
---|
73 | f=lambda x: array([(1 + sin(x*pi/4))*\ |
---|
74 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0])) |
---|
75 | |
---|
76 | |
---|
77 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
78 | |
---|
79 | #Set boundary conditions |
---|
80 | domain.set_boundary({'left': Bw, '0': Br, '1':Bw, 'external':Br}) |
---|
81 | |
---|
82 | |
---|
83 | #print domain.quantities['elevation'].vertex_values |
---|
84 | #print domain.quantities['level'].vertex_values |
---|
85 | |
---|
86 | ###################### |
---|
87 | #Initial condition |
---|
88 | print 'Initial condition' |
---|
89 | domain.set_quantity('level', Constant_height(W, 0.)) |
---|
90 | domain.check_integrity() |
---|
91 | |
---|
92 | ###################### |
---|
93 | #Evolution |
---|
94 | for t in domain.evolve(yieldstep = 0.01, finaltime = 5): |
---|
95 | domain.write_time() |
---|
96 | |
---|
97 | print 'Done' |
---|
98 | |
---|
99 | |
---|