1 | ## Automatically adapted for numpy.oldnumeric Oct 28, 2008 by alter_code1.py |
---|
2 | |
---|
3 | """Example of shallow water wave equation. |
---|
4 | |
---|
5 | Specific methods pertaining to the 2D shallow water equation |
---|
6 | are imported from shallow_water |
---|
7 | for use with the generic finite volume framework |
---|
8 | |
---|
9 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
10 | numerical vector named conserved_quantities. |
---|
11 | """ |
---|
12 | |
---|
13 | ###################### |
---|
14 | # Module imports |
---|
15 | # |
---|
16 | from anuga.shallow_water import Domain,\ |
---|
17 | Reflective_boundary, Dirichlet_boundary,\ |
---|
18 | Transmissive_boundary, Time_boundary |
---|
19 | from anuga.shallow_water.shallow_water_domain import Weir_simple as Weir |
---|
20 | |
---|
21 | from mesh_factory import rectangular |
---|
22 | from numpy.oldnumeric import array |
---|
23 | |
---|
24 | |
---|
25 | ###################### |
---|
26 | # Domain |
---|
27 | # |
---|
28 | |
---|
29 | N = 12 |
---|
30 | |
---|
31 | print 'Creating domain' |
---|
32 | #Create basic mesh |
---|
33 | points, vertices, boundary = rectangular(N, N/2, len1=1.2,len2=0.6, |
---|
34 | origin=(-0.07, 0)) |
---|
35 | |
---|
36 | print 'Number of elements', len(vertices) |
---|
37 | #Create shallow water domain |
---|
38 | domain = Domain(points, vertices, boundary) |
---|
39 | domain.smooth = False |
---|
40 | domain.default_order = 2 |
---|
41 | domain.set_name('show_balanced_limiters') |
---|
42 | domain.store = True |
---|
43 | domain.format = 'sww' #Native netcdf visualisation format |
---|
44 | |
---|
45 | #Set bed-slope and friction |
---|
46 | inflow_stage = 0.1 |
---|
47 | manning = 0.1 |
---|
48 | Z = Weir(inflow_stage) |
---|
49 | |
---|
50 | print 'Field values' |
---|
51 | domain.set_quantity('elevation', Z) |
---|
52 | domain.set_quantity('friction', manning) |
---|
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([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: [(1 + sin(x*pi/4))*\ |
---|
69 | (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]) |
---|
70 | |
---|
71 | #Set boundary conditions |
---|
72 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | ###################### |
---|
77 | #Initial condition |
---|
78 | # |
---|
79 | print 'Initial condition' |
---|
80 | domain.set_quantity('stage', Z) |
---|
81 | |
---|
82 | from numpy.oldnumeric import allclose |
---|
83 | |
---|
84 | #Evolve |
---|
85 | for t in domain.evolve(yieldstep = 0.1, finaltime = 30): |
---|
86 | domain.write_time(track_speeds=True) |
---|
87 | domain.write_boundary_statistics(['stage'],'left') |
---|
88 | |
---|
89 | print 'Done' |
---|
90 | |
---|
91 | |
---|