1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | Flat bed with rotational wind stress |
---|
4 | |
---|
5 | """ |
---|
6 | |
---|
7 | ###################### |
---|
8 | # Module imports |
---|
9 | # |
---|
10 | from mesh_factory import rectangular |
---|
11 | from shallow_water import Domain, Dirichlet_boundary, Wind_stress |
---|
12 | |
---|
13 | #Create basic mesh |
---|
14 | N = 20 |
---|
15 | length = 200 |
---|
16 | points, vertices, boundary = rectangular(N, N, length, length) |
---|
17 | |
---|
18 | #Create shallow water domain |
---|
19 | domain = Domain(points, vertices, boundary) |
---|
20 | domain.smooth = True |
---|
21 | domain.store = True |
---|
22 | domain.default_order=2 |
---|
23 | domain.set_name('wind_rotation') |
---|
24 | |
---|
25 | #Set initial conditions |
---|
26 | h = 1.0 |
---|
27 | domain.set_quantity('elevation', 0.0) |
---|
28 | domain.set_quantity('stage', h) |
---|
29 | domain.set_quantity('friction', 0.01) |
---|
30 | |
---|
31 | |
---|
32 | #Variable windfield implemented using functions |
---|
33 | def speed(t,x,y): |
---|
34 | """Large speeds halfway between center and edges |
---|
35 | Low speeds at center and edges |
---|
36 | """ |
---|
37 | |
---|
38 | from math import pi |
---|
39 | from Numeric import sqrt, exp, cos |
---|
40 | |
---|
41 | c = (length/2, length/2) |
---|
42 | r = sqrt((x - c[0])**2 + (y - c[1])**2)/length |
---|
43 | factor = exp( -(r-0.15)**2 ) |
---|
44 | |
---|
45 | #return 9000 * factor |
---|
46 | return 4000 * factor * (cos(t*2*pi/150) + 2) |
---|
47 | |
---|
48 | |
---|
49 | def phi(t,x,y): |
---|
50 | """Rotating field |
---|
51 | """ |
---|
52 | |
---|
53 | from math import pi |
---|
54 | from Numeric import sqrt, exp, cos, arctan2, choose, less |
---|
55 | |
---|
56 | c = (length/2, length/2) |
---|
57 | xx = (x - c[0])/length |
---|
58 | yy = (y - c[1])/length |
---|
59 | angle = arctan2(yy,xx) |
---|
60 | |
---|
61 | #Take normal direction (but reverse direction every 50 seconds) |
---|
62 | #if sin(t*2*pi/100) < 0: |
---|
63 | # sgn = -1 |
---|
64 | #else: |
---|
65 | # sgn = 1 |
---|
66 | #angle += sgn*pi/2 |
---|
67 | angle -= pi/2 |
---|
68 | |
---|
69 | #Convert to degrees and return |
---|
70 | return angle/pi*180 |
---|
71 | |
---|
72 | |
---|
73 | domain.forcing_terms.append( Wind_stress(speed, phi) ) |
---|
74 | |
---|
75 | |
---|
76 | #Add lateral wind gusts bearing 25 deg |
---|
77 | def gust(t,x,y): |
---|
78 | from math import sin, pi |
---|
79 | from Numeric import zeros, ones, Float |
---|
80 | |
---|
81 | N = len(x) |
---|
82 | |
---|
83 | tt = sin(2*pi*t/200) |
---|
84 | |
---|
85 | if tt > 0.9: |
---|
86 | return 6000*tt*ones(N, Float) |
---|
87 | else: |
---|
88 | return zeros(N, Float) |
---|
89 | |
---|
90 | domain.forcing_terms.append(Wind_stress(gust, 25)) |
---|
91 | |
---|
92 | |
---|
93 | ###################### |
---|
94 | # Boundary conditions |
---|
95 | #Br = Reflective_boundary(domain) |
---|
96 | Bd = Dirichlet_boundary([h, 0, 0]) |
---|
97 | domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd}) |
---|
98 | |
---|
99 | ###################### |
---|
100 | #Evolution |
---|
101 | for t in domain.evolve(yieldstep = 0.5, finaltime = 1000): |
---|
102 | domain.write_time() |
---|
103 | |
---|
104 | print 'Done' |
---|
105 | |
---|