1 | """ |
---|
2 | Dam break! |
---|
3 | """ |
---|
4 | |
---|
5 | #------------------------------------------------------------------------------ |
---|
6 | # Import necessary modules |
---|
7 | #------------------------------------------------------------------------------ |
---|
8 | |
---|
9 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
10 | |
---|
11 | from anuga.shallow_water import Domain |
---|
12 | from anuga.shallow_water import Reflective_boundary |
---|
13 | from anuga.shallow_water import Dirichlet_boundary |
---|
14 | |
---|
15 | from anuga.utilities.polygon import read_polygon, plot_polygons |
---|
16 | from anuga.utilities.polygon import Polygon_function |
---|
17 | |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | # Setup computational domain |
---|
20 | #------------------------------------------------------------------------------ |
---|
21 | length = 20. |
---|
22 | width = 10. |
---|
23 | dx = dy = 2 # Resolution: Length of subdivisions on both axes |
---|
24 | |
---|
25 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
26 | len1=length, len2=width) |
---|
27 | |
---|
28 | domain = Domain(points, vertices, boundary) # Create domain |
---|
29 | domain.set_name('dam_sample') # Output name |
---|
30 | #domain.set_store_vertices_uniquely(True) # Look at the 'real' triangles |
---|
31 | domain.set_minimum_allowed_height(0.01) |
---|
32 | |
---|
33 | #------------------------------------------------------------------------------ |
---|
34 | # Setup initial conditions |
---|
35 | #------------------------------------------------------------------------------ |
---|
36 | |
---|
37 | # Polygons |
---|
38 | study = [[0,0], [20,0], [20,10], [0,10], [0,0]] |
---|
39 | #dam = [[0,0], [6,0], [6,10], [0,10], [0,0]] |
---|
40 | poly_dam = read_polygon('dam.csv') |
---|
41 | print poly_dam |
---|
42 | #plot_polygons([poly_dam]) |
---|
43 | |
---|
44 | |
---|
45 | def dam1(x,y): |
---|
46 | z = -x/10 #initialise with slope (this is required to create the vector z?) |
---|
47 | X = len(x) #find the number of vector elements |
---|
48 | for i in range(X): |
---|
49 | if 6<= x[i]<=7 or x[i]<1: #dam wall |
---|
50 | z[i] = 2 |
---|
51 | if 6<= x[i] <=7 and 4<= y[i] <=6: #remove unwanted wall |
---|
52 | z[i] = -x[i]/10 |
---|
53 | return z |
---|
54 | |
---|
55 | def water(x,y): |
---|
56 | z = -x/10 #initialise with slope (this is required to create the vector z) |
---|
57 | X = len(x) #find the number of vector elements |
---|
58 | |
---|
59 | for i in range(X): |
---|
60 | if x[i]<=6: #dam |
---|
61 | z[i]= 2 |
---|
62 | |
---|
63 | return z |
---|
64 | |
---|
65 | ##manual definition |
---|
66 | # |
---|
67 | #domain.set_quantity('elevation', water) # Use function for elevation |
---|
68 | #domain.set_quantity('friction', 0.01) # Constant friction |
---|
69 | #domain.set_quantity('stage', expression='elevation') # take elevation |
---|
70 | #domain.set_quantity('elevation', dam1) # Use function for elevation |
---|
71 | |
---|
72 | |
---|
73 | # Assign values to quantities |
---|
74 | domain.set_quantity('elevation', dam1) # Use function for elevation |
---|
75 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
76 | domain.set_quantity('stage', Polygon_function( [(study, -1),(poly_dam, 2)] )) |
---|
77 | |
---|
78 | |
---|
79 | #------------------------------------------------------------------------------ |
---|
80 | # Setup boundary conditions |
---|
81 | #------------------------------------------------------------------------------ |
---|
82 | Bi = Dirichlet_boundary([1.5, 0, 0]) # Inflow |
---|
83 | Bo = Dirichlet_boundary([-20/10, 0, 0]) # Outflow |
---|
84 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
85 | |
---|
86 | domain.set_boundary({'left': Br, 'right': Bo, 'top': Br, 'bottom': Br}) |
---|
87 | |
---|
88 | |
---|
89 | #------------------------------------------------------------------------------ |
---|
90 | # Evolve system through time |
---|
91 | #------------------------------------------------------------------------------ |
---|
92 | for t in domain.evolve(yieldstep = 0.2, finaltime = 20): |
---|
93 | domain.write_time(track_speeds=False) |
---|
94 | |
---|