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 | import anuga |
---|
13 | |
---|
14 | from math import cos |
---|
15 | from numpy import zeros, float |
---|
16 | from time import localtime, strftime, gmtime |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | #------------------------------------------------------------------------------- |
---|
21 | # Copy scripts to time stamped output directory and capture screen |
---|
22 | # output to file |
---|
23 | #------------------------------------------------------------------------------- |
---|
24 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
25 | |
---|
26 | output_dir = 'dam_break_'+time |
---|
27 | output_file = 'dam_break' |
---|
28 | |
---|
29 | anuga.copy_code_files(output_dir,__file__) |
---|
30 | #start_screen_catcher(output_dir+'_') |
---|
31 | |
---|
32 | |
---|
33 | #------------------------------------------------------------------------------ |
---|
34 | # Setup domain |
---|
35 | #------------------------------------------------------------------------------ |
---|
36 | dx = 200. |
---|
37 | dy = dx |
---|
38 | L = 100000. |
---|
39 | W = 10*dx |
---|
40 | |
---|
41 | # structured mesh |
---|
42 | points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
43 | |
---|
44 | domain = anuga.Domain(points, vertices, boundary) |
---|
45 | |
---|
46 | domain.set_name(output_file) |
---|
47 | domain.set_datadir(output_dir) |
---|
48 | |
---|
49 | #------------------------------------------------------------------------------ |
---|
50 | # Setup Algorithm |
---|
51 | #------------------------------------------------------------------------------ |
---|
52 | domain.set_timestepping_method('rk2') |
---|
53 | domain.set_default_order(2) |
---|
54 | |
---|
55 | print domain.get_timestepping_method() |
---|
56 | |
---|
57 | domain.use_edge_limiter = True |
---|
58 | domain.tight_slope_limiters = True |
---|
59 | domain.use_centroid_velocities = False |
---|
60 | |
---|
61 | domain.CFL = 1.0 |
---|
62 | |
---|
63 | domain.beta_w = 0.6 |
---|
64 | domain.beta_uh = 0.6 |
---|
65 | domain.beta_vh = 0.6 |
---|
66 | |
---|
67 | |
---|
68 | #------------------------------------------------------------------------------ |
---|
69 | # Setup initial conditions |
---|
70 | #------------------------------------------------------------------------------ |
---|
71 | domain.set_quantity('elevation',0.0) |
---|
72 | domain.set_quantity('friction', 0.0) |
---|
73 | |
---|
74 | h0 = 10.0 |
---|
75 | h1 = 0.0 |
---|
76 | |
---|
77 | def height(x,y): |
---|
78 | z = zeros(len(x), float) |
---|
79 | for i in range(len(x)): |
---|
80 | if x[i]<=50000.0: |
---|
81 | z[i] = h0 |
---|
82 | else: |
---|
83 | z[i] = h1 |
---|
84 | return z |
---|
85 | |
---|
86 | |
---|
87 | domain.set_quantity('stage', height) |
---|
88 | #----------------------------------------------------------------------------- |
---|
89 | # Setup boundary conditions |
---|
90 | #------------------------------------------------------------------------------ |
---|
91 | from math import sin, pi, exp |
---|
92 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
93 | Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary |
---|
94 | Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
95 | |
---|
96 | |
---|
97 | # Associate boundary tags with boundary objects |
---|
98 | domain.set_boundary({'left': Bt, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
99 | |
---|
100 | |
---|
101 | #=============================================================================== |
---|
102 | from anuga.visualiser import RealtimeVisualiser |
---|
103 | vis = RealtimeVisualiser(domain) |
---|
104 | vis.render_quantity_height("stage", zScale =h0*500, dynamic=True) |
---|
105 | vis.colour_height_quantity('stage', (0.0, 0.5, 1.0)) |
---|
106 | vis.start() |
---|
107 | #=============================================================================== |
---|
108 | |
---|
109 | |
---|
110 | #------------------------------------------------------------------------------ |
---|
111 | # Evolve system through time |
---|
112 | #------------------------------------------------------------------------------ |
---|
113 | |
---|
114 | for t in domain.evolve(yieldstep = 100.0, finaltime = 60*60.): |
---|
115 | print domain.timestepping_statistics(track_speeds=True) |
---|
116 | vis.update() |
---|
117 | |
---|
118 | vis.evolveFinished() |
---|
119 | |
---|