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)
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))
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 )
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
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
def test_thermal_conduction(): # Generate Network and clean up boundaries (delete z-face pores) divs = [10, 50] Lc = 0.1 # cm pn = OpenPNM.Network.Cubic(shape=divs, spacing=Lc) pn.add_boundaries() pn.trim(pores=pn.pores(['top_boundary', 'bottom_boundary'])) # Generate Geometry objects for internal and boundary pores Ps = pn.pores('internal') Ts = pn.throats() geom = OpenPNM.Geometry.GenericGeometry(network=pn, pores=Ps, throats=Ts) geom['pore.area'] = Lc**2 geom['pore.diameter'] = Lc geom['throat.length'] = 1e-25 geom['throat.area'] = Lc**2 Ps = pn.pores('boundary') boun = OpenPNM.Geometry.GenericGeometry(network=pn, pores=Ps) boun['pore.area'] = Lc**2 boun['pore.diameter'] = 1e-25 # Create Phase object and associate with a Physics object Cu = OpenPNM.Phases.GenericPhase(network=pn) Cu['pore.thermal_conductivity'] = 1.0 # W/m.K phys = OpenPNM.Physics.GenericPhysics(network=pn, phase=Cu, pores=pn.pores(), throats=pn.throats()) mod = OpenPNM.Physics.models.thermal_conductance.series_resistors phys.add_model(propname='throat.thermal_conductance', model=mod) phys.regenerate() # Update the conductance values # Setup Algorithm object Fourier_alg = OpenPNM.Algorithms.FourierConduction(network=pn, phase=Cu) inlets = pn.pores('back_boundary') outlets = pn.pores(['front_boundary', 'left_boundary', 'right_boundary']) T_in = 30 * sp.sin(sp.pi * pn['pore.coords'][inlets, 1] / 5) + 50 Fourier_alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=T_in, pores=inlets) Fourier_alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=50, pores=outlets) Fourier_alg.run() Fourier_alg.return_results() # Calculate analytical solution over the same domain spacing Cu['pore.analytical_temp'] = 30 * sp.sinh( sp.pi * pn['pore.coords'][:, 0] / 5) / sp.sinh(sp.pi / 5) * sp.sin( sp.pi * pn['pore.coords'][:, 1] / 5) + 50 b = Cu['pore.analytical_temp'][pn.pores(geom.name)] a = Cu['pore.temperature'][pn.pores(geom.name)] a = sp.reshape(a, (divs[0], divs[1])) b = sp.reshape(b, (divs[0], divs[1])) diff = a - b assert sp.amax(np.absolute(diff)) < 0.015
def test_thermal_conduction(): # Generate Network and clean up boundaries (delete z-face pores) divs = [10, 50] Lc = 0.1 # cm pn = OpenPNM.Network.Cubic(shape=divs, spacing=Lc) pn.add_boundaries() pn.trim(pores=pn.pores(['top_boundary', 'bottom_boundary'])) # Generate Geometry objects for internal and boundary pores Ps = pn.pores('internal') Ts = pn.throats() geom = OpenPNM.Geometry.GenericGeometry(network=pn, pores=Ps, throats=Ts) geom['pore.area'] = Lc**2 geom['pore.diameter'] = Lc geom['throat.length'] = 1e-25 geom['throat.area'] = Lc**2 Ps = pn.pores('boundary') boun = OpenPNM.Geometry.GenericGeometry(network=pn, pores=Ps) boun['pore.area'] = Lc**2 boun['pore.diameter'] = 1e-25 # Create Phase object and associate with a Physics object Cu = OpenPNM.Phases.GenericPhase(network=pn) Cu['pore.thermal_conductivity'] = 1.0 # W/m.K phys = OpenPNM.Physics.GenericPhysics(network=pn, phase=Cu, pores=pn.pores(), throats=pn.throats()) mod = OpenPNM.Physics.models.thermal_conductance.series_resistors phys.add_model(propname='throat.thermal_conductance', model=mod) phys.regenerate() # Update the conductance values # Setup Algorithm object Fourier_alg = OpenPNM.Algorithms.FourierConduction(network=pn, phase=Cu) inlets = pn.pores('back_boundary') outlets = pn.pores(['front_boundary', 'left_boundary', 'right_boundary']) T_in = 30*sp.sin(sp.pi*pn['pore.coords'][inlets, 1]/5)+50 Fourier_alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=T_in, pores=inlets) Fourier_alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=50, pores=outlets) Fourier_alg.run() Fourier_alg.return_results() # Calculate analytical solution over the same domain spacing Cu['pore.analytical_temp'] = 30*sp.sinh(sp.pi*pn['pore.coords'][:, 0]/5)/sp.sinh(sp.pi/5)*sp.sin(sp.pi*pn['pore.coords'][:, 1]/5) + 50 b = Cu['pore.analytical_temp'][pn.pores(geom.name)] a = Cu['pore.temperature'][pn.pores(geom.name)] a = sp.reshape(a, (divs[0], divs[1])) b = sp.reshape(b, (divs[0], divs[1])) diff = a - b assert sp.amax(np.absolute(diff)) < 0.015
def calculate_eps_eff_from_geometry(substrate_epsR,pinw,gapw,substrate_height): a=pinw b=pinw+2*gapw h=substrate_height k0 = float(a)/b k0p = sqrt(1-k0**2) #k3 = tanh(pi*a/(4*h))/ tanh(pi*b/(4*h)) k3 = sinh(pi*a/(4*h)) / sinh(pi*b/(4*h)) k3p= sqrt(1-k3**2) Ktwid= ellipk(k0p**2)*ellipk(k3**2)/(ellipk(k0**2)*ellipk(k3p**2)) #return (1+substrate_epsR*Ktwid)/(1+Ktwid) return 1 + (substrate_epsR - 1) * Ktwid / 2
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 __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)
def sinh(ent): """Polymorphic sinh function that adapts to either a numeric or symbolic string input.""" if isinstance(ent,str): return symstr('sinh('+ent+')') else: return scipy.sinh(ent)
def __init__(self, Om, Ok=0): ### ignore Orad and neutrinos c = speed_light / 1000. ## km/s H0 = 100. ## km/s/Mpc Or = 0. Ol = 1. - Ok - Om - Or nbins = 10000 zmax = 10. dz = zmax / nbins z = sp.arange(nbins) * dz hubble = H0 * sp.sqrt(Ol + Ok * (1. + z)**2 + Om * (1. + z)**3 + Or * (1. + z)**4) chi = sp.zeros(nbins) for i in range(1, nbins): chi[i] = chi[i - 1] + c * (1. / hubble[i - 1] + 1. / hubble[i]) / 2. * dz self.r_comoving = interpolate.interp1d(z, chi) ## da here is the comoving angular diameter distance if Ok == 0.: da = chi elif Ok < 0.: da = sp.sin(H0 * sp.sqrt(-Ok) / c * chi) / (H0 * sp.sqrt(-Ok) / c) elif Ok > 0.: da = sp.sinh(H0 * sp.sqrt(Ok) / c * chi) / (H0 * sp.sqrt(Ok) / c) self.da = interpolate.interp1d(z, da) self.hubble = interpolate.interp1d(z, hubble) self.r_2_z = interpolate.interp1d(chi, z)
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))
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
def little_f(x, minx, maxx,Q,alph): f = sp.zeros_like(x) maxx = minx + sp.sinh(Q)/(alph*Q) ; #print maxx f = sp.arcsinh(alph*Q*(x-minx))/Q f[sp.where(x < minx)]=0.0 f[sp.where(x > maxx)]=1.0 return f
def vx_pert(mode, x, z, t, W, K, R1): vx_hat_vals = np.zeros((len(x), len(z)), dtype=complex) vx_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: vx_hat_vals[i,j] = (constB(mode, W, K, R1)*sc.cosh(m0(W)*sol[0]) + constC(mode, W, K, R1)*sc.sinh(m0(W)*sol[0])) elif sol[0] < -K: vx_hat_vals[i,j] = constA(mode, W, K, R1)*(sc.cosh(m1(W, R1)*sol[0]) + sc.sinh(m1(W, R1)*sol[0])) elif sol[0] > K: vx_hat_vals[i,j] = constD(mode, W, K, R1)*(sc.cosh(m2(W)*sol[0]) - sc.sinh(m2(W)*sol[0])) vx_vals[i,j] = vx_hat_vals[i,j] * np.exp(1j*(z[j]-t)) return vx_vals
def little_f(x, minx, maxx,Q,alph): f = sp.zeros_like(x) maxx = minx + sp.sinh(Q)/(alph*Q) ; #print maxx f = sp.arcsinh(alph*Q*(x-minx))/Q f[sp.where(x < minx)]=0.0 f[sp.where(x > maxx)]=1.0 return f
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
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
def vxhat(mode, x, W, K, R1): if 'alfven' in mode: vxhatfunction = np.zeros_like(x) else: if type(x) == float or type(x) == np.float64: if np.abs(x) <= K: vxhatfunction = (constB(mode, W, K, R1)*sc.cosh(m0(W)*x) + constC(mode, W, K, R1)*sc.sinh(m0(W)*x)) elif x < -K: vxhatfunction = constA(mode, W, K, R1)*(sc.cosh(m1(W, R1)*x) + sc.sinh(m1(W, R1)*x)) elif x > K: vxhatfunction = constD(mode, W, K, R1)*(sc.cosh(m2(W)*x) - sc.sinh(m2(W)*x)) else: truth = np.array(np.abs(x) <= K*np.ones(len(x))) indices = np.where(truth == True) vxhatfunction = np.zeros(len(x), dtype=complex) for i in indices: vxhatfunction[i] = (constB(mode, W, K, R1)*sc.cosh(m0(W)*x[i]) + constC(mode, W, K, R1)*sc.sinh(m0(W)*x[i])) truth2 = np.array(x < -K*np.ones(len(x))) indices2 = np.where(truth2 == True) for i in indices2: vxhatfunction[i] = constA(mode, W, K, R1)*(sc.cosh(m1(W, R1)*x[i]) + sc.sinh(m1(W, R1)*x[i])) truth3 = np.array(x > K*np.ones(len(x))) indices3 = np.where(truth3 == True) for i in indices3: vxhatfunction[i] = constD(mode, W, K, R1)*(sc.cosh(m2(W)*x[i]) - sc.sinh(m2(W)*x[i])) return vxhatfunction
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
def FillFDplusBE(En_A, T): """ fill an array with a som of Bose-Einstein and Fermi-Dirac numerically more precise than the sum of the above functions due to a pole in BE """ N = int((len(En_A) - 1) / 2) sp.seterr(over='ignore') ## ignore overflow in sinh sp.seterr(divide='ignore') ## we deal with the pole ourselves if T == 0.0: FB_A = sp.zeros(len(En_A)) else: FB_A = 1.0 / sp.sinh(En_A / T) FB_A[N] = 0.0 sp.seterr(divide='warn') sp.seterr(over='warn') return FB_A
def FillFDplusBE(En_A,T): """ fill an array with a som of Bose-Einstein and Fermi-Dirac numerically more precise than the sum of the above functions due to a pole in BE """ N = int((len(En_A)-1)/2) sp.seterr(over= 'ignore') ## ignore overflow in sinh sp.seterr(divide='ignore') ## we deal with the pole ourselves if T == 0.0: FB_A = sp.zeros(len(En_A)) else: FB_A = 1.0/sp.sinh(En_A/T) FB_A[N] = 0.0 sp.seterr(divide='warn') sp.seterr(over= 'warn') return FB_A
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
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
def Da_z(self, z): # r=intg.quad(self.Hinv_z,0,z) # this version seems to be faster r = intg.quad(self.DistIntegrand_a, 1. / (1 + z), 1) r = r[0] # assume precision is ok if self.Curv == 0: return r elif (self.Curv > 0): q = sp.sqrt(self.Curv) # someone check this eq # Pure ADD has a 1+z fact, but have # comoving one return sp.sinh(r * q) / (q) else: q = sp.sqrt(-self.Curv) return sp.sin(r * q) / (q)
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
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)
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 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 __init__(self, Om, Ok=0., Or=0., wl=-1., H0=100.): ### Ignore evolution of neutrinos from matter to radiation ### H0 in km/s/Mpc c = speed_light / 1000. ## km/s Ol = 1. - Ok - Om - Or nbins = 10000 zmax = 10. dz = zmax / nbins z = sp.arange(nbins) * dz hubble = H0 * sp.sqrt(Ol * (1. + z)**(3. * (1. + wl)) + Ok * (1. + z)**2 + Om * (1. + z)**3 + Or * (1. + z)**4) chi = sp.zeros(nbins) for i in range(1, nbins): chi[i] = chi[i - 1] + c * (1. / hubble[i - 1] + 1. / hubble[i]) / 2. * dz self.r_comoving = interpolate.interp1d(z, chi) ### dm here is the comoving angular diameter distance if Ok == 0.: dm = chi elif Ok < 0.: dm = sp.sin(H0 * sp.sqrt(-Ok) / c * chi) / (H0 * sp.sqrt(-Ok) / c) elif Ok > 0.: dm = sp.sinh(H0 * sp.sqrt(Ok) / c * chi) / (H0 * sp.sqrt(Ok) / c) self.hubble = interpolate.interp1d(z, hubble) self.r_2_z = interpolate.interp1d(chi, z) ### D_H self.dist_hubble = interpolate.interp1d(z, c / hubble) ### D_M self.dm = interpolate.interp1d(z, dm) ### D_V y = sp.power(z * self.dm(z)**2 * self.dist_hubble(z), 1. / 3.) self.dist_v = interpolate.interp1d(z, y)
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
def __init__(self, k=10, mode_vector=np.array([[0.], [0.], [1.]])): """ Initialization method :param k: concentration parameter (integer; default 10) :param mode_vector: mode vector (np.array of shape (3, 1); default [0,0,1]) """ self.k = k self._ck = sp.sinh(k) * (2 / k) self.mode_vector = mode_vector tuple_mode_vector = tuple(self.mode_vector[:, 0].tolist()) az, el, r = mc.cart2sph(*tuple_mode_vector) self.mode_vector_sph = np.array([[az], [el], [r]]) if (mode_vector == np.array([[0.], [0.], [1.]])).all(): self.rot = np.identity(3) else: rot1 = mc.roty((np.pi / 2) - el) rot2 = mc.rotz(az) self.rot = rot2 @ rot1 def w_mvf_pdf(x): return sp.exp(np.array(x, ndmin=1) * self.k) / self._ck def w_mvf_cdf(x): return (sp.exp(self.k * np.array(x, ndmin=1)) - sp.exp(-self.k)) / (self.k * self._ck) def w_mvf_inv_cdf(x): return sp.log( sp.exp(-self.k) + self.k * self._ck * np.array(x, ndmin=1)) / self.k self.w = ContinuousDistribution1D(name='w_vmf', pdf=w_mvf_pdf, cdf=w_mvf_cdf, inv_cdf=w_mvf_inv_cdf)
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)
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
circle = shapes.genCircle(1.,1.,0.,0.,400) confMap(circle,gFunc) ''' #Prob 3 def testHolo(func,a,b,r,tol): circle = shapes.genCircle(r,a,b,400) vals = func(circle) diff = max(vals) - min(vals) if(diff < tol ): return "differentiable" else: return "not differentiable {0}".format(diff) #my solution apparently didn't work, it says that all the functions are not differentiable print testHolo(lambda z: sp.real(z),1,1,0.01,1) print testHolo(lambda z: sp.absolute(z),1,1,0.01,1) print testHolo(lambda z: sp.conj(z),1,0,0.01,1) print testHolo(lambda z: z*sp.real(z),0,0,0.01,1) print testHolo(lambda z: z*sp.real(z),1,1,0.01,1) print testHolo(lambda z: sp.exp(z),0,np.pi,0.01,1) print testHolo(lambda z: sp.sin(sp.real(z))*sp.cosh(sp.imag(z))+ sp.cos(sp.real(z))*sp.sinh(sp.imag(z))*1j ,0,np.pi,0.01,1) print testHolo(lambda z: sp.sin(sp.real(z))*sp.cosh(sp.imag(z)) -sp.cos(sp.real(z))*sp.sinh(sp.imag(z))*1j,0,np.pi,0.01,1)
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
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 mymesh = mysys.CreateMesh() myx = mymesh[:, 0] pylab.ioff() pylab.figure(fi) pylab.cla()
def D(mode, W, M_A): return (sc.cosh(m2(W) * K) - sc.sinh(m2(W) * K) )**(-1) * \ (sc.cosh(m0(W, M_A) * K) * B(mode, W, M_A) + sc.sinh(m0(W, M_A) * K) * C(mode, W, M_A)) * W / (W - M_A)
Fourier_alg = OpenPNM.Algorithms.FourierConduction(network=pn, phase=Cu) inlets = pn.pores('back_boundary') outlets = pn.pores(['front_boundary', 'left_boundary', 'right_boundary']) T_out = 50 # Kelvin T_in = 30 * sp.sin(sp.pi * pn['pore.coords'][inlets, 1] / 5) + 50 Fourier_alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=T_in, pores=inlets) Fourier_alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=T_out, pores=outlets) Fourier_alg.run() Fourier_alg.return_results() Cu['pore.analytical_temp'] = 30 * sp.sinh( sp.pi * pn['pore.coords'][:, 0] / 5) / sp.sinh(sp.pi / 5) * sp.sin( sp.pi * pn['pore.coords'][:, 1] / 5) + 50 a = Cu['pore.temperature'][pn.pores('geom')] b = Cu['pore.analytical_temp'][pn.pores('geom')] a = sp.reshape(a, (divs[0], divs[1])) b = sp.reshape(b, (divs[0], divs[1])) plt.subplot(3, 1, 1) plt.imshow(b, interpolation='none') plt.colorbar() plt.subplot(3, 1, 2) plt.imshow(a, interpolation='none') plt.colorbar() plt.subplot(3, 1, 3) plt.imshow(a - b, interpolation='none') plt.colorbar()
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
def C(mode, W, M_A): if mode == 'sausage': return 0.1 else: return B(mode, W, M_A) * (lambda0(W, M_A) * sc.sinh(m0(W, M_A) * K) * (W - M_A) - lambda1(W) * sc.cosh(m0(W, M_A) * K) * W) / \ (lambda0(W, M_A) * sc.cosh(m0(W, M_A) * K) * (W - M_A) - lambda1(W) * sc.sinh(m0(W, M_A) * K) * W)
def Cp(self, T): [C1, C2, C3, C4, C5] = self.constCp cp = C1 + C2 * ((C3 / T) / sc.sinh(C3 / T))**2 + C4 * ( (C5 / T) / sc.cosh(C5 / T))**2 return cp
model=pm.thermal_conductance.series_resistors) #============================================================================== '''Run Algorithms''' #============================================================================== Fourier_alg = OpenPNM.Algorithms.FourierConduction(network=pn,phase=Cu) inlets = pn.pores('back_boundary') outlets = pn.pores(['front_boundary','left_boundary','right_boundary']) T_out = 50 # Kelvin T_in = 30*sp.sin(sp.pi*pn['pore.coords'][inlets,1]/5)+50 Fourier_alg.set_boundary_conditions(bctype='Dirichlet',bcvalue=T_in,pores=inlets) Fourier_alg.set_boundary_conditions(bctype='Dirichlet',bcvalue=T_out,pores=outlets) Fourier_alg.run() Fourier_alg.return_results() Cu['pore.analytical_temp'] = 30*sp.sinh(sp.pi*pn['pore.coords'][:,0]/5)/sp.sinh(sp.pi/5)*sp.sin(sp.pi*pn['pore.coords'][:,1]/5) + 50 a = Cu['pore.temperature'][pn.pores('geom')] b = Cu['pore.analytical_temp'][pn.pores('geom')] a = sp.reshape(a,(divs[0],divs[1])) b = sp.reshape(b,(divs[0],divs[1])) plt.subplot(3,1,1) plt.imshow(b,interpolation='none') plt.colorbar() plt.subplot(3,1,2) plt.imshow(a,interpolation='none') plt.colorbar() plt.subplot(3,1,3) plt.imshow(a-b,interpolation='none') plt.colorbar()
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] pylab.ioff() pylab.figure(n+1) pylab.cla() pylab.plot(myx,disps) pylab.plot(xvect,curAY)
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] )
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
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
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]