source: production/sydney_2006/find_max.py @ 2869

Last change on this file since 2869 was 2869, checked in by sexton, 18 years ago

updates to slump/slide formulation and document

File size: 1.4 KB
Line 
1"""
2Determining maximum of SMF slump surface elevation function.
3Jane Sexton, GA 2006
4"""
5
6from math import exp, cosh
7import Numeric
8
9# Grilli and Watts 2005 example
10dx = 2.0
11x0 = 10.0
12y0 = 0.0
13w = 2.0
14kappa = 3
15g = 9.8
16d = 0.259
17T = 0.052
18theta = 15.0 
19lam0 = 5.0 
20   
21def func(x,y,kappad):
22    numerator = exp(-((x-x0)/lam0)**2.0) - kappad*exp(-((x-dx-x0)/lam0)**2.0)
23    denominator = cosh(kappa*(y-y0)/(w+lam0))**2.0
24    return -numerator/denominator
25
26def dfuncdx(x,kappad):
27    dfdx = (x-x0)*exp(-((x-x0)/lam0)**2.0)-kappad*(x-dx-x0)*exp(-((x-dx-x0)/lam0)**2.0)
28    return dfdx
29
30step = 0.001
31x = x0
32deriv = 10
33tol = 0.001
34c = 0
35direction = 'positive'
36while c < 100000 and deriv > 0:
37    deriv = dfuncdx(x,1.0)
38    if deriv < 0: xstar = x
39    if direction == 'positive': x += step
40    if direction == 'negative': x -= step
41    c += 1
42
43print 'location of maximum of surface elevation function: xstar = %f' % (xstar/lam0)
44const = 1.0 #a3D = ? #sydney = 86? and kappad=1
45
46x = arange(-20,25,0.001)
47y = arange(-10,10,0.1)
48X,Y = meshgrid(x,y)
49
50test = 0.0
51for xi in x:
52    testi = func(xi,0.0,1.0)
53    if direction == 'positive':
54        if testi > test:
55            test = testi
56            xstar = xi
57    else:
58        if testi < test:
59            test = testi
60            xstar = xi
61   
62print 'check: xstar = %f and eta(xstar) = %f' %(xstar/lam0, test)
Note: See TracBrowser for help on using the repository browser.