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