Example #1
0
    def fgrad_y_psi(self, y, psi, return_covar_chain=False):
        """
	gradient of f w.r.t to y and psi

	returns: NxIx3 tensor of partial derivatives

	"""

        # 1. exponentiate the a and b (positive!)
        mpsi = psi.copy()
        mpsi[:, 0:2] = SP.exp(mpsi[:, 0:2])
        w, s, r, d = self.fgrad_y(y, psi, return_precalc=True)

        gradients = SP.zeros((y.shape[0], len(mpsi), 3))
        for i in range(len(mpsi)):
            a, b, c = mpsi[i]
            gradients[:, i, 0] = a * (b * (1.0 / SP.cosh(s[i]))**2).flatten()
            gradients[:, i, 1] = b * (a * (1 - 2 * s[i] * r[i]) *
                                      (1.0 / SP.cosh(s[i]))**2).flatten()
            gradients[:, i, 2] = (-2 * a * (b**2) * r[i] *
                                  ((1.0 / SP.cosh(s[i]))**2)).flatten()

        covar_grad_chain = SP.zeros((y.shape[0], len(mpsi), 3))
        import numpy as NP
        for i in range(len(mpsi)):
            a, b, c = mpsi[i]
            covar_grad_chain[:, i, 0] = a * (r[i])
            covar_grad_chain[:, i, 1] = b * (a * (c + y[:, 0]) *
                                             (1.0 / SP.cosh(s[i]))**2)
            covar_grad_chain[:, i,
                             2] = a * b * ((1.0 / SP.cosh(s[i]))**2).flatten()

        if return_covar_chain:
            return gradients, covar_grad_chain
        return gradients
Example #2
0
	def backward_pass(self, a1L, a1R, a2L, a2LR, a2R, a3, z1Lb, z1LRb, z1Rb, z2b, xLb, xRb, t):
	 	
		# Third Layer
		if self.k == 2 :
			r3=	-t*self.sigmoid(-t*a3)
		else :
			r3 = a3 - t

		grad3=sp.dot(r3,z2b.T)
		
		# Second Layer
		r3w3T = sp.dot(self.w3[:,:-1].T, r3)

		r2L=r3w3T*a2LR*self.sigmoid(a2R)*self.divsigmoid(a2L)
		r2R=r3w3T*a2LR*self.sigmoid(a2L)*self.divsigmoid(a2R)
		r2LR=r3w3T*self.sigmoid(a2L)*self.sigmoid(a2R)
		
		grad2L = sp.dot(r2L, z1Lb.T)
		grad2LR = sp.dot(r2LR, z1LRb.T)
		grad2R = sp.dot(r2R, z1Rb.T)
		
		# First Layer
		r1L = sp.power(1.0/sp.cosh(a1L),2)*(sp.dot(self.w2l[:,:-1].T, r2L)+sp.dot(self.w2lr[:,:self.H1].T, r2LR))
		r1R = sp.power(1.0/sp.cosh(a1R),2)*(sp.dot(self.w2r[:,:-1].T, r2R)+sp.dot(self.w2lr[:,self.H1:-1].T, r2LR))
		
		grad1L = sp.dot(r1L, xLb.T)
		grad1R = sp.dot(r1R, xRb.T)
		
		
		return grad3, grad2L, grad2LR, grad2R, grad1L, grad1R
Example #3
0
def const(mode, W, K, R1):
#    return 0.6
    const_val_r = (W * required_xi(mode, K) / (constB_dash(mode, W, K, R1)*sc.cosh(m0(W)*K) +
                                     constC_dash(mode, W, K, R1)*sc.sinh(m0(W)*K)))
    const_val_l = (W * required_xi(mode, K) / (constB_dash(mode, W, K, R1)*sc.cosh(m0(W)*-K) +
                                     constC_dash(mode, W, K, R1)*sc.sinh(m0(W)*-K)))
    return min(const_val_r, const_val_l)
Example #4
0
    def fgrad_y_psi(self, y, psi, return_covar_chain = False):
        """
	gradient of f w.r.t to y and psi

	returns: NxIx3 tensor of partial derivatives

	"""

	# 1. exponentiate the a and b (positive!)
        mpsi = psi.copy()
        mpsi[:,0:2] = SP.exp(mpsi[:,0:2])
	w, s, r, d = self.fgrad_y(y, psi, return_precalc = True)

	gradients = SP.zeros((y.shape[0], len(mpsi), 3))
	for i in range(len(mpsi)):
	    a,b,c = mpsi[i]
	    gradients[:,i,0] = a*(b*(1.0/SP.cosh(s[i]))**2).flatten()
	    gradients[:,i,1] = b*(a*(1-2*s[i]*r[i])*(1.0/SP.cosh(s[i]))**2).flatten()
	    gradients[:,i,2] = (-2*a*(b**2)*r[i]*((1.0/SP.cosh(s[i]))**2)).flatten()

	covar_grad_chain = SP.zeros((y.shape[0], len(mpsi), 3))
	import numpy as NP
	for i in range(len(mpsi)):
	    a,b,c = mpsi[i]
	    covar_grad_chain[:, i, 0] = a*(r[i])
            covar_grad_chain[:, i, 1] = b*(a*(c+y[:,0])*(1.0/SP.cosh(s[i]))**2)
	    covar_grad_chain[:, i, 2] = a*b*((1.0/SP.cosh(s[i]))**2).flatten()
    
	if return_covar_chain:
	    return gradients, covar_grad_chain
	return gradients
Example #5
0
def v(mode, x, W, K, M_A):
    if np.real(x) < -K:
        return A(mode, W, M_A) * (sc.cosh(m1(W) * x) + sc.sinh(m1(W) * x))
    elif np.abs(np.real(x)) <= K:
        return B(mode, W, M_A) * sc.cosh(m0(W, M_A) * x) + C(
            mode, W, M_A) * sc.sinh(m0(W, M_A) * x)
    elif np.real(x) > K:
        return D(mode, W, M_A) * (sc.cosh(m2(W) * x) - sc.sinh(m2(W) * x))
Example #6
0
def Analiticna(t, ksi):  #analitična rešitev enačbe G-B

    A = []
    for j in range(len(t)):

        A.append(-2 * sc.log(sc.cosh(ksi * (1 - 2. * t[j])) / sc.cosh(ksi)))

    return A
Example #7
0
def approx( h = 1.0E-3 ) :
    #    print( "testing Runge-Kutta methods on the catenary" )
    print(h, end="\t")
    x0 = 0.0
    x1 = 1.0
    mu = 2.0
    s0 = array( [ 1.0 / mu, 0.0 ] )
    p = s0
    x = x0
    def cat( p ) :
        return array( [ p[1], mu * sqrt( 1.0 + p[1] * p[1] ) ] )
    while x + h < x1 :
        p = runge_kutta21( cat, p, h )
        x += h
    p = runge_kutta21( cat, p, x1 - x )
    x = x1
    #    print( "h = ", h )
    #    print( "final value = ", p )
    expected = array( [ cosh( mu * x1 ) / mu, sinh( mu * x1 ) ] )
    error = p - expected
    print(error, end="\t" )

    x0 = 0.0
    x1 = 1.0
    mu = 2.0
    s0 = array( [ 1.0 / mu, 0.0 ] )
    p = s0
    x = x0
    while x + h < x1 :
        p = runge_kutta1( cat, p, h )
        x += h
    p = runge_kutta1( cat, p, x1 - x )
    x = x1
    #    print( "h = ", h )
    #    print( "final value = ", p )
    expected = array( [ cosh( mu * x1 ) / mu, sinh( mu * x1 ) ] )
    error = p - expected
    print(error, end="\t" )

    x0 = 0.0
    x1 = 1.0
    mu = 2.0
    s0 = array( [ 1.0 / mu, 0.0 ] )
    p = s0
    x = x0
    while x + h < x1 :
        p = runge_kutta41( cat, p, h )
        x += h
    p = runge_kutta41( cat, p, x1 - x )
    x = x1
    #    print( "h = ", h )
    #    print( "final value = ", p )
    expected = array( [ cosh( mu * x1 ) / mu, sinh( mu * x1 ) ] )
    error = p - expected
    print( error )
Example #8
0
def xixhat_boundary(mode, W, K, R1, boundary='r'):
    if 'alfven' in mode:
        xixhat = 0.
    else:
        if boundary == 'r' or boundary == 'right':
            xixhat = (1j / W) * (constB(mode, W, K, R1)*sc.cosh(m0(W)*K) + 
                                     constC(mode, W, K, R1)*sc.sinh(m0(W)*K))
        if boundary == 'l' or boundary == 'left':
            xixhat = (1j / W) * (constB(mode, W, K, R1)*sc.cosh(m0(W)*-K) + 
                                     constC(mode, W, K, R1)*sc.sinh(m0(W)*-K))
    return xixhat
Example #9
0
def Analiticna(N, ksi):  #analitična rešitev enačbe G-B

    a = 0
    b = 1
    h = (b - a) * 1.0 / N
    A = []

    for j in range(0, N + 1):

        A.append(-2 * sc.log(sc.cosh(ksi * (1 - 2.0 * j * h)) / sc.cosh(ksi)))

    return A
Example #10
0
def double_tanh_warp(x, n, lcore, lmid, ledge, la, lb, xa, xb):
    r"""Implements a sum-of-tanh warping function and its derivative.
    
    .. math::
    
        l = a\tanh\frac{x-x_a}{l_a} + b\tanh\frac{x-x_b}{l_b}
    
    Parameters
    ----------
    x : float or array of float
        Locations to evaluate the function at.
    n : int
        Derivative order to take. Used for ALL of the points.
    lcore : float
        Core length scale.
    lmid : float
        Intermediate length scale.
    ledge : float
        Edge length scale.
    la : positive float
        Transition of first tanh.
    lb : positive float
        Transition of second tanh.
    xa : float
        Transition of first tanh.
    xb : float
        Transition of second tanh.
    
    Returns
    -------
    l : float or array
        Warped length scale at the given locations.

    Raises
    ------
    NotImplementedError
        If `n` > 1.
    """
    a, b, c = scipy.dot([[-0.5, 0, 0.5], [0, 0.5, -0.5], [0.5, 0.5, 0]],
                        [[lcore], [ledge], [lmid]])
    a = a[0]
    b = b[0]
    c = c[0]
    if n == 0:
        return a * scipy.tanh((x - xa) / la) + b * scipy.tanh(
            (x - xb) / lb) + c
    elif n == 1:
        return (a / la * (scipy.cosh(
            (x - xa) / la))**(-2.0) + b / lb * (scipy.cosh(
                (x - xb) / lb))**(-2.0))
    else:
        raise NotImplementedError(
            "Only derivatives up to order 1 are supported!")
Example #11
0
def double_tanh_warp(x, n, lcore, lmid, ledge, la, lb, xa, xb):
    r"""Implements a sum-of-tanh warping function and its derivative.

    .. math::

        l = a\tanh\frac{x-x_a}{l_a} + b\tanh\frac{x-x_b}{l_b}

    Parameters
    ----------
    x : float or array of float
        Locations to evaluate the function at.
    n : int
        Derivative order to take. Used for ALL of the points.
    lcore : float
        Core length scale.
    lmid : float
        Intermediate length scale.
    ledge : float
        Edge length scale.
    la : positive float
        Transition of first tanh.
    lb : positive float
        Transition of second tanh.
    xa : float
        Transition of first tanh.
    xb : float
        Transition of second tanh.

    Returns
    -------
    l : float or array
        Warped length scale at the given locations.

    Raises
    ------
    NotImplementedError
        If `n` > 1.
    """
    a, b, c = scipy.dot([[-0.5, 0, 0.5], [0, 0.5, -0.5], [0.5, 0.5, 0]],
                        [[lcore], [ledge], [lmid]])
    a = a[0]
    b = b[0]
    c = c[0]
    if n == 0:
        return a * scipy.tanh((x - xa) / la) + b * scipy.tanh((x - xb) / lb) + c
    elif n == 1:
        return (a / la * (scipy.cosh((x - xa) / la))**(-2.0) +
                b / lb * (scipy.cosh((x - xb) / lb))**(-2.0))
    else:
        raise NotImplementedError("Only derivatives up to order 1 are supported!")
