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 | # Import necessary modules |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular |
---|
15 | from anuga.shallow_water import Domain |
---|
16 | from anuga.shallow_water.shallow_water_domain import Reflective_boundary |
---|
17 | from anuga.shallow_water.shallow_water_domain import Dirichlet_boundary |
---|
18 | from anuga.shallow_water.shallow_water_domain import Inflow |
---|
19 | |
---|
20 | #------------------------------------------------------------------------------ |
---|
21 | # Setup computational domain |
---|
22 | #------------------------------------------------------------------------------ |
---|
23 | |
---|
24 | #N = 120 |
---|
25 | N = 40 |
---|
26 | points, vertices, boundary = rectangular(N, N) |
---|
27 | domain = Domain(points, vertices, boundary) |
---|
28 | domain.set_name('kitchen_sink') # Output name |
---|
29 | print 'Size', len(domain) |
---|
30 | |
---|
31 | |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | # Setup initial conditions |
---|
34 | #------------------------------------------------------------------------------ |
---|
35 | |
---|
36 | domain.set_quantity('elevation', 0.0) # Zero bed elevation |
---|
37 | domain.set_quantity('stage', 0.0) # Constant stage |
---|
38 | domain.set_quantity('friction', 0.005) # Constant friction |
---|
39 | |
---|
40 | |
---|
41 | #------------------------------------------------------------------------------ |
---|
42 | # Setup specialised forcing terms |
---|
43 | #------------------------------------------------------------------------------ |
---|
44 | |
---|
45 | sink = Inflow(center=[0.7, 0.4], radius=0.0707, flow=0.0) |
---|
46 | tap = Inflow(center=(0.5, 0.5), radius=0.0316, |
---|
47 | flow=lambda t: min(0.01*t, 0.0142)) # Tap turning up |
---|
48 | |
---|
49 | |
---|
50 | domain.forcing_terms.append(tap) |
---|
51 | domain.forcing_terms.append(sink) |
---|
52 | |
---|
53 | #------------------------------------------------------------------------------ |
---|
54 | # Setup boundary conditions |
---|
55 | #------------------------------------------------------------------------------ |
---|
56 | |
---|
57 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
58 | domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
59 | |
---|
60 | #------------------------------------------------------------------------------ |
---|
61 | # Evolve system through time |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | from math import sin |
---|
64 | for t in domain.evolve(yieldstep = 0.01, finaltime = 20): |
---|
65 | domain.write_time() |
---|
66 | |
---|
67 | if domain.get_time() >= 6 and tap.flow != 0.0: |
---|
68 | print 'Turning tap off' |
---|
69 | tap.flow = 0.0 |
---|
70 | |
---|
71 | if domain.get_time() >= 3 and sink.flow == 0.0: |
---|
72 | print 'Turning drain on' |
---|
73 | sink.flow = lambda t: -0.04 + sin(t)*0.005 |
---|
74 | |
---|