1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | Flat bed with wind stress |
---|
4 | |
---|
5 | """ |
---|
6 | |
---|
7 | ###################### |
---|
8 | # Module imports |
---|
9 | # |
---|
10 | from mesh_factory import rectangular |
---|
11 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
12 | Transmissive_boundary, Constant_height, Wind_stress |
---|
13 | from Numeric import array |
---|
14 | |
---|
15 | #Create basic mesh |
---|
16 | N = 80 |
---|
17 | len1 = 100 |
---|
18 | len2 = 100 |
---|
19 | points, vertices, boundary = rectangular(N, N, len1, len2) |
---|
20 | |
---|
21 | #Create shallow water domain |
---|
22 | domain = Domain(points, vertices, boundary) |
---|
23 | domain.smooth = True |
---|
24 | domain.visualise = False |
---|
25 | domain.store = True |
---|
26 | domain.default_order=2 |
---|
27 | domain.set_name('wind_rotation') |
---|
28 | |
---|
29 | #Set initial conditions |
---|
30 | |
---|
31 | depth = 2 |
---|
32 | |
---|
33 | def x_slope(x, y): |
---|
34 | return 0*x/10 |
---|
35 | |
---|
36 | domain.set_quantity('elevation', x_slope) |
---|
37 | domain.set_quantity('level', Constant_height(x_slope, depth)) |
---|
38 | |
---|
39 | #Set driving forces |
---|
40 | manning = 0.0 |
---|
41 | domain.set_quantity('friction', manning) |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | #Constant windfield implemented using functions |
---|
46 | #domain.forcing_terms.append(Wind_stress(5000, 30)) |
---|
47 | |
---|
48 | #Constant windfield implemented using (lambda) functions |
---|
49 | #domain.forcing_terms.append(Wind_stress(lambda x,y,t: 5000, lambda x,y,t: 30)) |
---|
50 | |
---|
51 | #Variable windfield implemented using functions |
---|
52 | def speed(x,y,t): |
---|
53 | """Large speeds halfway between center and edges |
---|
54 | Low speeds at center and edges |
---|
55 | """ |
---|
56 | |
---|
57 | from math import sqrt, exp, cos, pi |
---|
58 | |
---|
59 | c = (len1/2, len2/2) |
---|
60 | r = sqrt((x - c[0])**2 + (y - c[1])**2) |
---|
61 | |
---|
62 | r /= max(len1,len2) |
---|
63 | |
---|
64 | factor = exp( -(r-0.15)**2 ) |
---|
65 | |
---|
66 | #print x,y,factor |
---|
67 | |
---|
68 | return 4000 * factor * (cos(t*2*pi/150) + 2) |
---|
69 | |
---|
70 | |
---|
71 | def phi(x,y,t): |
---|
72 | """Rotating field |
---|
73 | """ |
---|
74 | from math import sqrt, atan, pi |
---|
75 | |
---|
76 | c = (len1/2, len2/2) |
---|
77 | r = sqrt((x - c[0])**2 + (y - c[1])**2) |
---|
78 | |
---|
79 | xx = (x - c[0])/len1 |
---|
80 | yy = (y - c[1])/len2 |
---|
81 | |
---|
82 | angle = atan(yy/xx) |
---|
83 | |
---|
84 | if xx < 0: |
---|
85 | angle+=pi #atan in ]-pi/2; pi/2[ |
---|
86 | |
---|
87 | #Take normal direction |
---|
88 | angle -= pi/2 |
---|
89 | |
---|
90 | #Ensure positive radians |
---|
91 | if angle < 0: |
---|
92 | angle += 2*pi |
---|
93 | |
---|
94 | return angle/pi*180 |
---|
95 | |
---|
96 | |
---|
97 | domain.forcing_terms.append(Wind_stress(speed, phi)) |
---|
98 | |
---|
99 | #Add lateral wind gusts bearing 25 deg |
---|
100 | def gust(x,y,t): |
---|
101 | from math import sin, pi |
---|
102 | |
---|
103 | tt = sin(2*pi*t/200) |
---|
104 | |
---|
105 | if tt > 0.9: |
---|
106 | return 6000*tt |
---|
107 | else: |
---|
108 | return 0 |
---|
109 | |
---|
110 | domain.forcing_terms.append(Wind_stress(gust, 25)) |
---|
111 | |
---|
112 | |
---|
113 | ###################### |
---|
114 | # Boundary conditions |
---|
115 | Br = Reflective_boundary(domain) |
---|
116 | Bd = Dirichlet_boundary([depth, 0, 0]) |
---|
117 | |
---|
118 | domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
119 | #domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) |
---|
120 | #domain.set_boundary({'left': Br, 'right': Bd, 'top': Bd, 'bottom': Bd}) |
---|
121 | domain.check_integrity() |
---|
122 | |
---|
123 | |
---|
124 | ###################### |
---|
125 | #Evolution |
---|
126 | for t in domain.evolve(yieldstep = 0.5, finaltime = 1000): |
---|
127 | domain.write_time() |
---|
128 | |
---|
129 | print 'Done' |
---|
130 | |
---|