Example #12
0
def uv_to_Rz(u,v,delta=1.):
    """
    NAME:

       uv_to_Rz

    PURPOSE:

       calculate R and z from prolate confocal u and v coordinates

    INPUT:

       u - confocal u

       v - confocal v

       delta= focus

    OUTPUT:

       (R,z)

    HISTORY:

       2012-11-27 - Written - Bovy (IAS)

    """
    R= delta*sc.sinh(u)*sc.sin(v)
    z= delta*sc.cosh(u)*sc.cos(v)
    return (R,z)
def cal_2D(c0, sigma_, what="Delta_cos", z=1, add_MD=False):
    # c0 should use mol/m^3
    sigma = -sigma_
    psi_L = -2 * const.k * T / z / const.e * scipy.arcsinh(
        sigma / scipy.sqrt(8 * c0 * const.N_A * eps_w * const.k * T))
    psi_2D = psi_L - sigma / C_H
    A = scipy.sqrt(2 * z**2 * const.e**2 * eps_w * c0 * const.N_A / const.k /
                   T)
    B = z * const.e * psi_L / (2 * const.k * T)
    C_L = A * scipy.cosh(B)
    l_D = scipy.sqrt(eps_w * const.k * T /
                     (2 * z**2 * const.e**2 * c0 * const.N_A))
    Delta_Phi_el = -sigma**2 / (2 * C_H) - sigma**2 / (C_L + eps_w / l_D)
    if add_MD is True:
        n = sigma_ / (const.e * 10**13 * 10**4)
        Delta_Phi_MD = f_MD(n)
        Delta_Phi_el += Delta_Phi_MD
    Delta_cos = -Delta_Phi_el / gamma_w

    # Classical value
    # C = scipy.sqrt(32*const.k**3*T**3*eps_w*c0*const.N_A/z**2/const.e**2)
    # Delta_Phi_el = -sigma**2/(2*C_H) - C*(scipy.cosh(B)-1)
    # Delta_cos = -Delta_Phi_el/gamma_w

    # Classical value
    # sigma = scipy.sqrt(8*c0*const.N_A*eps_w*const.k*T)*scipy.sinh(z*const.e*psi_L/2/const.k/T)
    # C = scipy.sqrt(32*const.k**3*T**3*eps_w*c0*const.N_A/z**2/const.e**2)
    # Delta_Phi_el = -sigma**2/(2*C_H) - C*(scipy.cosh(B)-1)
    # Delta_cos = -Delta_Phi_el/gamma_w
    if what is "Delta_Phi_el":
        return Delta_Phi_el
    elif what is "Delta_cos":
        return Delta_cos
Example #14
0
    def f(self,x,t):
        N = len(x)/2
        xdot = pl.array([])

        # modulus the x for periodicity.
        x[N:2*N]= x[N:2*N]%self.d
        # HERE ---->> 1Dify
        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive x interparticle force of j on i
                temp += self.qq*(x[N+i]-x[N+j])/(pl.sqrt((x[N+i]-x[N+j])**2)**3)
                # All of the forces coming from the 'same' paricle but from other 'cells' due to the
                # periodic contrains can be wraped up in a sum that converges to an aswer that can
                # be expressed in terms of polygamma functions (se pg 92 of notebook).
                temp += self.qq*(polygamma(1,(self.d+x[N+i]-x[N+j])/self.d)-polygamma(1,1.0-((x[N+i]-x[N+j])/self.d)))/(self.d**2)
            # EC x force on particle i
            for a in range(2):
                temp+=self.As[i]*pl.sin(x[N+i]-a*pl.pi)*pl.cos(t-a*pl.pi)/(pl.cosh(1.0)-pl.cos(x[N+i]-a*pl.pi)) 
            temp -= self.beta*x[i]
            xdot = pl.append(xdot,temp)

        for i in range(N):
            xdot = pl.append(xdot,x[i])

    
        return xdot
Example #15
0
def log_d_pois_like_trunc_5(d,s1,s2,a,p):
    """double poisson w max 5 goals"""
    #dp = np.sign(d)*np.power(np.abs(d),p)
    dp = 1.5*np.arctan(d)    #print(dp)
    return ( log(a)*(s1+s2)+dp*(s1-s2) - 2*a*cosh(dp)
         -gammaln(s1+1) - gammaln(s2+1) 
        -log(gammaincc(6,a*exp(-dp))*gammaincc(6,a*exp(dp)) ) ) 
Example #16
0
def cosh(ent):
    """Polymorphic cosh function that adapts to either a numeric or
    symbolic string input."""
    if isinstance(ent,str):
        return symstr('cosh('+ent+')')
    else:
        return scipy.cosh(ent)
Example #17
0
def mtanh_profile(X, n, x0, delta, alpha, h, b):
    """Profile used with the mtanh function to fit profiles, suitable for use with :py:class:`MeanFunction`.
    
    Only supports univariate data!
    
    Parameters
    ----------
    X : array, (`M`, 1)
        The points to evaluate at.
    n : array, (1,)
        The order of derivative to compute. Only up to first derivatives are
        supported.
    x0 : float
        Pedestal center
    delta : float
        Pedestal halfwidth
    alpha : float
        Core slope
    h : float
        Pedestal height
    b : float
        Pedestal foot
    """
    X = X[:, 0]
    z = (x0 - X) / delta
    if n[0] == 0:
        return (h + b) / 2.0 + (h - b) * mtanh(alpha, z) / 2.0
    elif n[0] == 1:
        return -(h - b) / (2.0 * delta) * (1 + alpha / 4.0 *
                                           (1 + 2 * z + scipy.exp(2 * z))) / (
                                               scipy.cosh(z))**2
    else:
        raise NotImplementedError(
            "Derivatives of order greater than 1 are not supported!")
Example #18
0
def log_d_pois_like_trunc_5(d,s1,s2,a,p):
    """double poisson w max 5 goals"""
    #dp = np.sign(d)*np.power(np.abs(d),p)
    dp = 1.5*np.arctan(d)    #print(dp)
    return ( log(a)*(s1+s2)+dp*(s1-s2) - 2*a*cosh(dp)
         -gammaln(s1+1) - gammaln(s2+1) 
        -log(gammaincc(6,a*exp(-dp))*gammaincc(6,a*exp(dp)) ) ) 
 def __init__(self, eta, beta, L, no_angles, no_pulses, order=5):
     self.mod_K = SourceModule(RADON_KERNEL.format(order, no_angles, no_pulses))
     self.K_gpu = self.mod_K.get_function("K_l")
     self.mod_reduction = SourceModule(REDUCTION_KERNEL)
     self.reduction_gpu = self.mod_reduction.get_function("reduction")
     self.eta = eta
     self.gamma = gamma(eta)
     self.beta = beta
     self.L = L
     self.h = calc_h(L, beta, eta)
     drv.memcpy_htod(self.mod_K.get_global("rsq4pi")[0], scipy.array([1./sqrt(4.*pi)], dtype=scipy.float32))
     drv.memcpy_htod(self.mod_K.get_global("sqeta")[0], scipy.array([sqrt(self.eta)], dtype=scipy.float32))
     drv.memcpy_htod(self.mod_K.get_global("h")[0], scipy.array([self.h], dtype=scipy.float32))
     drv.memcpy_htod(self.mod_K.get_global("four_pi_gamma")[0],
                     scipy.array([4.*pi*self.gamma], dtype=scipy.float32))
     y = sqrt(self.gamma)/self.h
     drv.memcpy_htod(self.mod_K.get_global("y")[0], scipy.array([y], dtype=scipy.float32))
     n = scipy.arange(1, order+1, dtype=scipy.float32)
     n2 = n**2
     ex = exp(-n2/4.)
     pre_s2 = ex*cosh(n*y)
     pre_s3 = ex*n*sinh(n*y)
     drv.memcpy_htod(self.mod_K.get_global("n2")[0], n2)
     drv.memcpy_htod(self.mod_K.get_global("pre_s1")[0], ex)
     drv.memcpy_htod(self.mod_K.get_global("pre_s2")[0], pre_s2)
     drv.memcpy_htod(self.mod_K.get_global("pre_s3")[0], pre_s3)
Example #20
0
def soliton(x, t, theta):
    """
	One soliton solution of the sine-Gordon equation:
	u_{tt} - u_{xx} + sin(u) = 0
	with soliton rapidity theta
	"""
    z = cosh(theta) * x - sinh(theta) * t
    return 4 * arctan(exp(z))
Example #21
0
def vz_pert(mode, x, z, t, W, K, R1):
    vz_hat_vals = np.zeros((len(x), len(z)), dtype=complex)
    vz_vals = np.zeros((len(x), len(z)), dtype=complex)
    for i in range(len(x)):
        for j in range(len(z)):
            def func(r):
                return [r[0] - x[i] + xix(mode, r[0], r[1], t, W, K, R1), 
                        r[1] - z[j] + xiz(mode, r[0], r[1], t, W, K, R1)]
            sol = np.real(fsolve(func, [x[i],z[j]], xtol=1e-03))
            if abs(sol[0]) <= K:
                vz_hat_vals[i,j] = (1j * c0**2 / (c0**2 - W**2)) * m0(W)*(constB(mode, W, K, R1)*sc.sinh(m0(W)*sol[0]) +
                                       constC(mode, W, K, R1)*sc.cosh(m0(W)*sol[0]))
            elif sol[0] < -K:
                vz_hat_vals[i,j] = (1j * c1(R1)**2 / (c1(R1)**2 - W**2)) * m1(W, R1)*constA(mode, W, K, R1)*(sc.sinh(m1(W, R1)*sol[0]) + 
                                                                 sc.cosh(m1(W, R1)*sol[0]))
            elif sol[0] > K:
                vz_hat_vals[i,j] = (1j * c2**2 / (c2**2 - W**2)) * m2(W)*constD(mode, W, K, R1)*(sc.sinh(m2(W)*sol[0]) -
                                                             sc.cosh(m2(W)*sol[0]))
            vz_vals[i,j] = vz_hat_vals[i,j] * np.exp(1j*(z[j]-t))
    return vz_vals    
Example #22
0
def rho_hat(mode, x, W, K, R1):
    truth = np.array(np.abs(x) <= K*np.ones(len(x)))
    indices = np.where(truth == True)
    rho_hatfunction = np.zeros(len(x), dtype=complex)
    for i in indices:
        rho_hatfunction[i] = m0(W)*(constB(mode, W, K, R1)*sc.sinh(m0(W)*x[i]) +
                             constC(mode, W, K, R1)*sc.cosh(m0(W)*x[i])) * lamb00(W) / (c0**2 * m00(W))
#        if mode in slow_surf_mode_options + slow_body_1_mode_options + slow_body_2_mode_options:
#            rho_hatfunction[i] = -rho_hatfunction[i]
    truth2 = np.array(x < -K*np.ones(len(x)))
    indices2 = np.where(truth2 == True)
    for i in indices2:
        rho_hatfunction[i] = constA(mode, W, K, R1)*(sc.sinh(m1(W, R1)*x[i]) +
                             sc.cosh(m1(W, R1)*x[i])) * lamb1(W, R1) / c1(R1)**2
    truth3 = np.array(x > K*np.ones(len(x)))
    indices3 = np.where(truth3 == True)
    for i in indices3:
        rho_hatfunction[i] = constD(mode, W, K, R1)*(sc.sinh(m2(W)*x[i]) -
                             sc.cosh(m2(W)*x[i])) * lamb2(W) / c2**2
    return rho_hatfunction
Example #23
0
 def f(self,xarr,t):
     temp = 0.0
 
     for i in range(2):
         temp+=pl.sin(self.k*xarr[2]-i*pl.pi)*pl.cos(self.w*t-i*pl.pi)/(pl.cosh(self.k*xarr[3])-pl.cos(self.k*xarr[2]-i*pl.pi)) 
     temp = temp*self.coef
     temp -= self.drg*xarr[0]
     x0dot = temp
     x1dot = 0.0
     x2dot = xarr[0]
     x3dot = 0.0
     return [x0dot,x1dot,x2dot,x3dot]
