def calc_vavg(tau,A,m,n,N0,Nz,c,phi,sigma=False): """Calculating average sediment velocities. tau: basal shear stress A: flow law factor m: exponent of effective pressure n: exponent of basal shear stress N0: effective pressure Nz: effective pressure gradient c: cohesion phi: angle of internal friction""" za = calc_za(tau,N0,Nz,c,phi) v = numpy.zeros(len(tau),numpy.float) if sigma: f = flow2 else: f = flow1 for i in range(0,len(v)): sys = integrate.gsl_function(f,[tau[i],A,m,n,N0,Nz,c,phi,0.]) flag,result,error,num = integrate.qng(sys,za[i],0.,1e-6, 1e-6) if flag != 0: print flag if za[i]!=0: v[i] = -result/za[i] return v
def test_qng(self): def f1(x,y): return Numeric.sin(x) sys = integrate.gsl_function(f1, None) flag, result, error, method = integrate.qng(sys, 0, Numeric.pi, 1e-8, 1e-8) assert(Numeric.absolute(result - 2) < 1e-7) assert(error<1e-8)
def calc_vsld(tau,A,m,n,N0,Nz,c,phi,sigma=False): za = calc_za(tau,N0,Nz,c,phi) v = numpy.zeros(len(tau),numpy.float) if sigma: f = flow2 else: f = flow1 for i in range(0,len(v)): sys = integrate.gsl_function(f,[tau[i],A,m,n,N0,Nz,c,phi,None]) flag,result,error,num = integrate.qng(sys,za[i],0.,1e-8, 1e-8) if flag != 0: print flag v[i] = result return v
def run_fail(): """Demonstrates pygsl capabilites in finding problems with callbacks """ def f1(x, *args): return None import pygsl sys = integrate.gsl_function(f1, None) # Enables printing debug messages. The higher the level the more information # will be displayed #pygsl.set_debug_level(3) # Quite a few functions add traceback frames when they propage the error # through the different levels. If you can not understand the error messages # directly, looking at the source where the error occured can help. #pygsl.add_c_traceback_frames(True) flag, result, error, method = integrate.qng(sys, 0, numx.pi, 1e-8, 1e-8) pygsl.set_debug_level(0)