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,\ |
---|
16 | Weir_simple as Weir, Constant_height |
---|
17 | |
---|
18 | from mesh_factory import rectangular |
---|
19 | from Numeric import array |
---|
20 | |
---|
21 | |
---|
22 | ###################### |
---|
23 | # Domain |
---|
24 | # |
---|
25 | |
---|
26 | N = 12 |
---|
27 | |
---|
28 | print 'Creating domain' |
---|
29 | #Create basic mesh |
---|
30 | points, vertices, boundary = rectangular(N, N/2, len1=1.2,len2=0.6, |
---|
31 | origin=(-0.07, 0)) |
---|
32 | |
---|
33 | print 'Number of elements', len(vertices) |
---|
34 | #Create shallow water domain |
---|
35 | domain = Domain(points, vertices, boundary) |
---|
36 | domain.smooth = False |
---|
37 | domain.visualise = False |
---|
38 | domain.visualise = True |
---|
39 | domain.default_order = 2 |
---|
40 | domain.filename = 'test_of_pyvolution' |
---|
41 | domain.store = True |
---|
42 | domain.format = 'sww' #Native netcdf visualisation format |
---|
43 | |
---|
44 | #Set bed-slope and friction |
---|
45 | inflow_stage = 0.1 |
---|
46 | manning = 0.1 |
---|
47 | Z = Weir(inflow_stage) |
---|
48 | |
---|
49 | print 'Field values' |
---|
50 | domain.set_quantity('elevation', Z) |
---|
51 | domain.set_quantity('friction', manning) |
---|
52 | |
---|
53 | |
---|
54 | ###################### |
---|
55 | # Boundary conditions |
---|
56 | # |
---|
57 | print 'Boundaries' |
---|
58 | Br = Reflective_boundary(domain) |
---|
59 | Bt = Transmissive_boundary(domain) |
---|
60 | |
---|
61 | #Constant inflow |
---|
62 | Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0]) |
---|
63 | |
---|
64 | #Time dependent inflow |
---|
65 | from math import sin, pi |
---|
66 | Bw = Time_boundary(domain=domain, |
---|
67 | f=lambda x: [(1 + sin(x*pi/4))*\ |
---|
68 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]) |
---|
69 | |
---|
70 | #Set boundary conditions |
---|
71 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | ###################### |
---|
76 | #Initial condition |
---|
77 | # |
---|
78 | print 'Initial condition' |
---|
79 | domain.set_quantity('stage', Constant_height(Z, 0.)) |
---|
80 | |
---|
81 | from Numeric import allclose |
---|
82 | |
---|
83 | #Evolve |
---|
84 | for t in domain.evolve(yieldstep = 0.1, finaltime = 30): |
---|
85 | domain.write_time() |
---|
86 | domain.boundary_stats(['stage'],'left') |
---|
87 | |
---|
88 | print 'Done' |
---|
89 | |
---|
90 | |
---|