Example #24
0
def bzhat(mode, x, z, t, W, K, R1):
    if 'alfven' in mode:
        bzhat_function = np.zeros(len(x), dtype=complex)
    else:
        truth = np.array((x <= (K + xix_boundary(mode, z, t, W, K, R1, boundary='r'))*np.ones(len(x))) &
                         (x >= (-K + xix_boundary(mode, z, t, W, K, R1, boundary='l'))*np.ones(len(x))))
        indices = np.where(truth == True)
        bzhat_function = np.zeros(len(x), dtype=complex)
        for i in indices:
            bzhat_function[i] = (-1j*B0/W)*m0(W)*(constB(mode, W, K, R1)*sc.sinh(m0(W)*x[i]) +
                                       constC(mode, W, K, R1)*sc.cosh(m0(W)*x[i]))
    return bzhat_function
Example #25
0
def vzhat(mode, x, W, K, R1):
    if 'alfven' in mode:
        vzhat_function = np.zeros_like(x)
    else:
        if type(x) == float or type(x) == np.float64:
            if np.abs(x) <= K:
                vzhat_function = (1j * c0**2 / (c0**2 - W**2)) * m0(W)*(constB(mode, W, K, R1)*sc.sinh(m0(W)*x) +
                                           constC(mode, W, K, R1)*sc.cosh(m0(W)*x))
            elif x < -K:
                vzhat_function = (1j * c1(R1)**2 / (c1(R1)**2 - W**2)) * m1(W, R1)*constA(mode, W, K, R1)*(sc.sinh(m1(W, R1)*x) + 
                                                                     sc.cosh(m1(W, R1)*x))
            elif x > K:
                vzhat_function = (1j * c2**2 / (c2**2 - W**2)) * m2(W)*constD(mode, W, K, R1)*(sc.sinh(m2(W)*x) -
                                                                 sc.cosh(m2(W)*x))
        else:
            truth = np.array(np.abs(x) <= K*np.ones(len(x)))
            indices = np.where(truth == True)
            vzhat_function = np.zeros(len(x), dtype=complex)
            for i in indices:
                vzhat_function[i] = (1j * c0**2 / (c0**2 - W**2)) * m0(W)*(constB(mode, W, K, R1)*sc.sinh(m0(W)*x[i]) +
                                               constC(mode, W, K, R1)*sc.cosh(m0(W)*x[i]))
            truth2 = np.array(x < -K*np.ones(len(x)))
            indices2 = np.where(truth2 == True)
            for i in indices2:
                vzhat_function[i] = (1j * c1(R1)**2 / (c1(R1)**2 - W**2)) * m1(W, R1)*constA(mode, W, K, R1)*(sc.sinh(m1(W, R1)*x[i]) + 
                                                                         sc.cosh(m1(W, R1)*x[i]))
            truth3 = np.array(x > K*np.ones(len(x)))
            indices3 = np.where(truth3 == True)
            for i in indices3:
                vzhat_function[i] = (1j * c2**2 / (c2**2 - W**2)) * m2(W)*constD(mode, W, K, R1)*(sc.sinh(m2(W)*x[i]) -
                                                                     sc.cosh(m2(W)*x[i]))
    return vzhat_function
Example #26
0
def make_phi_hyper(n):
    """make phi n th expression
    n must be n<=4

    :param n:
    :return: phi
    """
    x = symbols('x')
    kl = make_kl(n + 1)
    k = kl / l
    phi = sym.sinh(k * x) + sym.sin(k * x) + \
          (sp.sin(kl) - sp.sinh(kl)) / (sp.cosh(kl) - sp.cos(kl)) * (sym.cosh(k * x) + sym.cos(k * x))
    return phi
