source: inundation/ga/storm_surge/pyvolution/wind_example_variable.py @ 643

Last change on this file since 643 was 624, checked in by ole, 20 years ago
File size: 2.2 KB
RevLine 
[519]1"""Example of shallow water wave equation.
2
[522]3Flat bed with rotational wind stress
[519]4
5"""
6
7######################
8# Module imports
9#
10from mesh_factory import rectangular
[614]11from shallow_water import Domain, Dirichlet_boundary, Wind_stress
[519]12
13#Create basic mesh
[624]14N = 20
[614]15length = 200
[612]16points, vertices, boundary = rectangular(N, N, length, length)
[519]17
18#Create shallow water domain
19domain = Domain(points, vertices, boundary)
20domain.smooth = True
21domain.visualise = False
22domain.store = True
23domain.default_order=2
24domain.set_name('wind_rotation')
25
26#Set initial conditions
[614]27h = 1.0
[522]28domain.set_quantity('elevation', 0.0)
[614]29domain.set_quantity('level', h)
30domain.set_quantity('friction', 0.01)
[519]31
32
33#Variable windfield implemented using functions
[624]34def 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]50def 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]74domain.forcing_terms.append( Wind_stress(speed, phi) )
[519]75
[522]76
[519]77#Add lateral wind gusts bearing 25 deg
[624]78def 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   
91domain.forcing_terms.append(Wind_stress(gust, 25))
92
93
94######################
95# Boundary conditions
[614]96#Br = Reflective_boundary(domain)
97Bd = Dirichlet_boundary([h, 0, 0])
98domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
[519]99
100######################
101#Evolution
102for t in domain.evolve(yieldstep = 0.5, finaltime = 1000):
103    domain.write_time()
104
105print 'Done'   
106
Note: See TracBrowser for help on using the repository browser.