1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water driven up a linear slope and time varying boundary, |
---|
4 | similar to a beach environment |
---|
5 | """ |
---|
6 | |
---|
7 | #------------------------------------------------------------------------------ |
---|
8 | # Import necessary modules |
---|
9 | #------------------------------------------------------------------------------ |
---|
10 | |
---|
11 | import sys |
---|
12 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
13 | from anuga.shallow_water import Domain |
---|
14 | from anuga.shallow_water import Reflective_boundary |
---|
15 | from anuga.shallow_water import Dirichlet_boundary |
---|
16 | from anuga.shallow_water import Time_boundary |
---|
17 | from anuga.shallow_water import Transmissive_boundary |
---|
18 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
19 | #from anuga.geospatial_data.geospatial_data import * |
---|
20 | from math import cos |
---|
21 | from Numeric import zeros, Float |
---|
22 | |
---|
23 | #------------------------------------------------------------------------------ |
---|
24 | # Setup computational domain |
---|
25 | #------------------------------------------------------------------------------ |
---|
26 | dx = 200. |
---|
27 | dy = dx |
---|
28 | L = 100000. |
---|
29 | W = dx |
---|
30 | |
---|
31 | # structured mesh |
---|
32 | points, vertices, boundary = rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
33 | |
---|
34 | domain = Domain(points, vertices, boundary) |
---|
35 | |
---|
36 | domain.set_timestepping_method('rk2') |
---|
37 | domain.set_default_order(2) |
---|
38 | domain.set_name('myexample9') |
---|
39 | domain.set_datadir('.') # Use current directory for output |
---|
40 | |
---|
41 | domain.set_all_limiters(0.9) |
---|
42 | |
---|
43 | print domain.beta_w |
---|
44 | domain.use_old_limiter = False |
---|
45 | domain.CFL = 1.0 |
---|
46 | |
---|
47 | #------------------------------------------------------------------------------ |
---|
48 | # Setup initial conditions |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | #domain.set_quantity('elevation', topography) # Use function for elevation |
---|
51 | domain.set_quantity('elevation',0.0) |
---|
52 | domain.set_quantity('friction', 0.00) |
---|
53 | |
---|
54 | h0 = 10.0 |
---|
55 | h1 = 1.0 |
---|
56 | |
---|
57 | def height(x,y): |
---|
58 | z = zeros(len(x),Float) |
---|
59 | for i in range(len(x)): |
---|
60 | if x[i]<=50000.0: |
---|
61 | z[i] = h0 |
---|
62 | else: |
---|
63 | z[i] = h1 |
---|
64 | return z |
---|
65 | |
---|
66 | |
---|
67 | domain.set_quantity('stage', height) |
---|
68 | #domain.set_quantity('stage', 0.0) |
---|
69 | |
---|
70 | #----------------------------------------------------------------------------- |
---|
71 | # Setup boundary conditions |
---|
72 | #------------------------------------------------------------------------------ |
---|
73 | from math import sin, pi, exp |
---|
74 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
75 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
76 | Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
77 | amplitude = 1 |
---|
78 | #Bw = Transmissive_Momentum_Set_Stage_boundary(domain=domain, |
---|
79 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
80 | ## Sine wave |
---|
81 | # f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0]) |
---|
82 | ## Single wave |
---|
83 | f=lambda t: [h0, 0.0, 0.0]) |
---|
84 | ## Sawtooth? |
---|
85 | # f=lambda t: [(-8.0*(sin((1./180.)*t*2*pi))+(1./2.)*sin((2./180.)*t*2*pi)+(1./3.)*sin((3./180.)*t*2*pi)), 0.0, 0.0]) |
---|
86 | ## Sharp rise, linear fall |
---|
87 | # f=lambda t: [(5.0*(-((t-0.)/300.)*(t<300.)-cos((t-300.)*2.*pi*(1./240.))*(t>=300. and t<420.)+(1.-(t-420.)/300.)*(t>=420. and t <720.))), 0.0, 0.0]) |
---|
88 | # f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0]) |
---|
89 | # f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0]) |
---|
90 | |
---|
91 | # Associate boundary tags with boundary objects |
---|
92 | domain.set_boundary({'left': Bw, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
93 | |
---|
94 | |
---|
95 | #=============================================================================== |
---|
96 | from anuga.visualiser import RealtimeVisualiser |
---|
97 | vis = RealtimeVisualiser(domain) |
---|
98 | #vis.render_quantity_height("elevation", zScale=1, offset = 5.0, dynamic=False) |
---|
99 | vis.render_quantity_height("stage", zScale =10000, dynamic=True) |
---|
100 | #vis.colour_height_quantity('stage', (lambda q:q['stage'], -1.0, 1.0)) |
---|
101 | vis.colour_height_quantity('stage', (1.0, 0.5, 0.5)) |
---|
102 | vis.start() |
---|
103 | #=============================================================================== |
---|
104 | |
---|
105 | |
---|
106 | #------------------------------------------------------------------------------ |
---|
107 | # Evolve system through time |
---|
108 | #------------------------------------------------------------------------------ |
---|
109 | |
---|
110 | for t in domain.evolve(yieldstep = 50.0, finaltime = 10*40*60.): |
---|
111 | domain.write_time() |
---|
112 | vis.update() |
---|
113 | |
---|
114 | vis.evolveFinished() |
---|
115 | |
---|