1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water flowing down a channel with more complex topography |
---|
4 | """ |
---|
5 | |
---|
6 | #------------------------------------------------------------------------------ |
---|
7 | # Import necessary modules |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
10 | from anuga.shallow_water import Domain |
---|
11 | from anuga.shallow_water import Reflective_boundary |
---|
12 | from anuga.shallow_water import Dirichlet_boundary |
---|
13 | from anuga.shallow_water import Time_boundary |
---|
14 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
15 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
16 | from math import tan, sqrt, sin, pi |
---|
17 | |
---|
18 | #------------------------------------------------------------------------------ |
---|
19 | # Setup computational domain |
---|
20 | #------------------------------------------------------------------------------ |
---|
21 | length = 30. |
---|
22 | width = 25. |
---|
23 | Cx = 12.96 # centre of island on the x axis |
---|
24 | Cy = 13.8 # centre of island on the y axis |
---|
25 | dx = dy = 1 # Resolution: Length of subdivisions on both axes |
---|
26 | water_depth = 0.32 |
---|
27 | |
---|
28 | #boundary |
---|
29 | poly_domain = [[0,0],[length,0],[length,width],[0,width]] |
---|
30 | meshname = 'test.msh' |
---|
31 | |
---|
32 | |
---|
33 | #Create interior region |
---|
34 | Dome = [[(Cx)-4,(Cy)-4],[(Cx)+4,(Cy)-4,], |
---|
35 | [(Cx)+4,(Cy)+4],[(Cx)-4,(Cy)+4]] |
---|
36 | |
---|
37 | remainder_res=1 |
---|
38 | Dome_res = .01 |
---|
39 | |
---|
40 | interior_dome = [[Dome, Dome_res]] |
---|
41 | |
---|
42 | #Create mesh |
---|
43 | create_mesh_from_regions(poly_domain, |
---|
44 | boundary_tags={'wavemaker': [0], 'right': [1], |
---|
45 | 'top': [2], 'left': [3]}, |
---|
46 | maximum_triangle_area = remainder_res, |
---|
47 | filename=meshname, |
---|
48 | interior_regions = interior_dome, |
---|
49 | use_cache=True, |
---|
50 | verbose=True) |
---|
51 | |
---|
52 | domain = Domain(meshname, use_cache=True, verbose = True) |
---|
53 | domain.set_name('circular') # Output name |
---|
54 | print domain.statistics() |
---|
55 | |
---|
56 | #------------------------------------------------------------------------------ |
---|
57 | # Setup initial conditions |
---|
58 | #------------------------------------------------------------------------------ |
---|
59 | def topography(x,y): |
---|
60 | """Complex topography defined by a function of vectors x and y |
---|
61 | """ |
---|
62 | |
---|
63 | |
---|
64 | z= 0*x # defining z for all values other than the if statements |
---|
65 | r= 3.6 # radius, provided in document |
---|
66 | angle = 14 # angle, provided in document |
---|
67 | h= r*tan(angle/57.2957795) # finding height of cone if not truncated |
---|
68 | |
---|
69 | |
---|
70 | N = len(x) |
---|
71 | for i in range(N): |
---|
72 | |
---|
73 | #truncated top |
---|
74 | if (x[i]-Cx)**2 + (y[i]-Cy)**2 <1.1**2: |
---|
75 | z[i] += 0.625 |
---|
76 | |
---|
77 | # cone |
---|
78 | if (x[i]-Cx)**2 + (y[i]-Cy)**2 <r**2 and (x[i]-Cx)**2 + (y[i]-Cy)**2 >1.1**2: |
---|
79 | z[i] = -(sqrt(((x[i]-Cx)**2+(y[i]-Cy)**2)/((r/h)**2))-h) |
---|
80 | return z |
---|
81 | |
---|
82 | domain.set_quantity('elevation', topography, verbose=True) # Use function for elevation |
---|
83 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
84 | domain.set_quantity('stage',water_depth) # Dry initial condition |
---|
85 | |
---|
86 | |
---|
87 | #------------------------------------------------------------------------------ |
---|
88 | # Setup boundary conditions |
---|
89 | #------------------------------------------------------------------------------ |
---|
90 | # Create boundary function from timeseries provided in file |
---|
91 | |
---|
92 | ##boundary_filename="ts2cnew1_input_20_80sec_new" |
---|
93 | ##prepare_timeboundary(boundary_filename+'.txt') |
---|
94 | ## |
---|
95 | ##function = file_function(boundary_filename+'.tms', |
---|
96 | ## domain, verbose=True) |
---|
97 | def wave_form(t): |
---|
98 | return 0.1*sin(2*pi*t/50.) |
---|
99 | |
---|
100 | # Create and assign boundary objects |
---|
101 | Bw = Dirichlet_boundary([water_depth, 0, 0]) #wall |
---|
102 | Bt = Transmissive_Momentum_Set_Stage_boundary(domain, wave_form) #wavemaker |
---|
103 | domain.set_boundary({'left': Bw, 'right': Bw, 'top': Bw, 'wavemaker': Bt}) |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | #------------------------------------------------------------------------------ |
---|
109 | # Evolve system through time |
---|
110 | #------------------------------------------------------------------------------ |
---|
111 | for t in domain.evolve(yieldstep = 0.2, finaltime = 100.0): |
---|
112 | print domain.timestepping_statistics() |
---|
113 | |
---|
114 | |
---|
115 | |
---|