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