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 | #------------------------------------------------------------------------------ |
---|
9 | # Import necessary modules |
---|
10 | #------------------------------------------------------------------------------ |
---|
11 | |
---|
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 | |
---|
19 | from Numeric import zeros, Float |
---|
20 | from RandomArray import normal, seed |
---|
21 | |
---|
22 | seed(13, 17) # Ensure random number sequence is reproducible |
---|
23 | |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | # Setup computational domain |
---|
26 | #------------------------------------------------------------------------------ |
---|
27 | |
---|
28 | points, vertices, boundary = rectangular_cross(90, 30, |
---|
29 | len1=3.0, |
---|
30 | len2=1.0) # Basic mesh |
---|
31 | |
---|
32 | domain = Domain(points, vertices, boundary) # Create domain |
---|
33 | domain.set_name('sensitivity') # Output to file runup.sww |
---|
34 | domain.set_datadir('.') # Use current directory for output |
---|
35 | domain.tight_slope_limiters = 1 |
---|
36 | domain.beta_h = 0 |
---|
37 | |
---|
38 | #------------------------------------------------------------------------------ |
---|
39 | # Setup initial conditions |
---|
40 | #------------------------------------------------------------------------------ |
---|
41 | |
---|
42 | def topography(x,y): |
---|
43 | |
---|
44 | N = len(x) |
---|
45 | z = zeros(N, Float) |
---|
46 | |
---|
47 | |
---|
48 | for i in range(N): |
---|
49 | # linear bed slope |
---|
50 | z[i] = -x[i]/15 |
---|
51 | |
---|
52 | # IID noise |
---|
53 | z[i] += normal(0.0, 0.01) |
---|
54 | |
---|
55 | return z |
---|
56 | |
---|
57 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
58 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
59 | domain.set_quantity('stage', -.4) # Constant negative initial stage |
---|
60 | |
---|
61 | |
---|
62 | #------------------------------------------------------------------------------ |
---|
63 | # Setup boundary conditions |
---|
64 | #------------------------------------------------------------------------------ |
---|
65 | |
---|
66 | from math import sin, pi, exp |
---|
67 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
68 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
69 | Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values |
---|
70 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
71 | f=lambda t: [(.1*sin(t*2*pi)-0.1) , 0.0, 0.0]) |
---|
72 | |
---|
73 | # Associate boundary tags with boundary objects |
---|
74 | domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br}) |
---|
75 | |
---|
76 | |
---|
77 | import time |
---|
78 | t0 = time.time() |
---|
79 | #------------------------------------------------------------------------------ |
---|
80 | # Evolve system through time |
---|
81 | #------------------------------------------------------------------------------ |
---|
82 | |
---|
83 | for t in domain.evolve(yieldstep = 0.1, finaltime = 50.0): |
---|
84 | domain.write_time() |
---|
85 | |
---|
86 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
87 | |
---|