Example #27
0
    def f(self,x,t):
        # for now masses just = 1.0
        # the 4.0 only works for 2D
        N = len(x)/4
        xdot = pl.array([])
        # modulus the y component to keep periodicity right.
        x[3*N:4*N]= x[3*N:4*N]%self.yd
        # x too
        if self.x_periodic:
            x[2*N:3*N]= x[2*N:3*N]%self.xd
        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive x interparticle force of j on i
                temp += self.qq*(x[2*N+i]-x[2*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
                # if periodic in x we are going to need to include all the wrap around forces
                if self.x_periodic:
                    #repulsive y interparticle force of j on i
                    temp += self.qq*(x[2*N+i]-x[2*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
                    for gama in range(self.order):
                        temp += -self.qq*(gama*self.xd-(x[2*N+i]-x[2*N+j]))/(pl.sqrt((gama*self.xd-(x[2*N+i]-x[2*N+j]))**2+(x[3*N+i]-x[3*N+j])**2)**3)
                        temp += self.qq* (gama*self.xd+(x[2*N+i]-x[2*N+j]))/(pl.sqrt((gama*self.xd+(x[2*N+i]-x[2*N+j]))**2+(x[3*N+i]-x[3*N+j])**2)**3)
            # EC x force on particle i
            # surface set to 1.0
            for a in range(2):
                temp+=self.As[i]*pl.sin(x[2*N+i]-a*pl.pi)*pl.cos(t-a*pl.pi)/(pl.cosh(1.0)-pl.cos(x[2*N+i]-a*pl.pi)) 
            temp -= self.beta*x[i]
            xdot = pl.append(xdot,temp)
        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive y interparticle force of j on i
                temp += self.qq*(x[3*N+i]-x[3*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
                # force from same particle but in other direction becasue of periodic boundar
                # conditions
                for gama in range(self.order):
                    temp += -self.qq*(gama*self.yd-(x[3*N+i]-x[3*N+j]))/(pl.sqrt((gama*self.yd-(x[3*N+i]-x[3*N+j]))**2+(x[2*N+i]-x[2*N+j])**2)**3)
                    temp += self.qq* (gama*self.yd+(x[3*N+i]-x[3*N+j]))/(pl.sqrt((gama*self.yd+(x[3*N+i]-x[3*N+j]))**2+(x[2*N+i]-x[2*N+j])**2)**3)
            temp -= self.beta*x[N+i]
            xdot = pl.append(xdot,temp)
        for i in range(N):
            xdot = pl.append(xdot,x[i])
        for i in range(N):
            xdot = pl.append(xdot,x[N+i])

    
        return xdot
Example #28
0
    def f(self,x,t):
    
        # the 4.0 only works for 2D
        N = len(x)/4
        xdot = pl.array([])

        print('x is: '+str(x))
    
        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive x interparticle force of j on i
                temp += self.qq*(x[2*N+i]-x[2*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
            # EC x force on particle i
            temp += self.A*(pl.cos(t))*(-2*(pl.cosh(self.d-x[3*N+i]) + pl.cosh(x[3*N+i]))*(pl.cos(x[2*N+i])**2 - pl.cosh(self.d-x[3*N+i])*pl.cosh(x[3*N+i]))*pl.sin(x[2*N+i]))/((pl.cos(x[2*N+i]) - pl.cosh(self.d-x[3*N+i]))*(pl.cos(x[2*N+i]) + pl.cosh(self.d - x[3*N+i]))*(pl.cos(x[2*N+i]) - pl.cosh(x[3*N+i]))*(pl.cos(x[2*N+i]) + pl.cosh(x[3*N+i]))) -self.beta*x[i]
            xdot = pl.append(xdot,temp)
        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive y interparticle force of j on i
                temp += self.qq*(x[3*N+i]-x[3*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
            # EC y force on particle i
            temp += self.A*(pl.cos(t))*(2*pl.cos(x[2*N+i])*(pl.sinh(self.d - x[3*N+i]) - pl.sinh(x[3*N+i]))*(-pl.sin(x[2*N+i])**2 + pl.sinh(self.d - x[3*N+i])*pl.sinh(x[3*N+i])))/((pl.cos(x[2*N+i]) - pl.cosh(self.d - x[3*N+i]))*(pl.cos(x[2*N+i]) + pl.cosh(self.d - x[3*N+i]))*(pl.cos(x[2*N+i]) - pl.cosh(x[3*N+i]))*(pl.cos(x[2*N+i]) + pl.cosh(x[3*N+i])))-self.beta*x[N+i]
            # quadropole restoring force to center of electric curtains
            temp += -self.quadA*(pl.cos(50.0*t)+1.0)*(x[3*N+i]-self.d/2.0)
            xdot = pl.append(xdot,temp)
        for i in range(N):
            xdot = pl.append(xdot,x[i]) 
        for i in range(N):
            xdot = pl.append(xdot,x[N+i])
    
        print('len xdot is: '+str(len(xdot)))
        print('xdot is: '+str(xdot))
        return xdot
Example #29
0
def make_kl(n):
    """calculate coshx*cosx=1 (radian)
    using periodicity of cosx

    :param n:nth answer
    :return:
    """
    product = [
        abs(sp.cosh(x) * sp.cos(x) - 1)
        for x in np.arange(n * np.pi, (n + 1 / 2) * np.pi, 0.001)
    ]
    index = product.index(min(product))
    kl = n * np.pi + 0.001 * index
    return kl
Example #30
0
def rho_pert(mode, x, z, t, W, K, R1):
    rho_hat_vals = np.zeros((len(x), len(z)), dtype=complex)
    rho_vals = np.zeros((len(x), len(z)), dtype=complex)
    for i in range(len(x)):
        for j in range(len(z)):
            def func(r):
                return [r[0] - x[i] + xix(mode, r[0], r[1], t, W, K, R1), 
                        r[1] - z[j] + xiz(mode, r[0], r[1], t, W, K, R1)]
            sol = np.real(fsolve(func, [x[i],z[j]], xtol=1e-03))
            if abs(sol[0]) <= K:
                rho_hat_vals[i,j] = m0(W)*(constB(mode, W, K, R1)*sc.sinh(m0(W)*sol[0]) +
                                constC(mode, W, K, R1)*sc.cosh(m0(W)*sol[0])) * lamb00(W) / (c0**2 * m00(W))
#                if mode in slow_surf_mode_options + slow_body_1_mode_options + slow_body_2_mode_options:
#                    rho_hat_vals[i,j] = -rho_hat_vals[i,j]
            elif sol[0] < -K:
                rho_hat_vals[i,j] = constA(mode, W, K, R1)*(sc.sinh(m1(W, R1)*sol[0]) +
                                sc.cosh(m1(W, R1)*sol[0])) * lamb1(W, R1) / c1(R1)**2
            elif sol[0] > K:
                rho_hat_vals[i,j] = constD(mode, W, K, R1)*(sc.sinh(m2(W)*sol[0]) -
                                     sc.cosh(m2(W)*sol[0])) * lamb2(W) / c2**2
            
            rho_vals[i,j] = rho_hat_vals[i,j] * np.exp(1j*(z[j]-t))
    return rho_vals
Example #31
0
def test(h = 5.0E-6):
    x0 = 0.0
    x1 = 1.0
    mu = 2.0
    s0 = array( [ 1.0 / mu, 0.0 ] )
    p = s0
    x = x0
    def cat( p ) :
        return array( [ p[1], mu * sqrt( 1.0 + p[1] * p[1] ) ] )
    while x + h < x1 :
        p = runge_kutta41( cat, p, h )
        x += h
    p = runge_kutta41( cat, p, x1 - x )
    x = x1
    expected = array( [ cosh( mu * x1 ) / mu, sinh( mu * x1 ) ] )
    error = p - expected
Example #32
0
def breather(x, t, v, w, x0, xi=-pi / 2):
    xi += pi / 2  # to keep with Fig.17 of "Breaking integrability at the boundary"

    W = sqrt(1 - w**2)
    g = 1 / sqrt(1 - v**2)
    Sin = sin(w * g * (t - v * (x - x0)) + xi)
    Cosh = cosh(W * g * (x - x0 - v * t))

    u = 4 * arctan2(W * Sin / w, Cosh)

    Cos = cos(w * g * (t - v * (x - x0)) + xi)
    Tanh = tanh(W * g * (x - x0 - v * t))
    N = v * W**2 * Sin * Tanh + w * W * Cos
    D = (W * Sin / Cosh)**2 + w**2

    ut = 4 * w * g / Cosh * N / D
    return {'u': u, 'ut': ut}
Example #33
0
 def K(self, Q, P, angles, quadratures):
     no_angles, no_pulses = quadratures.shape
     L = no_angles*no_pulses
     h = calc_h(L, self.beta, self.eta)
     y = sqrt(self.gamma)/h
     n = arange(1, self.order+1, dtype=float32)
     n2 = n**2
     pre_s1 = exp(-n2/4.)
     pre_s2 = pre_s1*cosh(n*y)
     pre_s3 = pre_s1*n*sinh(n*y)
     phix = scipy.vstack([scipy.tile(angles, (no_pulses, 1)).T.ravel(), quadratures.ravel()]).T
     QP = scipy.vstack([Q, P]).T
     Kp = partial(K, self.eta, self.gamma, h, y,
                  n2, pre_s1, pre_s2, pre_s3, QP)
     W = scipy.zeros_like(Q, dtype=float32)
     for Wp in self.pool.imap(Kp, scipy.array_split(phix, 2*self.no_procs, axis=0), chunksize=1):
         W += scipy.sum(Wp, axis=0)
     return W/L
Example #34
0
 def __init__(self, eta, beta, L, angles, no_pulses, order=5):
     self.order = order
     self.angles = angles
     self.eta = eta
     self.gamma = gamma(eta)
     self.beta = beta
     self.L = L
     self.h = calc_h(L, beta, eta)
     self.rsq4pi = 1. / sqrt(4. * pi)
     self.sqeta = sqrt(self.eta)
     self.four_pi_gamma = 4. * pi * self.gamma
     self.y = sqrt(self.gamma) / self.h
     n = scipy.arange(1, order + 1, dtype=scipy.float32)
     self.n2 = n**2
     self.pre_s1 = exp(-self.n2 / 4.)
     self.pre_s2 = self.pre_s1 * cosh(n * self.y)
     self.pre_s3 = self.pre_s1 * n * sinh(n * self.y)
     self.cos_phi = cos(angles)
     self.sin_phi = sin(angles)
Example #35
0
def K(eta, h, Q, P, phix, order=5):
    g = gamma(eta)
    y = sqrt(g)/h
    phi = phix[:,0]
    X = phix[:,1]/sqrt(eta)
    Z = (outer(cos(phi), Q) + outer(sin(phi), P) - X[:,None])/h
    Zy = Z/y
    Zy2 = Zy**2
    n = arange(1, order+1)
    n2 = n**2
    f_denom = 1./(n2 + Zy2[:,:,None])
    v = Zy*sin(Z)*dot(f_denom, exp(-n2/4.)*n*sinh(n*y))
    cosZ = cos(Z)
    v += Zy2*(dot(f_denom, exp(-n2/4.))
              - cosZ*dot(f_denom, exp(-n2/4.)*cosh(n*y)))
    del f_denom
    v /= sqrt(pi)
    v += cosZ*(exp(y**2)-1./(2.*sqrt(pi)))+(1./(2.*sqrt(pi))-1.)
    v /= 4.*pi*g
    return v
def sommerfeldIntegral(funct,x,a,bs=1.0,Ns=10,Nmax=1e4,tol=1e-6,maxLoops=100,additParams=()):
    
    '''
        Same as sommerfeldIntegralM but does not handle array inputs (x must be a scalar)
    '''
    
    logging.getLogger(__name__)
    
    N=Ns
    b=bs
    
    Sp = 1e10
    while 1:
                
        h = 1.0/N*scipy.log(1.05*scipy.sqrt(2.0)*N)    
        n = scipy.arange(-N,N+1)
        
        An = scipy.cosh(n*h)*scipy.exp(-scipy.power(scipy.sinh(n*h),2.0))
        inval = 0.5*(b+a)+0.5*(b-a)*scipy.special.erf(scipy.sinh(n*h))
        
        f=funct(inval,additParams)*scipy.exp(-1.0j*x*inval)

        S = h*(b-a)/scipy.sqrt(pi)*scipy.sum(An*f)

        ds = scipy.absolute(S-Sp)/scipy.absolute(Sp)
                
        if ds<tol:
            flag=1
            break

        # abort if N is getting too large
        if N>Nmax or loop>maxLoops:
            logger.error('Max N or Max loops reached; aborting')
            flag = -1
            break    
            
        Sp = S*1.0
        N = N*2
        b = b*1.5

    return S, flag
Example #37
0
File: sech.py Project: daibo/pyofss
    def generate(self, t):
        """
        :param Dvector t: Temporal domain array
        :return: Array of complex values. *Unit:* :math:`\sqrt{W}`
        :rtype: Cvector

        Generate an array of complex values representing a Sech pulse.
        """
        if len(t) < 8:
            raise OutOfRangeError("Require temporal array with at least 8 values")

        # Assume t[0] = t_0 and t[-1] = t_0 + t_range - dt,
        # with dt = t[1] - t[0]
        t_range = t[-1] - t[0] + (t[1] - t[0])
        t_normalised = (t - self.position * t_range) / self.width
        time = t_normalised * t_normalised

        phase = self.initial_phase
        phase -= 2.0 * pi * self.offset_nu * t + 0.5 * self.C * time

        return sqrt(self.peak_power) * exp(1j * phase) / cosh(t_normalised)
Example #38
0
def tanh_warp(x, n, l1, l2, lw, x0):
    r"""Implements a tanh warping function and its derivative.

    .. math::

        l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}

    Parameters
    ----------
    x : float or array of float
        Locations to evaluate the function at.
    n : int
        Derivative order to take. Used for ALL of the points.
    l1 : positive float
        Left saturation value.
    l2 : positive float
        Right saturation value.
    lw : positive float
        Transition width.
    x0 : float
        Transition location.

    Returns
    -------
    l : float or array
        Warped length scale at the given locations.

    Raises
    ------
    NotImplementedError
        If `n` > 1.
    """
    if n == 0:
        return (l1 + l2) / 2.0 - (l1 - l2) / 2.0 * scipy.tanh((x - x0) / lw)
    elif n == 1:
        return -(l1 - l2) / (2.0 * lw) * (scipy.cosh((x - x0) / lw))**(-2.0)
    else:
        raise NotImplementedError(
            "Only derivatives up to order 1 are supported!"
        )
Example #39
0
def tanh_warp(x, n, l1, l2, lw, x0):
    r"""Implements a tanh warping function and its derivative.
    
    .. math::
    
        l = \frac{l_1 + l_2}{2} - \frac{l_1 - l_2}{2}\tanh\frac{x-x_0}{l_w}
    
    Parameters
    ----------
    x : float or array of float
        Locations to evaluate the function at.
    n : int
        Derivative order to take. Used for ALL of the points.
    l1 : positive float
        Left saturation value.
    l2 : positive float
        Right saturation value.
    lw : positive float
        Transition width.
    x0 : float
        Transition location.
    
    Returns
    -------
    l : float or array
        Warped length scale at the given locations.
    
    Raises
    ------
    NotImplementedError
        If `n` > 1.
    """
    if n == 0:
        return (l1 + l2) / 2.0 - (l1 - l2) / 2.0 * scipy.tanh((x - x0) / lw)
    elif n == 1:
        return -(l1 - l2) / (2.0 * lw) * (scipy.cosh((x - x0) / lw))**(-2.0)
    else:
        raise NotImplementedError(
            "Only derivatives up to order 1 are supported!")
Example #40
0
    def generate(self, t):
        """
        :param Dvector t: Temporal domain array
        :return: Array of complex values. *Unit:* :math:`\sqrt{W}`
        :rtype: Cvector

        Generate an array of complex values representing a Sech pulse.
        """
        if len(t) < 8:
            raise OutOfRangeError(
                "Require temporal array with at least 8 values")

        # Assume t[0] = t_0 and t[-1] = t_0 + t_range - dt,
        # with dt = t[1] - t[0]
        t_range = t[-1] - t[0] + (t[1] - t[0])
        t_normalised = (t - self.position * t_range) / self.width
        time = t_normalised * t_normalised

        phase = self.initial_phase
        phase -= 2.0 * pi * self.offset_nu * t + 0.5 * self.C * time

        return sqrt(self.peak_power) * exp(1j * phase) / cosh(t_normalised)
Example #41
0
File: sech.py Project: daibo/pyofss
    def __call__(self, domain, field):
        """
        :param object domain: A domain
        :param object field: Current field
        :return: Field after modification by Sech
        :rtype: Object
        """
        self.field = field

        t_normalised = (domain.t - self.position * domain.window_t) / self.width
        time = t_normalised * t_normalised

        phase = self.initial_phase
        phase -= 2.0 * pi * self.offset_nu * domain.t + 0.5 * self.C * time

        magnitude = sqrt(self.peak_power) / cosh(t_normalised)

        if domain.channels > 1:
            self.field[self.channel] += magnitude * exp(1j * phase)
        else:
            self.field += magnitude * exp(1j * phase)

        return self.field
Example #42
0
    def __call__(self, domain, field):
        """
        :param object domain: A domain
        :param object field: Current field
        :return: Field after modification by Sech
        :rtype: Object
        """
        self.field = field

        t_normalised = \
            (domain.t - self.position * domain.window_t) / self.width
        time = t_normalised * t_normalised

        phase = self.initial_phase
        phase -= 2.0 * pi * self.offset_nu * domain.t + 0.5 * self.C * time

        magnitude = sqrt(self.peak_power) / cosh(t_normalised)

        if domain.channels > 1:
            self.field[self.channel] += magnitude * exp(1j * phase)
        else:
            self.field += magnitude * exp(1j * phase)

        return self.field
Example #43
0
 def __init__(self, eta, beta, L, no_angles, no_pulses, order=5):
     self.mod_K = SourceModule(
         RADON_KERNEL.format(order, no_angles, no_pulses))
     self.K_gpu = self.mod_K.get_function("K_l")
     self.mod_reduction = SourceModule(REDUCTION_KERNEL)
     self.reduction_gpu = self.mod_reduction.get_function("reduction")
     self.eta = eta
     self.gamma = gamma(eta)
     self.beta = beta
     self.L = L
     self.h = calc_h(L, beta, eta)
     drv.memcpy_htod(
         self.mod_K.get_global("rsq4pi")[0],
         scipy.array([1. / sqrt(4. * pi)], dtype=scipy.float32))
     drv.memcpy_htod(
         self.mod_K.get_global("sqeta")[0],
         scipy.array([sqrt(self.eta)], dtype=scipy.float32))
     drv.memcpy_htod(
         self.mod_K.get_global("h")[0],
         scipy.array([self.h], dtype=scipy.float32))
     drv.memcpy_htod(
         self.mod_K.get_global("four_pi_gamma")[0],
         scipy.array([4. * pi * self.gamma], dtype=scipy.float32))
     y = sqrt(self.gamma) / self.h
     drv.memcpy_htod(
         self.mod_K.get_global("y")[0], scipy.array([y],
                                                    dtype=scipy.float32))
     n = scipy.arange(1, order + 1, dtype=scipy.float32)
     n2 = n**2
     ex = exp(-n2 / 4.)
     pre_s2 = ex * cosh(n * y)
     pre_s3 = ex * n * sinh(n * y)
     drv.memcpy_htod(self.mod_K.get_global("n2")[0], n2)
     drv.memcpy_htod(self.mod_K.get_global("pre_s1")[0], ex)
     drv.memcpy_htod(self.mod_K.get_global("pre_s2")[0], pre_s2)
     drv.memcpy_htod(self.mod_K.get_global("pre_s3")[0], pre_s3)
Example #44
0
 def CpIG(self, T):
     [C1, C2, C3, C4, C5] = self.constCp
     cp  = C1 
     cp += C2*((C3/T)/sc.sinh(C3/T))**2
     cp += C4*((C5/T)/sc.cosh(C5/T))**2
     return cp
Example #45
0
def new_sym_bode0(s,ucv):
	kbase=ucv[0]
	cbase=ucv[1]
	kj1=ucv[2]
	cj1=ucv[3]
	Kact=ucv[4]
	tauact=ucv[5]
	kj2=ucv[6]
	cj2=ucv[7]
	gainbode0=ucv[8]
	mubeam=5.7281
	EIbeam=339134.5276
	Lbeam=4.6482
	rl0=0.0902
	Ll0=0.3302
	ml0=16.032
	Il0=0.19
	rl1=0.06145
	Ll1=0.1969
	ml1=5.0264
	Il1=0.027
	rl2=0.1077
	Ll2=0.4001
	ml2=5.5799
	Il2=0.0728
	abeam=Lbeam**2/EIbeam
	betabeam=(-1*s**2*Lbeam**4*mubeam/EIbeam)**(0.25)
	c1beam=0.5*cos(betabeam)+0.5*cosh(betabeam)
	c2beam=-sin(betabeam)+sinh(betabeam)
	c3beam=cos(betabeam)-cosh(betabeam)
	c4beam=sin(betabeam)+sinh(betabeam)
	a_1 = s**2
	a_2 = betabeam**2
	a_3 = 1/a_2
	a_4 = -0.5*abeam*a_3*c3beam
	a_5 = 1/betabeam
	a_6 = 1/(cbase*s+kbase)
	a_7 = 0.5*a_5*c4beam*Lbeam*a_6
	a_8 = a_7+a_4
	a_9 = 1/s
	a_10 = Ll2-rl2
	a_11 = Il2*a_1-ml2*a_10*rl2*a_1
	a_12 = 1/betabeam**3
	a_13 = -0.5*abeam*a_12*c2beam*Lbeam*ml0*a_1
	a_14 = -0.5*abeam*a_12*c2beam*Lbeam
	a_15 = 0.5*abeam*a_3*c3beam*Ll0
	a_16 = a_15+a_14
	a_17 = a_16*ml1*a_1
	a_18 = 0.5*abeam*a_3*c3beam*ml0*rl0*a_1
	a_19 = 0.5*abeam*a_3*c3beam
	a_20 = 1/(cj1*s+kj1)
	a_21 = -0.5*a_5*c4beam*Lbeam
	a_22 = -c1beam*Ll0
	a_23 = Ll0-rl0
	a_24 = 0.5*abeam*a_12*c2beam*Lbeam*ml0*a_23*a_1
	a_25 = Il0*a_1-ml0*a_23*rl0*a_1
	a_26 = 0.5*abeam*a_3*c3beam*a_25
	a_27 = a_20*(a_26+a_24+a_22+a_21)
	a_28 = a_27+a_19
	a_29 = ml1*rl1*a_1*a_28
	a_30 = Ll1*a_28+a_15+a_14
	a_31 = 1/(cj2*s+kj2)
	a_32 = Ll1-rl1
	a_33 = -a_16*ml1*a_32*a_1
	a_34 = a_18+a_13+c1beam
	a_35 = -Ll1*a_34
	a_36 = Il1*a_1-ml1*a_32*rl1*a_1
	a_37 = a_36*a_28
	a_38 = a_31*(a_37+a_26+a_35+a_33+a_24+a_22+a_21)+a_27+a_19
	a_39 = ml2*rl2*a_1*a_38+ml2*a_1*a_30+a_29+a_18+a_17+a_13+c1beam
	a_40 = a_29+a_18+a_17+a_13+c1beam
	a_41 = 1/Lbeam
	a_42 = 1/abeam
	a_43 = 0.5*abeam*a_5*c4beam*a_41
	a_44 = c1beam*a_6
	a_45 = a_44+a_43
	a_46 = Ll0*a_45
	a_47 = a_46+a_7+a_4
	a_48 = 0.5*a_42*betabeam*c2beam*Lbeam*a_6
	a_49 = a_25*a_45
	a_50 = -0.5*betabeam*c2beam*a_41
	a_51 = 0.5*a_42*a_2*c3beam*a_6
	a_52 = -Ll0*(a_51+a_50)
	a_53 = -ml0*a_23*a_1*a_8
	a_54 = a_20*(a_53+a_52+a_49+a_48+c1beam)
	a_55 = a_54+a_44+a_43
	a_56 = Ll1*a_55+a_46+a_7+a_4
	a_57 = -ml1*a_32*a_1*a_47
	a_58 = ml0*rl0*a_1*a_45
	a_59 = ml0*a_1*a_8
	a_60 = -Ll1*(a_59+a_58+a_51+a_50)
	a_61 = a_36*a_55
	a_62 = a_31*(a_61+a_60+a_57+a_53+a_52+a_49+a_48+c1beam)+a_54+a_44+ \
		a_43
	a_63 = -ml2*rl2*a_1*a_62-ml2*a_1*a_56-ml1*rl1*a_1*a_55-ml1*a_1*a_47 \
		-ml0*a_1*a_8-ml0*rl0*a_1*a_45-0.5*a_42*a_2*c3beam*a_6+0.5*betabeam \
		*c2beam*a_41
	a_64 = a_11*a_62-Ll2*(ml1*rl1*a_1*a_55+ml1*a_1*a_47+a_59+a_58+a_51 \
		+a_50)-ml2*a_10*a_1*a_56+a_61+a_60+a_57+a_53+a_52+a_49+a_48+c1beam
	a_65 = 1/(a_39*a_64+(a_11*a_38-Ll2*a_40-ml2*a_10*a_1*a_30+a_37+a_26 \
		+a_35+a_33+a_24+a_22+a_21)*a_63)
	a_66 = 1/(tauact+s)
	bode = gainbode0*a_1*(a_8*(-Kact*ml2*rl2*s*(-a_11*a_38+Ll2*a_40+ \
		ml2*a_10*a_1*a_30-a_36*a_28-0.5*abeam*a_3*c3beam*a_25+Ll1*a_34+ \
		a_16*ml1*a_32*a_1-0.5*abeam*a_12*c2beam*Lbeam*ml0*a_23*a_1+c1beam \
		*Ll0+0.5*a_5*c4beam*Lbeam)*a_65*tauact*a_66-Kact*a_9*a_11*a_39 \
		*a_65*tauact*a_66)-0.5*abeam*a_12*c2beam*Lbeam*(-Kact*ml2*rl2* \
		s*a_64*a_65*tauact*a_66-Kact*a_9*a_11*a_63*a_65*tauact*a_66))
	return bode
Example #46
0
def mtanh_profile(X, n, x0, delta, alpha, h, b):
    """Profile used with the mtanh function to fit profiles, suitable for use with :py:class:`MeanFunction`.
    
    Only supports univariate data!
    
    Parameters
    ----------
    X : array, (`M`, 1)
        The points to evaluate at.
    n : array, (1,)
        The order of derivative to compute. Only up to first derivatives are
        supported.
    x0 : float
        Pedestal center
    delta : float
        Pedestal halfwidth
    alpha : float
        Core slope
    h : float
        Pedestal height
    b : float
        Pedestal foot
    """
    X = X[:, 0]
    z = (x0 - X) / delta
    if n[0] == 0:
        return (h + b) / 2.0 + (h - b) * mtanh(alpha, z) / 2.0
    elif n[0] == 1:
        return -(h - b) / (2.0 * delta) * (1 + alpha / 4.0 * (1 + 2 * z + scipy.exp(2 * z))) / (scipy.cosh(z))**2
    else:
        raise NotImplementedError("Derivatives of order greater than 1 are not supported!")
Example #47
0
evect = rand(3)
evect += 0.5 - 1
evect = evect * 10
ivect = evect + myvect

tmmevect = array(map(mysys.FindEig, ivect * 1.0j))
for q, cureig in enumerate(tmmevect):
    print("TMM eig %d= " % (q + 1) + str(cureig[1]))
errors = myvect - tmmevect[:, 1]
perrors = abs(errors / myvect * 100.0)

print("max. percent error (Analytic-TMM)=" + str(max(perrors)))

beta = (myvect ** 2 * mu / EI) ** 0.25
beta2 = (tmmevect[:, 1] ** 2 * mu / EI) ** 0.25
test = cos(beta * L) * cosh(beta * L) + 1
test2 = cos(beta2 * L) * cosh(beta2 * L) + 1
xvect = arange(0, 1.01, 0.01)
xvect = xvect * L
for n, cureig, curbeta in zip(range(len(tmmevect)), tmmevect, beta):
    curAY = (sin(curbeta * L) - sinh(curbeta * L)) * (sin(curbeta * xvect) - sinh(curbeta * xvect)) + (
        cos(curbeta * L) + cosh(curbeta * L)
    ) * (cos(curbeta * xvect) - cosh(curbeta * xvect))
    mind = argmax(abs(curAY))
    mymax = curAY[mind]
    curAY = curAY * 0.2 / mymax
    disps, angles, modedict = mysys.FindModeShape(cureig)
    disps = real(disps)[:, 0]
    mind2 = argmax(abs(disps))
    mymax2 = disps[mind2]
    disps = disps * 0.2 / mymax2
Example #48
0
evect=rand(3)
evect+=0.5-1
evect=evect*10
ivect=evect+myvect

tmmevect=array(map(mysys.FindEig,ivect*1.0j))
for q,cureig in enumerate(tmmevect):
    print('TMM eig %d= '%(q+1)+str(cureig[1])) 
errors=myvect-tmmevect[:,1]
perrors=abs(errors/myvect*100.)

print('max. percent error (Analytic-TMM)='+str(max(perrors)))

beta=(myvect**2*mu/EI)**0.25
beta2=(tmmevect[:,1]**2*mu/EI)**0.25
test=cos(beta*L)*cosh(beta*L)+1
test2=cos(beta2*L)*cosh(beta2*L)+1
xvect=arange(0,1.01,0.01)
xvect=xvect*L
for n,cureig,curbeta in zip(range(len(tmmevect)),tmmevect,beta):
    curAY=(sin(curbeta*L)-sinh(curbeta*L))*(sin(curbeta*xvect)-sinh(curbeta*xvect))+(cos(curbeta*L)+cosh(curbeta*L))*(cos(curbeta*xvect)-cosh(curbeta*xvect))
    mind=argmax(abs(curAY))
    mymax=curAY[mind]
    curAY=curAY*0.2/mymax
    disps,angles,modedict=mysys.FindModeShape(cureig)
    disps=real(disps)[:,0]
    mind2=argmax(abs(disps))
    mymax2=disps[mind2]
    disps=disps*0.2/mymax2
    mymesh=mysys.CreateMesh()
    myx=mymesh[:,0]
Example #49
0
        # Using own data file to extract the input state.
        input = workspace["states"][-1, :]
        background = workspace["background"]
    delta = workspace["delta"]
    pump = workspace["pump"]
    loss = workspace["loss"]


filename = (
    filename +
    "delta=%.2f_pump=%.2E_loss=%.2E_mint=%.2f_maxt_%.2f_nt=%d_dt=%.2E.npz" %
    (delta, pump, loss, args.mint, args.maxt, args.nt, args.dt))


absorber = (1000 *
            (1/s.cosh((x - x.min()) / 8.0) +
             1/s.cosh((x - x.max()) / 8.0)))
absorber[abs(x) < 64] = 0


t = s.linspace(args.mint, args.maxt, args.nt)
states = ccgnlse.integrate(
    t, x, input, args.dt,
    [-delta, 0.0, -1.0],
    1.0,
    potential,
    pump, loss,
    absorber, background)


workspace = {}
def Bodes(s, params):
    GthNum = Gth.Gth.num(s)
    GthDen = Gth.Gth.den(s)
    if type(params) == dict:
        params = SFLR_TMM.SFLR_params(**params)
    EI = params.EI
    L1 = params.L
    L2 = params.L2
    mu = params.mu
    c_beam = params.c_beam
    if c_beam > 0.0:
        EI = EI*(1.0+c_beam*s)
##     beta = pow((-1*s*s*L**4*mu/EI),0.25)
##     d1 = 0.5*(cos(beta)+cosh(beta))
##     d2 = 0.5*(sinh(beta)-sin(beta))
##     d3 = 0.5*(cosh(beta)-cos(beta))
##     d4 = 0.5*(sin(beta)+sinh(beta))
    beta1 = pow((-1*s*s*L1**4*mu/EI),0.25)
    d1_1 = 0.5*(cos(beta1)+cosh(beta1))
    d2_1 = 0.5*(sinh(beta1)-sin(beta1))
    d3_1 = 0.5*(cosh(beta1)-cos(beta1))
    d4_1 = 0.5*(sin(beta1)+sinh(beta1))
    beta2 = pow((-1*s*s*L2**4*mu/EI),0.25)
    d1_2 = 0.5*(cos(beta2)+cosh(beta2))
    d2_2 = 0.5*(sinh(beta2)-sin(beta2))
    d3_2 = 0.5*(cosh(beta2)-cos(beta2))
    d4_2 = 0.5*(sin(beta2)+sinh(beta2))
    a_m = params.a_m
    a_L = params.a_L
    a_I = params.a_I
    a_r = params.a_r
    b_m = params.b_m
    b_L = params.b_L
    b_I = params.b_I
    b_r = params.b_r
    k_spring = params.k_spring
    c_spring = params.c_spring
    k_clamp = params.k_clamp
    c_clamp = params.c_clamp
    K_act = params.K_act
    tau = params.tau
    a_gain = params.a_gain
    p_act1 = params.p_act1
    p_act2 = params.p_act2
    z_act = params.z_act
    H = params.H
    I = 1.0j
    enc_gain = 180.0/pi*1024.0/360.0
    #--------------------------------
    a_1 = s**2
    a_2 = 1/GthDen
    a_3 = sqrt(p_act1**2+4*pi**2)
    a_4 = 1/s
    a_5 = 1/(s+p_act1)
    a_6 = 1/(a_2*GthNum*K_act*a_3*a_4*a_5*H+1.0E+0)
    a_7 = 1.0E+0*a_2*GthNum*K_act*a_3*a_4*a_5*a_6
    a_8 = 1/(c_spring*s+k_spring)
    a_9 = beta1**3
    a_10 = L1**3
    a_11 = 1/a_10
    a_12 = beta1**2
    a_13 = 1/(c_clamp*s+k_clamp)
    a_14 = a_1*b_I-b_m*b_r*a_1*(b_L-b_r)
    a_15 = a_2*GthNum*K_act*a_3*a_4*a_5*a_13*a_14*a_6+a_7
    a_16 = L1**2
    a_17 = 1/a_16
    a_18 = 1/L1
    a_19 = -1.0E+0*beta1*d2_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_14*a_6*a_18 \
        -a_12*d3_1*EI*a_15*a_17-1.0E+0*a_9*d4_1*a_2*GthNum*K_act*a_3* \
        a_4*a_5*b_L*EI*a_6*a_11+1.0E+0*b_m*b_r*d1_1*a_2*GthNum*K_act*a_3 \
        *s*a_5*a_6
    a_20 = 1/beta1
    a_21 = 1/EI
    a_22 = 1/a_12
    a_23 = -1.0E+0*a_22*b_m*b_r*d3_1*a_2*GthNum*K_act*a_3*s*a_5*a_21*a_6 \
        *a_16+1.0E+0*a_20*d4_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_14*a_21 \
        *a_6*L1+1.0E+0*beta1*d2_1*a_2*GthNum*K_act*a_3*a_4*a_5*b_L*a_6* \
        a_18+d1_1*a_15
    a_24 = 1/a_9
    a_25 = -1.0E+0*a_24*b_m*b_r*d2_1*a_2*GthNum*K_act*a_3*s*a_5*a_21*a_6 \
        *a_10+1.0E+0*a_22*d3_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_14*a_21 \
        *a_6*a_16+a_20*d4_1*a_15*L1+1.0E+0*d1_1*a_2*GthNum*K_act*a_3*a_4 \
        *a_5*b_L*a_6
    a_26 = a_m*a_1*a_25+a_m*a_r*a_1*a_23+1.0E+0*a_19
    a_27 = beta2**3
    a_28 = a_L*a_23
    a_29 = 1.0E+0*a_25
    a_30 = a_29+a_28
    a_31 = 1/L2**3
    a_32 = beta2**2
    a_33 = 1/L2**2
    a_34 = a_L-a_r
    a_35 = a_1*a_I-a_m*a_r*a_1*a_34
    a_36 = -a_m*a_1*a_34*a_25+a_35*a_23+1.0E+0*(-1.0E+0*a_20*b_m*b_r*d4_1 \
        *a_2*GthNum*K_act*a_3*s*a_5*a_6*L1+beta1*d2_1*EI*a_15*a_18+1.0E+0 \
        *a_12*d3_1*a_2*GthNum*K_act*a_3*a_4*a_5*b_L*EI*a_6*a_17+1.0E+0 \
        *d1_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_14*a_6)-a_L*a_19
    a_37 = 1/L2
    a_38 = beta2*d2_2*a_36*a_37+1.0E+0*a_32*d3_2*EI*a_23*a_33+a_27*d4_2 \
        *EI*a_30*a_31-d1_2*a_26
    a_39 = 1.0E+0*beta1*d2_1*b_L*a_18+a_12*d3_1*a_13*b_L*EI*a_17+1.0E+0 \
        *d1_1
    a_40 = -1.0E+0*a_22*d3_1*a_21*a_16-1.0E+0*a_20*d4_1*b_L*a_21*L1-d1_1 \
        *a_13*b_L
    a_41 = -1.0E+0*a_24*d2_1*a_21*a_10-1.0E+0*a_22*d3_1*b_L*a_21*a_16- \
        a_20*d4_1*a_13*b_L*L1
    a_42 = -a_m*a_1*a_34*a_41+a_35*a_40+1.0E+0*(-1.0E+0*a_20*d4_1*L1-beta1 \
        *d2_1*a_13*b_L*EI*a_18-1.0E+0*d1_1*b_L)-a_L*a_39
    a_43 = 1.0E+0*a_41+a_L*a_40
    a_44 = 1/beta2
    a_45 = a_m*a_1*a_41+a_m*a_r*a_1*a_40+1.0E+0*a_39
    a_46 = a_8*a_14*a_6+1.0E+0
    a_47 = a_13*a_46+1.0E+0*a_8*a_6
    a_48 = -1.0E+0*beta1*d2_1*a_46*a_18-a_12*d3_1*EI*a_47*a_17-1.0E+0* \
        a_9*d4_1*a_8*b_L*EI*a_6*a_11+1.0E+0*b_m*b_r*d1_1*a_1*a_8*a_6
    a_49 = -1.0E+0*a_22*b_m*b_r*d3_1*a_1*a_8*a_21*a_6*a_16+1.0E+0*a_20 \
        *d4_1*a_21*a_46*L1+1.0E+0*beta1*d2_1*a_8*b_L*a_6*a_18+d1_1*a_47
    a_50 = -1.0E+0*a_24*b_m*b_r*d2_1*a_1*a_8*a_21*a_6*a_10+1.0E+0*a_22 \
        *d3_1*a_21*a_46*a_16+a_20*d4_1*a_47*L1+1.0E+0*d1_1*a_8*b_L*a_6
    a_51 = a_m*a_1*a_50+a_m*a_r*a_1*a_49+1.0E+0*a_48
    a_52 = 1.0E+0*a_50+a_L*a_49
    a_53 = -a_m*a_1*a_34*a_50+a_35*a_49+1.0E+0*(-1.0E+0*a_20*b_m*b_r*d4_1 \
        *a_1*a_8*a_6*L1+beta1*d2_1*EI*a_47*a_18+1.0E+0*a_12*d3_1*a_8 \
        *b_L*EI*a_6*a_17+1.0E+0*d1_1*a_46)-a_L*a_48
    a_54 = beta2*d2_2*a_53*a_37+1.0E+0*a_32*d3_2*EI*a_49*a_33+a_27*d4_2 \
        *EI*a_52*a_31-d1_2*a_51
    a_55 = -beta2*d2_2*a_42*a_37-1.0E+0*a_32*d3_2*EI*a_40*a_33-a_27*d4_2 \
        *EI*a_43*a_31+d1_2*a_45
    a_56 = -a_44*d4_2*a_51*L2+1.0E+0*beta2*d2_2*EI*a_49*a_37+a_32*d3_2 \
        *EI*a_52*a_33+d1_2*a_53
    a_57 = 1/(a_55*a_56+a_54*(-a_44*d4_2*a_45*L2+1.0E+0*beta2*d2_2*EI* \
        a_40*a_37+a_32*d3_2*EI*a_43*a_33+d1_2*a_42))
    a_58 = a_44*d4_2*a_26*L2-1.0E+0*beta2*d2_2*EI*a_23*a_37-a_32*d3_2* \
        EI*a_30*a_33-d1_2*a_36
    a_59 = a_55*a_58*a_57+a_38*(a_44*d4_2*a_45*L2-1.0E+0*beta2*d2_2*EI \
        *a_40*a_37-a_32*d3_2*EI*a_43*a_33-d1_2*a_42)*a_57
    RESULT = a_gain*a_1*(a_43*(a_38*a_56*a_57+a_54*a_58*a_57)+a_52*a_59 \
        +a_29+a_28)/(enc_gain*(1.0E+0*a_8*a_6*a_59+a_7))
    return RESULT
Example #51
0
leg_width(lg,8.)

plt.xlim(0.,3.)
plt.savefig('figs/speeds',bbox_inches='tight',transparent=True)    


#
# vertical structure of most unstable wave
#

z = np.linspace(0.,1.,100)

sigma8 = grate(k,8.)
ikmax = sigma8.argmax()
mu = mu[ikmax]
co = sp.cosh(mu*z)
si = sp.sinh(mu*z)

cr,ci = .5,ci[ikmax]
c2 = cr**2 + ci**2

co = sp.cosh(mu*z)
si = sp.sinh(mu*z)
phi_r = co - (cr/(mu*c2))*si
phi_i = (ci/(mu*c2))*si

phi_abs = np.sqrt( phi_r**2 + phi_i**2 )

phi_phase = np.zeros(z.size)
for i in range(z.size):
    phi_phase[i] = sp.math.atan2( phi_i[i],phi_r[i] )
Example #52
0
def euler_beam_modes(n=10, bctype=2, beamparams=sp.array((7.31e10, 1 / 12 * 0.03 * .015 ** 3, 2747, .015 * 0.03, 0.4)),
                     npoints=2001):
    """
    %VTB6_3 Natural frequencies and mass normalized mode shape for an Euler-
    % Bernoulli beam with a chosen boundary condition.
    % [w,x,U]=VTB6_3(n,bctype,bmpar,npoints) will return the nth natural 
    % frequency (w) and mode shape (U) of an Euler-Bernoulli beam.
    % If n is a vector, return the coresponding mode shapes and natural
    % frequencies.
    % With no output arguments the modes are ploted.
    % If only one mode is requested, and there are no output arguments, the
    % mode shape is animated.
    % The boundary condition is defined as follows:
    %
    % bctype = 1 free-free
    % bctype = 2 clamped-free
    % bctype = 3 clamped-pinned
    % bctype = 4 clamped-sliding
    % bctype = 5 clamped-clamped
    % bctype = 6 pinned-pinned
    %
    % The beam parameters are input through the vector bmpar:
    % bmpar = [E I rho A L];
    % where the variable names are consistent with Section 6.5 of the 
    % text.
    %
    %% Example: 20 cm long aluminum beam with h=1.5 cm, b=3 cm
    %% Animate the 4th mode for free-free boundary conditions
    % E=7.31e10;
    % I=1/12*.03*.015^3;
    % rho=2747;
    % A=.015*.03;
    % L=0.2;
    % vtb6_3(4,1,[E I rho A L]);
    %

    % Copyright Joseph C. Slater, 2007
    % Engineering Vibration Toolbox
    """
    E = beamparams[0]
    I = beamparams[1]
    rho = beamparams[2]
    A = beamparams[3]
    L = beamparams[4]
    if isinstance(n, int):
        ln = n
        n = sp.arange(n) + 1
    else:
        ln = len(n)

    # len=[0:(1/(npoints-1)):1]';  %Normalized length of the beam
    len = sp.linspace(0, 1, npoints)
    x = len * L
    # Determine natural frequencies and mode shapes depending on the
    # boundary condition.
    # Mass simplification. The following was arange_(1,length_(n)).reshape(-1)
    mode_num_range = sp.arange(0, ln)
    Bnl = sp.empty(ln)
    w = sp.empty(ln)
    U = sp.empty([npoints, ln])

    if bctype == 1:
        desc = 'Free-Free '
        Bnllow = sp.array((0, 0, 4.73004074486, 7.8532046241,
                           10.995607838, 14.1371654913, 17.2787596574))
        for i in mode_num_range:
            if n[i] > 7:
                Bnl[i] = (2 * n[i] - 3) * sp.pi / 2
            else:
                Bnl[i] = Bnllow[i]
        for i in mode_num_range:
            if n[i] == 1:
                w[i] = 0
                U[:, i] = 1 + len * 0
            elif n[i] == 2:
                w[i] = 0
                U[:, i] = len - 0.5
            else:
                sig = (sp.cosh(Bnl[i]) - sp.cos(Bnl[i])) / \
                      (sp.sinh(Bnl[i]) - sp.sin(Bnl[i]))
                w[i] = (Bnl[i] ** 2) * sp.sqrt(E * I / (rho * A * L ** 4))
                b = Bnl[i] * len
                U[:, i] = sp.cosh(b) + sp.cos(b) - sig * \
                    (sp.sinh(b) + sp.sin(b))
    elif bctype == 2:
        desc = 'Clamped-Free '
        Bnllow = sp.array((1.88, 4.69, 7.85, 10.99, 14.14))
        for i in mode_num_range:
            if n[i] > 4:
                Bnl[i] = (2 * n[i] - 1) * sp.pi / 2
            else:
                Bnl[i] = Bnllow[i]

        for i in mode_num_range:
            sig = (sp.sinh(Bnl[i]) - sp.sin(Bnl[i])) / \
                  (sp.cosh(Bnl[i]) - sp.cos(Bnl[i]))
            w[i] = (Bnl[i] ** 2) * sp.sqrt(E * I / (rho * A * L ** 4))
            b = Bnl[i] * len
            # plt.plot(x,(sp.cosh(b) - sp.cos(b) - sig * (sp.sinh(b) - sp.sin(b))))
            U[:, i] = sp.cosh(b) - sp.cos(b) - sig * (sp.sinh(b) - sp.sin(b))

    elif bctype == 3:
        desc = 'Clamped-Pinned '
        Bnllow = sp.array((3.93, 7.07, 10.21, 13.35, 16.49))
        for i in mode_num_range:
            if n[i] > 4:
                Bnl[i] = (4 * n[i] + 1) * sp.pi / 4
            else:
                Bnl[i] = Bnllow[i]
        for i in mode_num_range:
            sig = (sp.cosh(Bnl[i]) - sp.cos(Bnl[i])) / \
                  (sp.sinh(Bnl[i]) - sp.sin(Bnl[i]))
            w[i] = (Bnl[i] ** 2) * sp.sqrt(E * I / (rho * A * L ** 4))
            b = Bnl[i] * len
            U[:, i] = sp.cosh(b) - sp.cos(b) - sig * (sp.sinh(b) - sp.sin(b))
    elif bctype == 4:
        desc = 'Clamped-Sliding '
        Bnllow = sp.array((2.37, 5.5, 8.64, 11.78, 14.92))
        for i in mode_num_range:
            if n[i] > 4:
                Bnl[i] = (4 * n[i] - 1) * sp.pi / 4
            else:
                Bnl[i] = Bnllow[i]
        for i in mode_num_range:
            sig = (sp.sinh(Bnl[i]) + sp.sin(Bnl[i])) / \
                  (sp.cosh(Bnl[i]) - sp.cos(Bnl[i]))
            w[i] = (Bnl[i] ** 2) * sp.sqrt(E * I / (rho * A * L ** 4))
            b = Bnl[i] * len
            U[:, i] = sp.cosh(b) - sp.cos(b) - sig * (sp.sinh(b) - sp.sin(b))
    elif bctype == 5:
        desc = 'Clamped-Clamped '
        Bnllow = sp.array((4.73, 7.85, 11, 14.14, 17.28))
        for i in mode_num_range:
            if n[i] > 4:
                Bnl[i] = (2 * n[i] + 1) * sp.pi / 2
            else:
                Bnl[i] = Bnllow[i]
        for i in mode_num_range:
            sig = (sp.cosh(Bnl[i]) - sp.cos(Bnl[i])) / \
                  (sp.sinh(Bnl[i]) - sp.sin(Bnl[i]))
            w[i] = (Bnl[i] ** 2) * sp.sqrt(E * I / (rho * A * L ** 4))
            b = Bnl[i] * len
            U[:, i] = sp.cosh(b) - sp.cos(b) - sig * (sp.sinh(b) - sp.sin(b))
    elif bctype == 6:
        desc = 'Pinned-Pinned '
        for i in mode_num_range:
            Bnl[i] = n[i] * sp.pi
            w[i] = (Bnl[i] ** 2) * sp.sqrt(E * I / (rho * A * L ** 4))
            U[:, i] = sp.sin(Bnl[i] * len)

    # Mass Normalization of mode shapes
    for i in mode_num_range:
        U[:, i] = U[:, i] / sp.sqrt(sp.dot(U[:, i], U[:, i]) * rho * A * L)

    """
    ppause=0
    x=len * L
    if nargout == 0:
        if length_(n) != 1:
            for i in arange_(1,length_(n)).reshape(-1):
                plot_(x,U[:,i])
                axis_([0,L,min_(min_(U)),max_(max_(U))])
                figure_(gcf)
                title_([desc,char('  '),char('Mode '),int2str_(i),char('     Natural Frequency = '),num2str_(w[i]),char(' rad/s')])
                ylabel_(char('Modal Amplitude'))
                xlabel_(char('Length along bar - x'))
                grid_(char('on'))
                disp_(char('Press return to continue'))
                pause
        else:
            nsteps=50
            clf
            step=2 * pi / (nsteps)
            i=arange_(0,(2 * pi - step),step)
            hold_(char('off'))
            handle=uicontrol_(char('style'),char('pushbutton'),char('units'),char('normal'),char('backgroundcolor'),char('red'),char('position'),[0.94,0.94,0.05,0.05],char('String'),char('Stop'),char('callback'),char('global stopstop;stopstop=1;'))
            handle2=uicontrol_(char('style'),char('pushbutton'),char('units'),char('normal'),char('backgroundcolor'),char('yellow'),char('position'),[0.94,0.87,0.05,0.05],char('String'),char('Pause'),char('callback'),char('global ppause;ppause=1;'))
            handle3=uicontrol_(char('style'),char('pushbutton'),char('units'),char('normal'),char('backgroundcolor'),char('green'),char('position'),[0.94,0.8,0.05,0.05],char('String'),char('Resume'),char('callback'),char('global ppause;ppause=0;'))
            stopstop=0
            bb=0
            while stopstop == 0 and bb < 100:

                bb=bb + 1
                for ii in [i].reshape(-1):
                    while ppause == 1:

                        pause_(0.01)
                        if stopstop == 1:
                            delete_(handle)
                            delete_(handle2)
                            delete_(handle3)
                            return w,x,U

                    plot_(x,U[:,1] * sp.cos(ii))
                    axis_([0,L,- max_(abs_(U)),max_(abs_(U))])
                    grid_(char('on'))
                    figure_(gcf)
                    title_([desc,char('  '),char('Mode '),int2str_(n),char('     \\omega_n = '),num2str_(w[1]),char(' rad/s')])
                    ylabel_(char('Modal Amplitude'))
                    xlabel_(char('Length along bar - x'))
                    drawnow

            clear_(char('stopstop'))
            delete_(handle)
            delete_(handle2)
            delete_(handle3)
    """
    return w, x, U
Example #53
0
    def f(self,xarr,t):
        temp1 = 0.0
        temp2 = 0.0

        # RIGHT NOW WE ARE LOOKING AT THE SQUARE WAVE VERSION. TO GO BACK TO NORMAL JUST REPLACE
        # SELF.SQUAREWAVE WITH PL.COS. !!!!!!!!!!!!!!!!!!!!!!!!!
    
        for i in range(2):
            temp1+=pl.sin(self.k*xarr[2]-i*pl.pi)*self.square_wave(self.w*t-i*pl.pi)/(pl.cosh(self.k*(self.surf+abs(xarr[3]-self.surf)))-pl.cos(self.k*xarr[2]-i*pl.pi)) 
        temp1 = temp1*self.coef
        temp1 -= self.drg*xarr[0]
        x0dot = temp1
        for i in range(2):
            temp2+=pl.sign(xarr[3]-self.surf)*pl.sinh(self.k*(self.surf+abs(xarr[3]-self.surf)))*self.square_wave(self.w*t-i*pl.pi)/(pl.cosh(self.k*(self.surf+abs(xarr[3]-self.surf)))-pl.cos(self.k*xarr[2]-i*pl.pi)) 
        temp2 = temp2*self.coef
        temp2 -= self.drg*xarr[1]
        temp2 -= pl.sign(xarr[3]-self.surf)*self.g
        x1dot = temp2
        x2dot = xarr[0]
        x3dot = xarr[1]
        return [x0dot,x1dot,x2dot,x3dot]
def Bodes(s, params):
    mynum = squeeze(Gth.Gth.num)
    myden = squeeze(Gth.Gth.den)
    try:
        GthNum = mynum(s)
        GthDen = myden(s)
    except:
        mynum = poly1d(mynum)
        myden = poly1d(myden)
        GthNum = mynum(s)
        GthDen = myden(s)
        
    if type(params) == dict:
        params = SFLR_TMM.SFLR_params(**params)
    EI = params.EI
    L1 = params.L
    L2 = params.L2
    mu = params.mu
    c_beam = params.c_beam
    if c_beam > 0.0:
        EI = EI*(1.0+c_beam*s)
##     beta = pow((-1*s*s*L**4*mu/EI),0.25)
##     d1 = 0.5*(cos(beta)+cosh(beta))
##     d2 = 0.5*(sinh(beta)-sin(beta))
##     d3 = 0.5*(cosh(beta)-cos(beta))
##     d4 = 0.5*(sin(beta)+sinh(beta))
    beta1 = pow((-1*s*s*L1**4*mu/EI),0.25)
    d1_1 = 0.5*(cos(beta1)+cosh(beta1))
    d2_1 = 0.5*(sinh(beta1)-sin(beta1))
    d3_1 = 0.5*(cosh(beta1)-cos(beta1))
    d4_1 = 0.5*(sin(beta1)+sinh(beta1))
    beta2 = pow((-1*s*s*L2**4*mu/EI),0.25)
    d1_2 = 0.5*(cos(beta2)+cosh(beta2))
    d2_2 = 0.5*(sinh(beta2)-sin(beta2))
    d3_2 = 0.5*(cosh(beta2)-cos(beta2))
    d4_2 = 0.5*(sin(beta2)+sinh(beta2))
    a_m = params.a_m
    a_L = params.a_L
    a_I = params.a_I
    a_r = params.a_r
    b_m = params.b_m
    b_L = params.b_L
    b_I = params.b_I
    b_r = params.b_r
    k_spring = params.k_spring
    c_spring = params.c_spring
    k_clamp = params.k_clamp
    c_clamp = params.c_clamp
    K_act = params.K_act
    tau = params.tau
    a_gain = params.a_gain
    p_act1 = params.p_act1
    p_act2 = params.p_act2
    z_act = params.z_act
    H = params.H
    I = 1.0j
    enc_gain = 180.0/pi*1024.0/360.0
    #--------------------------------
    a_1 = s**2
    a_2 = 1/GthDen
    a_3 = sqrt(p_act1**2+4*pi**2)
    a_4 = 1/s
    a_5 = 1/(s+p_act1)
    a_6 = 1/(a_2*GthNum*K_act*a_3*a_4*a_5*H+1.0E+0)
    a_7 = 1/(c_clamp*s+k_clamp)
    a_8 = a_1*b_I-b_m*b_r*a_1*(b_L-b_r)
    a_9 = a_2*GthNum*K_act*a_3*a_4*a_5*a_7*a_8*a_6+1.0E+0*a_2*GthNum*K_act \
        *a_3*a_4*a_5*a_6
    a_10 = 1/L1
    a_11 = 1/beta1
    a_12 = 1/EI
    a_13 = beta1**2
    a_14 = 1/a_13
    a_15 = L1**2
    a_16 = -1.0E+0*a_14*b_m*b_r*d3_1*a_2*GthNum*K_act*a_3*s*a_5*a_12*a_6 \
        *a_15+1.0E+0*a_11*d4_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_8*a_12* \
        a_6*L1+1.0E+0*beta1*d2_1*a_2*GthNum*K_act*a_3*a_4*a_5*b_L*a_6*a_10 \
        +d1_1*a_9
    a_17 = a_L*a_16
    a_18 = beta1**3
    a_19 = 1/a_18
    a_20 = L1**3
    a_21 = -1.0E+0*a_19*b_m*b_r*d2_1*a_2*GthNum*K_act*a_3*s*a_5*a_12*a_6 \
        *a_20+1.0E+0*a_14*d3_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_8*a_12* \
        a_6*a_15+a_11*d4_1*a_9*L1+1.0E+0*d1_1*a_2*GthNum*K_act*a_3*a_4* \
        a_5*b_L*a_6
    a_22 = 1.0E+0*a_21
    a_23 = 1/(c_spring*s+k_spring)
    a_24 = a_23*a_8*a_6+1.0E+0
    a_25 = a_7*a_24+1.0E+0*a_23*a_6
    a_26 = -1.0E+0*a_14*b_m*b_r*d3_1*a_1*a_23*a_12*a_6*a_15+1.0E+0*a_11 \
        *d4_1*a_12*a_24*L1+1.0E+0*beta1*d2_1*a_23*b_L*a_6*a_10+d1_1*a_25
    a_27 = -1.0E+0*a_19*b_m*b_r*d2_1*a_1*a_23*a_12*a_6*a_20+1.0E+0*a_14 \
        *d3_1*a_12*a_24*a_15+a_11*d4_1*a_25*L1+1.0E+0*d1_1*a_23*b_L*a_6
    a_28 = 1.0E+0*a_27+a_L*a_26
    a_29 = 1/a_20
    a_30 = 1/a_15
    a_31 = -1.0E+0*beta1*d2_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_8*a_6*a_10 \
        -a_13*d3_1*EI*a_9*a_30-1.0E+0*a_18*d4_1*a_2*GthNum*K_act*a_3*a_4 \
        *a_5*b_L*EI*a_6*a_29+1.0E+0*b_m*b_r*d1_1*a_2*GthNum*K_act*a_3 \
        *s*a_5*a_6
    a_32 = a_m*a_1*a_21+a_m*a_r*a_1*a_16+1.0E+0*a_31
    a_33 = beta2**3
    a_34 = a_22+a_17
    a_35 = 1/L2**3
    a_36 = beta2**2
    a_37 = 1/L2**2
    a_38 = a_L-a_r
    a_39 = a_1*a_I-a_m*a_r*a_1*a_38
    a_40 = -a_m*a_1*a_38*a_21+a_39*a_16+1.0E+0*(-1.0E+0*a_11*b_m*b_r*d4_1 \
        *a_2*GthNum*K_act*a_3*s*a_5*a_6*L1+beta1*d2_1*EI*a_9*a_10+1.0E+0 \
        *a_13*d3_1*a_2*GthNum*K_act*a_3*a_4*a_5*b_L*EI*a_6*a_30+1.0E+0 \
        *d1_1*a_2*GthNum*K_act*a_3*a_4*a_5*a_8*a_6)-a_L*a_31
    a_41 = 1/L2
    a_42 = beta2*d2_2*a_40*a_41+1.0E+0*a_36*d3_2*EI*a_16*a_37+a_33*d4_2 \
        *EI*a_34*a_35-d1_2*a_32
    a_43 = 1.0E+0*beta1*d2_1*b_L*a_10+a_13*d3_1*a_7*b_L*EI*a_30+1.0E+0 \
        *d1_1
    a_44 = -1.0E+0*a_14*d3_1*a_12*a_15-1.0E+0*a_11*d4_1*b_L*a_12*L1-d1_1 \
        *a_7*b_L
    a_45 = -1.0E+0*a_19*d2_1*a_12*a_20-1.0E+0*a_14*d3_1*b_L*a_12*a_15- \
        a_11*d4_1*a_7*b_L*L1
    a_46 = -a_m*a_1*a_38*a_45+a_39*a_44+1.0E+0*(-1.0E+0*a_11*d4_1*L1-beta1 \
        *d2_1*a_7*b_L*EI*a_10-1.0E+0*d1_1*b_L)-a_L*a_43
    a_47 = 1.0E+0*a_45+a_L*a_44
    a_48 = 1/beta2
    a_49 = a_m*a_1*a_45+a_m*a_r*a_1*a_44+1.0E+0*a_43
    a_50 = -1.0E+0*beta1*d2_1*a_24*a_10-a_13*d3_1*EI*a_25*a_30-1.0E+0* \
        a_18*d4_1*a_23*b_L*EI*a_6*a_29+1.0E+0*b_m*b_r*d1_1*a_1*a_23*a_6
    a_51 = a_m*a_1*a_27+a_m*a_r*a_1*a_26+1.0E+0*a_50
    a_52 = -a_m*a_1*a_38*a_27+a_39*a_26+1.0E+0*(-1.0E+0*a_11*b_m*b_r*d4_1 \
        *a_1*a_23*a_6*L1+beta1*d2_1*EI*a_25*a_10+1.0E+0*a_13*d3_1*a_23 \
        *b_L*EI*a_6*a_30+1.0E+0*d1_1*a_24)-a_L*a_50
    a_53 = beta2*d2_2*a_52*a_41+1.0E+0*a_36*d3_2*EI*a_26*a_37+a_33*d4_2 \
        *EI*a_28*a_35-d1_2*a_51
    a_54 = -beta2*d2_2*a_46*a_41-1.0E+0*a_36*d3_2*EI*a_44*a_37-a_33*d4_2 \
        *EI*a_47*a_35+d1_2*a_49
    a_55 = -a_48*d4_2*a_51*L2+1.0E+0*beta2*d2_2*EI*a_26*a_41+a_36*d3_2 \
        *EI*a_28*a_37+d1_2*a_52
    a_56 = 1/(a_54*a_55+a_53*(-a_48*d4_2*a_49*L2+1.0E+0*beta2*d2_2*EI* \
        a_44*a_41+a_36*d3_2*EI*a_47*a_37+d1_2*a_46))
    a_57 = a_48*d4_2*a_32*L2-1.0E+0*beta2*d2_2*EI*a_16*a_41-a_36*d3_2* \
        EI*a_34*a_37-d1_2*a_40
    RESULT = a_gain*a_1*(a_47*(a_42*a_55*a_56+a_53*a_57*a_56)+a_28*(a_54 \
        *a_57*a_56+a_42*(a_48*d4_2*a_49*L2-1.0E+0*beta2*d2_2*EI*a_44* \
        a_41-a_36*d3_2*EI*a_47*a_37-d1_2*a_46)*a_56)+a_22+a_17)
    return RESULT
Example #55
0
def log_2_pois_like(d,a,s1,s2): #taken out the max_score  limit for now
    dp = np.sign(d)*np.power(np.abs(d),1.5)
    return ( log(a)*(s1+s2)+dp*(5+s2-s1) -2*a*cosh(dp) -
             gammaln(s1+1) - gammaln(s2+1) )
Example #56
0
 def f(self,xarr,t):
     x0dot = self.A*(pl.cos(t)+0.2)*(-2*(pl.cosh(self.d-xarr[3]) + pl.cosh(xarr[3]))*(pl.cos(xarr[2])**2 - pl.cosh(self.d-xarr[3])*pl.cosh(xarr[3]))*pl.sin(xarr[2]))/((pl.cos(xarr[2]) - pl.cosh(self.d-xarr[3]))*(pl.cos(xarr[2]) + pl.cosh(self.d - xarr[3]))*(pl.cos(xarr[2]) - pl.cosh(xarr[3]))*(pl.cos(xarr[2]) + pl.cosh(xarr[3])))- self.beta*xarr[0]
     x1dot = self.A*(pl.cos(t)+0.2)*(2*pl.cos(xarr[2])*(pl.sinh(self.d - xarr[3]) - pl.sinh(xarr[3]))*(-pl.sin(xarr[2])**2 + pl.sinh(self.d - xarr[3])*pl.sinh(xarr[3])))/((pl.cos(xarr[2]) - pl.cosh(self.d - xarr[3]))*(pl.cos(xarr[2]) + pl.cosh(self.d - xarr[3]))*(pl.cos(xarr[2]) - pl.cosh(xarr[3]))*(pl.cos(xarr[2]) + pl.cosh(xarr[3])))- self.beta*xarr[1]
     x2dot = xarr[0]
     x3dot = xarr[1]
     return [x0dot,x1dot,x2dot,x3dot]
Example #57
0
    def f(self,x,t):
        # the 4.0 only works for 2D
        N = len(x)/4
        xdot = pl.array([])
        # modulus the x component to keep periodicity right.
        x[2*N:3*N]= x[2*N:3*N]%self.diameter

        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive x interparticle force of j on i
                temp += self.qq*(x[2*N+i]-x[2*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
                # force from same particle but in other direction becasue of periodic boundar
                # conditions
                temp += -self.qq*(self.diameter-(x[2*N+i]-x[2*N+j]))/(pl.sqrt((self.diameter-(x[2*N+i]-x[2*N+j]))**2+(x[3*N+i]-x[3*N+j])**2)**3)
                # could do this forever but for now just include one more of force going around in
                # same direction as first. draw a diagam if you need to
                temp += self.qq*(self.diameter+(x[2*N+i]-x[2*N+j]))/(pl.sqrt((self.diameter+(x[2*N+i]-x[2*N+j]))**2+(x[3*N+i]-x[3*N+j])**2)**3)
            # EC x force on particle i
            temp += self.A*(self.square_wave(t))*(-2*(pl.cosh(self.d-x[3*N+i]) + \
                pl.cosh(x[3*N+i]))*(pl.cos(x[2*N+i])**2 - \
                    pl.cosh(self.d-x[3*N+i])*pl.cosh(x[3*N+i]))*pl.sin(x[2*N+i]))/((pl.cos(x[2*N+i])\
                        - pl.cosh(self.d-x[3*N+i]))*(pl.cos(x[2*N+i]) + pl.cosh(self.d - \
                            x[3*N+i]))*(pl.cos(x[2*N+i]) - pl.cosh(x[3*N+i]))*(pl.cos(x[2*N+i]) + \
                                pl.cosh(x[3*N+i]))) - self.beta*x[i]
            xdot = pl.append(xdot,temp)
        for i in range(N):
            temp = 0.0
            for j in range(N):
                if i == j:
                    continue
                #repulsive y interparticle force of j on i
                temp += self.qq*(x[3*N+i]-x[3*N+j])/(pl.sqrt((x[2*N+i]-x[2*N+j])**2+(x[3*N+i]-x[3*N+j])**2)**3)
                # force from same particle but in other direction becasue of periodic boundar
                # conditions
                temp += self.qq*(x[3*N+i]-x[3*N+j])/(pl.sqrt((self.diameter-(x[2*N+i]-x[2*N+j]))**2+(x[3*N+i]-x[3*N+j])**2)**3)
            # EC y force on particle i
            temp += self.A*(self.square_wave(t))*(2*pl.cos(x[2*N+i])*(pl.sinh(self.d - x[3*N+i]) - \
                pl.sinh(x[3*N+i]))*(-pl.sin(x[2*N+i])**2 + pl.sinh(self.d - \
                    x[3*N+i])*pl.sinh(x[3*N+i])))/((pl.cos(x[2*N+i]) - pl.cosh(self.d - \
                        x[3*N+i]))*(pl.cos(x[2*N+i]) + pl.cosh(self.d - x[3*N+i]))*(pl.cos(x[2*N+i]) \
                            - pl.cosh(x[3*N+i]))*(pl.cos(x[2*N+i]) + \
                                pl.cosh(x[3*N+i])))-self.beta*x[N+i] 
            # quadropole restoring force to center of electric curtains
            temp += -self.quadA*(pl.cos(200.0*t)+0.1)*(x[3*N+i]-self.d/2.0)
            xdot = pl.append(xdot,temp)
        for i in range(N):
            xdot = pl.append(xdot,x[i]) 
        for i in range(N):
            xdot = pl.append(xdot,x[N+i])
        return xdot
Example #58
0
def tanh_grad(X):
    return 1 / np.square(np.cosh(X))