def fullDet(b, nu): a = rho * b i = ivp(nu, u1 * a) / (u1 * a * iv(nu, u1 * a)) if nu == 1: k2 = -2 k = 0 else: k2 = 2 * nu / (u2 * b)**2 - 1 / (nu - 1) k = -1 X = (1 / (u1 * a)**2 + 1 / (u2 * a)**2) P1 = jn(nu, u2 * a) * yn(nu, u2 * b) - yn(nu, u2 * a) * jn(nu, u2 * b) P2 = (jvp(nu, u2 * a) * yn(nu, u2 * b) - yvp(nu, u2 * a) * jn(nu, u2 * b)) / (u2 * a) P3 = (jn(nu, u2 * a) * yvp(nu, u2 * b) - yn(nu, u2 * a) * jvp(nu, u2 * b)) / (u2 * b) P4 = (jvp(nu, u2 * a) * yvp(nu, u2 * b) - yvp(nu, u2 * a) * jvp(nu, u2 * b)) / (u2 * a * u2 * b) A = (n12 * i**2 - n32 * nu**2 * X**2) if nu == 1: B = 0 else: B = 2 * n22 * n32 * nu * X * (P1 * P4 - P2 * P3) return (n32 * k2 * A * P1**2 + (n12 + n22) * n32 * i * k2 * P1 * P2 - (n22 + n32) * k * A * P1 * P3 - (n12 * n32 + n22 * n22) * i * k * P1 * P4 + n22 * n32 * k2 * P2**2 - n22 * (n12 + n32) * i * k * P2 * P3 - n22 * (n22 + n32) * k * P2 * P4 - B)
def exact(k, R1, R2, derivs): if (derivs): # Bessel evaluated at R1 J0_1 = special.j0(k * R1) Y0_1 = special.y0(k * R1) J1_1 = special.j1(k * R1) Y1_1 = special.y1(k * R1) # Bessel evaluated at R2 J0_2 = special.j0(k * R2) Y0_2 = special.y0(k * R2) J1_2 = special.j1(k * R2) Y1_2 = special.y1(k * R2) # # d Z1(k r)/dr = k*Z0(k r) - Z1(k r) / r # Jprime_1 = k * J0_1 - J1_1 / R1 Jprime_2 = k * J0_2 - J1_2 / R2 Yprime_1 = k * Y0_1 - Y1_1 / R1 Yprime_2 = k * Y0_2 - Y1_2 / R2 else: Jprime_1 = special.jvp(1, k * R1, 1) Jprime_2 = special.jvp(1, k * R2, 1) Yprime_1 = special.yvp(1, k * R1, 1) Yprime_2 = special.yvp(1, k * R2, 1) # F(k r) = J'_m(kr R1) * Y'_m(kr R2) - J'_m(kr R2) * Y'_m(kr R1) = 0 return Jprime_1 * Yprime_2 - Jprime_2 * Yprime_1
def fullDet(b, nu): a = rho * b i = ivp(nu, u1*a) / (u1*a * iv(nu, u1*a)) if nu == 1: k2 = -2 k = 0 else: k2 = 2 * nu / (u2 * b)**2 - 1 / (nu - 1) k = -1 X = (1 / (u1*a)**2 + 1 / (u2*a)**2) P1 = jn(nu, u2*a) * yn(nu, u2*b) - yn(nu, u2*a) * jn(nu, u2*b) P2 = (jvp(nu, u2*a) * yn(nu, u2*b) - yvp(nu, u2*a) * jn(nu, u2*b)) / (u2 * a) P3 = (jn(nu, u2*a) * yvp(nu, u2*b) - yn(nu, u2*a) * jvp(nu, u2*b)) / (u2 * b) P4 = (jvp(nu, u2*a) * yvp(nu, u2*b) - yvp(nu, u2*a) * jvp(nu, u2*b)) / (u2 * a * u2 * b) A = (n12 * i**2 - n32 * nu**2 * X**2) if nu == 1: B = 0 else: B = 2 * n22 * n32 * nu * X * (P1 * P4 - P2 * P3) return (n32 * k2 * A * P1**2 + (n12 + n22) * n32 * i * k2 * P1 * P2 - (n22 + n32) * k * A * P1 * P3 - (n12*n32 + n22*n22) * i * k * P1 * P4 + n22 * n32 * k2 * P2**2 - n22 * (n12 + n32) * i * k * P2 * P3 - n22 * (n22 + n32) * k * P2 * P4 - B)
def nj_dev(pr=0, m=31, n=11, deg=0): if deg == 0: x_mn = jn_zeros(m, n)[-1] func = jvp(m, x_mn, 0) * yvp(m, x_mn * pr, 0) elif deg == 1: x_mn = jnp_zeros(m, n)[-1] func = jvp(m, x_mn, 1) * yvp(m, x_mn * pr, 0) print(x_mn) return func
def test_cylindrical_bessel_y_prime(): order = np.random.randint(0, 5) value = np.random.rand(1).item() assert (roundScaler(NumCpp.bessel_yn_prime_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler(sp.yvp(order, value).item(), NUM_DECIMALS_ROUND)) shapeInput = np.random.randint(20, 100, [2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 5) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) assert np.array_equal(roundArray(NumCpp.bessel_yn_prime_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.yvp(order, data), NUM_DECIMALS_ROUND))
def compute_eigenvector(r, sigma, m, zero): """ Return the eigenvector for the system. Args: r (np.array(float)): array of radial locations. sigma (float): ratio of inner to outer radius, ri/ro. m (int): circumferential wavenumber. zero (float): a zero of the determinant of the convected wave equation Returns: the eigenvector associated with the input 'm' and 'zero', evaluated at radial locations defined by the input array 'r'. Length of the return array is len(r). """ Q_mn = -sp.jvp(m, sigma * zero) / sp.yvp(m, sigma * zero) eigenvector = np.zeros(len(r)) for irad in range(len(r)): eigenvector[irad] = \ sp.jv(m, zero*r[irad]) + Q_mn*sp.yv(m, zero*r[irad]) # Normalize the eigenmode. Find abs of maximum value. ev_mag = np.absolute(eigenvector) ev_max = np.max(ev_mag) eigenvector = eigenvector / ev_max return eigenvector
def _hefield(self, wl, nu, neff, r): self._heceq(neff, wl, nu) for i, rho in enumerate(self.fiber._r): if r < rho: break else: i += 1 layer = self.fiber.layers[i] n = layer.maxIndex(wl) u = layer.u(rho, neff, wl) urp = u * r / rho c1 = rho / u c2 = wl.k0 * c1 c3 = nu * c1 / r if r else 0 # To avoid div by 0 c6 = constants.Y0 * n * n if neff < n: B1 = jn(nu, u) B2 = yn(nu, u) F1 = jn(nu, urp) / B1 F2 = yn(nu, urp) / B2 if i > 0 else 0 F3 = jvp(nu, urp) / B1 F4 = yvp(nu, urp) / B2 if i > 0 else 0 else: c2 = -c2 B1 = iv(nu, u) B2 = kn(nu, u) F1 = iv(nu, urp) / B1 F2 = kn(nu, urp) / B2 if i > 0 else 0 F3 = ivp(nu, urp) / B1 F4 = kvp(nu, urp) / B2 if i > 0 else 0 A, B, Ap, Bp = layer.C[:, 0] + layer.C[:, 1] * self.alpha Ez = A * F1 + B * F2 Ezp = A * F3 + B * F4 Hz = Ap * F1 + Bp * F2 Hzp = Ap * F3 + Bp * F4 if r == 0 and nu == 1: # Asymptotic expansion of Ez (or Hz): # J1(ur/p)/r (r->0) = u/(2p) if neff < n: f = 1 / (2 * jn(nu, u)) else: f = 1 / (2 * iv(nu, u)) c3ez = A * f c3hz = Ap * f else: c3ez = c3 * Ez c3hz = c3 * Hz Er = c2 * (neff * Ezp - constants.eta0 * c3hz) Ep = c2 * (neff * c3ez - constants.eta0 * Hzp) Hr = c2 * (neff * Hzp - c6 * c3ez) Hp = c2 * (-neff * c3hz + c6 * Ezp) return numpy.array((Er, Ep, Ez)), numpy.array((Hr, Hp, Hz))
def cutoffHE2(b): nu = 2 a = rho * b i = ivp(2, u1*a) / (u1*a * iv(2, u1*a)) X = (1 / (u1*a)**2 + 1 / (u2*a)**2) P1 = jn(nu, u2*a) * yn(nu, u2*b) - yn(nu, u2*a) * jn(nu, u2*b) P2 = (jvp(nu, u2*a) * yn(nu, u2*b) - yvp(nu, u2*a) * jn(nu, u2*b)) / (u2 * a) P3 = (jn(nu, u2*a) * yvp(nu, u2*b) - yn(nu, u2*a) * jvp(nu, u2*b)) / (u2 * b) P4 = (jvp(nu, u2*a) * yvp(nu, u2*b) - yvp(nu, u2*a) * jvp(nu, u2*b)) / (u2 * a * u2 * b) A = 2 * nu / (u2 * b)**2 - 1 / (nu - 1) return (n22 / n32 * (i*P1 + P2) * (n12*i*P3 + n22 * P4) + (A * i * P1 + A * P2 + i*P3 + P4) * (n12*i*P1 + n22*P2) - n32 * nu**2 * X**2 * P1 * (A * P1 + P3) - n22 * nu * X * (nu * X * P1 * P3 + 2 * P1 * P4 - 2 * P2 * P3))
def lpConstants(self, r, neff, wl, nu, A): u = self.u(r, neff, wl) if neff < self.maxIndex(wl): W = constants.pi / 2 return (W * (u * yvp(nu, u) * A[0] - yn(nu, u) * A[1]), W * (jn(nu, u) * A[1] - u * jvp(nu, u) * A[0])) else: return ((u * kvp(nu, u) * A[0] - kn(nu, u) * A[1]), (iv(nu, u) * A[1] - u * ivp(nu, u) * A[0]))
def solve_for_AB(k, R1, R2): # solve the system for A,B # # / J'_m(k R1) Y'_m(k R1) \ /A\ -- /0\ # \ J'_m(k R2) Y'_m(k R2) / \B/ -- \0/ M = numpy.zeros((2, 2)) M[0][0] = special.jvp(1, k * R1, 1) # Jprime_1 at R1 M[0][1] = special.yvp(1, k * R1, 1) # Yprime_1 at R1 M[1][0] = special.jvp(1, k * R2, 1) # Jprime_1 at R2 M[1][1] = special.yvp(1, k * R2, 1) # Yprime_1 at R2 # close but no cigar to zero, otherwise it returns x=(0,0) b = numpy.array([1.e-16, 1.e-16]) x = numpy.linalg.solve(M, b) return x[0], x[1]
def cutoffHE1(b): a = rho * b i = ivp(1, u1*a) / (u1*a * i1(u1*a)) X = (1 / (u1*a)**2 + 1 / (u2*a)**2) P = j1(u2*a) * y1(u2*b) - y1(u2*a) * j1(u2*b) Ps = (jvp(1, u2*a) * y1(u2*b) - yvp(1, u2*a) * j1(u2*b)) / (u2 * a) return (i * P + Ps) * (n12 * i * P + n22 * Ps) - n32 * X * X * P * P
def cutoffHE1(b): a = rho * b i = ivp(1, u1 * a) / (u1 * a * i1(u1 * a)) X = (1 / (u1 * a)**2 + 1 / (u2 * a)**2) P = j1(u2 * a) * y1(u2 * b) - y1(u2 * a) * j1(u2 * b) Ps = (jvp(1, u2 * a) * y1(u2 * b) - yvp(1, u2 * a) * j1(u2 * b)) / (u2 * a) return (i * P + Ps) * (n12 * i * P + n22 * Ps) - n32 * X * X * P * P
def EH_fields(self, ri, ro, nu, neff, wl, EH, tm=True): """ modify EH in-place (for speed) """ n = self.maxIndex(wl) u = self.u(ro, neff, wl) if ri == 0: if nu == 0: if tm: self.C = numpy.array([1., 0., 0., 0.]) else: self.C = numpy.array([0., 0., 1., 0.]) else: self.C = numpy.zeros((4, 2)) self.C[0, 0] = 1 # Ez = 1 self.C[2, 1] = 1 # Hz = alpha elif nu == 0: self.C = numpy.zeros(4) if tm: c = constants.Y0 * n * n idx = (0, 3) self.C[:2] = self.tetmConstants(ri, ro, neff, wl, EH, c, idx) else: c = -constants.eta0 idx = (1, 2) self.C[2:] = self.tetmConstants(ri, ro, neff, wl, EH, c, idx) else: self.C = self.vConstants(ri, ro, neff, wl, nu, EH) # Compute EH fields if neff < n: c1 = wl.k0 * ro / u F3 = jvp(nu, u) / jn(nu, u) F4 = yvp(nu, u) / yn(nu, u) else: c1 = -wl.k0 * ro / u F3 = ivp(nu, u) / iv(nu, u) F4 = kvp(nu, u) / kn(nu, u) c2 = neff * nu / u * c1 c3 = constants.eta0 * c1 c4 = constants.Y0 * n * n * c1 EH[0] = self.C[0] + self.C[1] EH[1] = self.C[2] + self.C[3] EH[2] = (c2 * (self.C[0] + self.C[1]) - c3 * (F3 * self.C[2] + F4 * self.C[3])) EH[3] = (c4 * (F3 * self.C[0] + F4 * self.C[1]) - c2 * (self.C[2] + self.C[3])) return EH
def cutoffHE2(b): nu = 2 a = rho * b i = ivp(2, u1 * a) / (u1 * a * iv(2, u1 * a)) X = (1 / (u1 * a)**2 + 1 / (u2 * a)**2) P1 = jn(nu, u2 * a) * yn(nu, u2 * b) - yn(nu, u2 * a) * jn(nu, u2 * b) P2 = (jvp(nu, u2 * a) * yn(nu, u2 * b) - yvp(nu, u2 * a) * jn(nu, u2 * b)) / (u2 * a) P3 = (jn(nu, u2 * a) * yvp(nu, u2 * b) - yn(nu, u2 * a) * jvp(nu, u2 * b)) / (u2 * b) P4 = (jvp(nu, u2 * a) * yvp(nu, u2 * b) - yvp(nu, u2 * a) * jvp(nu, u2 * b)) / (u2 * a * u2 * b) A = 2 * nu / (u2 * b)**2 - 1 / (nu - 1) return (n22 / n32 * (i * P1 + P2) * (n12 * i * P3 + n22 * P4) + (A * i * P1 + A * P2 + i * P3 + P4) * (n12 * i * P1 + n22 * P2) - n32 * nu**2 * X**2 * P1 * (A * P1 + P3) - n22 * nu * X * (nu * X * P1 * P3 + 2 * P1 * P4 - 2 * P2 * P3))
def eigensystem(b, m, ri, ro): r""" Computes the function associated with the eigensystem of the convected wave equation. The location of the zeros for this function correspond to the eigenvalues for the convected wave equation. The solution to the Bessel equation with boundary conditions applied yields a system of two linear equations. .. math:: A x = \begin{bmatrix} J'_m(\mu \lambda) & Y'_m(\mu \lambda) \\ J'_m(\mu) & Y'_m(\mu) \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} = 0 This procedure evaluates the function .. math:: det(A) = f(b) = J_m(b*ri)*Y_m(b*ro) - J_m(b*ro)*Y_m(b*ri) So, this procedure can be passed to another routine such as numpy to find zeros. Args: b (float): coordinate. m (int): circumferential wave number. ri (float): inner radius of a circular annulus. ro (float): outer radius of a circular annulus. """ f = sp.jvp(m, b * ri) * sp.yvp(m, b * ro) - sp.jvp(m, b * ro) * sp.yvp( m, b * ri) return f
def Psi(self, r, neff, wl, nu, C): u = self.u(r, neff, wl) if neff < self.maxIndex(wl): psi = (C[0] * jn(nu, u) + C[1] * yn(nu, u) if C[1] else C[0] * jn(nu, u)) psip = u * (C[0] * jvp(nu, u) + C[1] * yvp(nu, u) if C[1] else C[0] * jvp(nu, u)) else: psi = (C[0] * iv(nu, u) + C[1] * kn(nu, u) if C[1] else C[0] * iv(nu, u)) psip = u * (C[0] * ivp(nu, u) + C[1] * kvp(nu, u) if C[1] else C[0] * ivp(nu, u)) # if numpy.isnan(psi): # print(neff, self.maxIndex(wl), C, r) return psi, psip
def JnYn(maxn, resolution): delta = numpy.pi / resolution z_table = numpy.mgrid[min(minz_j(maxn), minz_y(maxn)) : max(maxz_j(maxn), maxz_y(maxn)) : delta] J_table = [] Jdot_table = [] Y_table = [] Ydot_table = [] for n in range(maxn + 1): J_table.append(special.jn(n, z_table)) Jdot_table.append(special.jvp(n, z_table)) Y_table.append(special.yn(n, z_table)) Ydot_table.append(special.yvp(n, z_table)) return z_table, J_table, Jdot_table, Y_table, Ydot_table
def JnYn(maxn, resolution): delta = numpy.pi / resolution z_table = numpy.mgrid[min(minz_j(maxn),minz_y(maxn)): max(maxz_j(maxn), maxz_y(maxn)):delta] J_table = [] Jdot_table = [] Y_table = [] Ydot_table = [] for n in range(maxn+1): J_table.append(special.jn(n, z_table)) Jdot_table.append(special.jvp(n, z_table)) Y_table.append(special.yn(n, z_table)) Ydot_table.append(special.yvp(n, z_table)) return z_table, J_table, Jdot_table, Y_table, Ydot_table
def vConstants(self, ri, ro, neff, wl, nu, EH): a = numpy.zeros((4, 4)) n = self.maxIndex(wl) u = self.u(ro, neff, wl) urp = self.u(ri, neff, wl) if neff < n: B1 = jn(nu, u) B2 = yn(nu, u) F1 = jn(nu, urp) / B1 F2 = yn(nu, urp) / B2 F3 = jvp(nu, urp) / B1 F4 = yvp(nu, urp) / B2 c1 = wl.k0 * ro / u else: B1 = iv(nu, u) B2 = kn(nu, u) F1 = iv(nu, urp) / B1 if u else 1 F2 = kn(nu, urp) / B2 F3 = ivp(nu, urp) / B1 if u else 1 F4 = kvp(nu, urp) / B2 c1 = -wl.k0 * ro / u c2 = neff * nu / urp * c1 c3 = constants.eta0 * c1 c4 = constants.Y0 * n * n * c1 a[0, 0] = F1 a[0, 1] = F2 a[1, 2] = F1 a[1, 3] = F2 a[2, 0] = F1 * c2 a[2, 1] = F2 * c2 a[2, 2] = -F3 * c3 a[2, 3] = -F4 * c3 a[3, 0] = F3 * c4 a[3, 1] = F4 * c4 a[3, 2] = -F1 * c2 a[3, 3] = -F2 * c2 return numpy.linalg.solve(a, EH)
def _tmfield(self, wl, nu, neff, r): N = len(self.fiber) C = numpy.array((1, 0)) EH = numpy.zeros(4) ri = 0 for i in range(N-1): ro = self.fiber.outerRadius(i) layer = self.fiber.layers[i] n = layer.maxIndex(wl) u = layer.u(ro, neff, wl) if i > 0: C = layer.tetmConstants(ri, ro, neff, wl, EH, constants.Y0 * n * n, (0, 3)) if r < ro: break if neff < n: c1 = wl.k0 * ro / u F3 = jvp(nu, u) / jn(nu, u) F4 = yvp(nu, u) / yn(nu, u) else: c1 = -wl.k0 * ro / u F3 = ivp(nu, u) / iv(nu, u) F4 = kvp(nu, u) / kn(nu, u) c4 = constants.Y0 * n * n * c1 EH[0] = C[0] + C[1] EH[3] = c4 * (F3 * C[0] + F4 * C[1]) ri = ro else: layer = self.fiber.layers[-1] u = layer.u(ro, neff, wl) # C = return numpy.array((0, ephi, 0)), numpy.array((hr, 0, hz))
nargs=2) parser.add_argument("--lxy", dest="lxy", default=(100, 100), type=float) opt = parser.parse_args() print(opt, argvs) freq = convert_SI(opt.freq, unit_in='GHz', unit_out='Hz') wave = cnt.c / freq * convert(unit_in="m", unit_out="mm") px = np.linspace(-opt.lxy[0] / 2, opt.lxy[0] / 2, opt.nxy[0]) py = np.linspace(-opt.lxy[1] / 2, opt.lxy[1] / 2, opt.nxy[1]) mesh = np.meshgrid(px, py) x, y = mesh[0], mesh[1] r, t = np.sqrt(x**2 + y**2), np.arctan(y / x) m, n = opt.mn a, b = opt.radi if opt.mn[0] == 0: e_m = 1 else: e_m = 2 x0_i = jn_zeros(*opt.mn)[-1] x1_i = jnp_zeros(*opt.mn)[-1] func = jv(m, x1_i * r / b) * yvp(m, x1_i) - \ jvp(m, x1_i) * yv(m, x1_i * r / b) obj = plot2d(aspect="auto") obj.axs.contourf(x, y, func) obj.SavePng()
freq = np.fft.fftfreq(n, 1 / Fs) T = np.linspace(0, n * t, num=n, endpoint=False) # From 0 to n-1 t U = np.zeros(np.shape(T)) #omega = np.linspace(0,2*np.pi*Fs,n) epsilon = 1 / (0.2 * n * t) omega = 2 * np.pi * freq[0:n // 2 + 1] - 1j * epsilon k = omega / bbeta pome = 2 * np.pi * 0.1 R = 2 * omega**2 / (np.pi**0.5 * pome**3) * np.exp(-omega**2 / pome**2) for m in range(-N, N + 1): print('m=', m) alpha = -spf.jvp(m, k * a) / spf.yvp(m, k * a) beta = (spf.jv(m, k * rs) + alpha * spf.yv(m, k * rs)) / spf.hankel2( m, k * rs) c1 = (spf.jvp(m, k * rs) + alpha * spf.yvp(m, k * rs) - beta * spf.h2vp(m, k * rs))**(-1) / (k * mu * 2 * np.pi * rs) * R c2 = alpha * c1 c3 = beta * c1 if r < a: disp_m = 0 elif r >= a and r < rs: disp_m = c1 * spf.jv(m, k * r) + c2 * spf.yv(m, k * r) elif rs <= r: disp_m = c3 * spf.hankel2(m, k * r) disp_m = np.append(disp_m, np.conj(disp_m[::-1][0:-1])) disp_t = np.fft.ifft(disp_m) * np.exp(epsilon * T)
a, b = opt.radi pr = np.linspace(10, 50, 1000) m = 5 n = 10 print(jn_zeros(m, n)[-1]) print(jnp_zeros(m, n)[-1]) print(yn_zeros(m, n)[-1]) print(ynp_zeros(m, n)[-1]) x0_mn_1 = jn_zeros(m, 5)[-1] x1_mn_1 = jnp_zeros(m, 5)[-1] x0_mn_2 = jn_zeros(m, 7)[-1] x1_mn_2 = jnp_zeros(m, 7)[-1] d_1 = jvp(m, pr, 0) * yvp(m, x1_mn_1, 1) - \ yvp(m, pr, 0) * jvp(m, x1_mn_1, 1) d_2 = jvp(m, pr, 0) * yvp(m, x1_mn_2, 1) - \ yvp(m, pr, 0) * jvp(m, x1_mn_2, 1) plt.figure() plt.plot(pr, d_1) plt.plot(pr, d_2) plt.grid() plt.figure() plt.plot(pr, jvp(m, pr, 0) * yvp(m, x1_mn_1, 1)) plt.plot(pr, jvp(m, pr, 0) * yvp(m, x1_mn_2, 1)) plt.grid() plt.figure()
def z(self,x): 'Z(x) equation that keeps showing up in waveguide modes' m, n, chi = self.m, self.n, self.root return yvp(m,chi,1)*jn(m,x)-jvp(m,chi,1)*yn(m,x)
X = R*np.cos(Th) Y = R*np.sin(Th) U = np.zeros(np.shape(X)) sig1 = (R>=a)*(R<rs) sig2 = (R>=rs) U = np.zeros(np.shape(X)) mlist = list(range(-N,N+1)) k = omega/bbeta for m in mlist: print('m=',m) alpha = -spf.jvp(m,k*a)/spf.yvp(m,k*a) beta = (spf.jn(m,k*rs)+alpha*spf.yn(m,k*rs))/spf.hankel2(m,k*rs) c1 = (spf.jvp(m,k*rs)+alpha*spf.yvp(m,k*rs)-beta*spf.h2vp(m,k*rs))**(-1)/(k*mu*2*np.pi*rs) c2 = alpha*c1 c3 = beta*c1 disp1_m = c1*spf.jn(m,k*R)+c2*spf.yn(m,k*R) disp2_m = c3*spf.hankel2(m,k*R) disp_m = disp1_m*sig1.astype(int)+disp2_m*sig2.astype(int) U = U + disp_m*np.exp(1j*m*Th) # alpha = -spf.h1vp(m,k*a)/spf.h2vp(m,k*a) # beta = (spf.hankel1(m,k*rs)+alpha*spf.hankel2(m,k*rs))/spf.hankel2(m,k*rs) # c1 = (spf.h1vp(m,k*rs)+alpha*spf.h2vp(m,k*rs)-beta*spf.h2vp(m,k*rs))**(-1)/(k*mu*2*np.pi*rs)
def z_dash(self,x): ''' Z'(x) equation for waveguide mode ''' m, n, chi = self.m, self.n, self.root # jvp(m,x,r) is the rth derivative of the bessel function of order m evaluated at x return yn(m,chi)*jvp(m,x,1)-jn(m,chi)*yvp(m,x,1)
def root_equation(self,m,c,x): '''Radial root equation of Phi for TE mode''' return yvp(m,x,1)*jvp(m,c*x,1)-jvp(m,x,1)*yvp(m,c*x,1)
def doTest(): print(colored('Testing Special Module', 'magenta')) print(colored('Testing airy_ai scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.airy_ai_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.airy(value)[0].item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_ai array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.airy_ai_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.airy(data)[0], NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_ai_prime scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.airy_ai_prime_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.airy(value)[1].item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_ai_prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.airy_ai_prime_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.airy(data)[1], NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_bi scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.airy_bi_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.airy(value)[2].item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_bi array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.airy_bi_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.airy(data)[2], NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_bi_prime scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.airy_bi_prime_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.airy(value)[3].item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing airy_bi_prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.airy_bi_prime_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.airy(data)[3], NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bernoulli scaler', 'cyan')) value = np.random.randint(0, 20) if (roundScaler(NumCpp.bernoulli_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.bernoulli(value)[-1], NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_in scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_in_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.iv(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_in array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 10) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_in_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.iv(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_in_prime scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_in_prime_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.ivp(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_in_prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 10) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_in_prime_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.ivp(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_jn scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_jn_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.jv(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_jn array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 10) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_jn_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.jv(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_jn_prime scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_jn_prime_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.jvp(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_jn_prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 10) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_jn_prime_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.jvp(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_kn scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_kn_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.kn(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_kn array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 5) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_kn_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.kn(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_kn_prime scaler', 'cyan')) order = np.random.randint(0, 5) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_kn_prime_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.kvp(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_kn_prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 5) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_kn_prime_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.kvp(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_yn scaler', 'cyan')) order = np.random.randint(0, 5) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_yn_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.yn(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_yn array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 5) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_yn_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.yn(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_yn_prime scaler', 'cyan')) order = np.random.randint(0, 5) value = np.random.rand(1).item() if (roundScaler(NumCpp.bessel_yn_prime_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.yvp(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing bessel_yn_prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 5) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.bessel_yn_prime_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.yvp(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing beta scaler', 'cyan')) a = np.random.rand(1).item() * 10 b = np.random.rand(1).item() * 10 if (roundScaler(NumCpp.beta_Scaler(a, b), NUM_DECIMALS_ROUND) == roundScaler( sp.beta(a, b).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing beta array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) aArray = NumCpp.NdArray(shape) bArray = NumCpp.NdArray(shape) a = np.random.rand(shape.rows, shape.cols) * 10 b = np.random.rand(shape.rows, shape.cols) * 10 aArray.setArray(a) bArray.setArray(b) if np.array_equal( roundArray(NumCpp.beta_Array(aArray, bArray), NUM_DECIMALS_ROUND), roundArray(sp.beta(a, b), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing cnr', 'cyan')) n = np.random.randint(0, 50) r = np.random.randint(0, n + 1) if round(NumCpp.cnr(n, r)) == round(sp.comb(n, r)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing cyclic_hankel_1', 'cyan')) order = np.random.randint(0, 6) value = np.random.rand(1).item() * 10 if (roundComplex(complex(NumCpp.cyclic_hankel_1(order, value)), NUM_DECIMALS_ROUND) == roundComplex( sp.hankel1(order, value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing cyclic_hankel_2', 'cyan')) order = np.random.randint(0, 6) value = np.random.rand(1).item() * 10 if (roundComplex(complex(NumCpp.cyclic_hankel_2(order, value)), NUM_DECIMALS_ROUND) == roundComplex( sp.hankel2(order, value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing digamma scaler', 'cyan')) value = np.random.rand(1).item() * 10 if (roundScaler(NumCpp.digamma_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.digamma(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing digamma array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) * 10 cArray.setArray(data) if np.array_equal( roundArray(NumCpp.digamma_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.digamma(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erf scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.erf_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.erf(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erf array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal(roundArray(NumCpp.erf_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.erf(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erf_inv scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.erf_inv_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.erfinv(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erf_inv array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.erf_inv_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.erfinv(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erfc scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.erfc_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.erfc(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erfc array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.erfc_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.erfc(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erfc_inv scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.erfc_inv_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.erfcinv(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing erfc_inv array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.erfc_inv_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.erfcinv(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing factorial scaler', 'cyan')) n = np.random.randint(0, 170) if (roundScaler(NumCpp.factorial_Scaler(n), NUM_DECIMALS_ROUND) == roundScaler( sp.factorial(n).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing factorial array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArrayUInt32(shape) data = np.random.randint(0, 170, [shape.rows, shape.cols]) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.factorial_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.factorial(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing gamma scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.gamma_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.gamma(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing gamma array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.gamma_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.gamma(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) # There is no scipy equivalent to this function print(colored('Testing gamma1pm1 scaler', 'cyan')) value = np.random.rand(1).item() answer = NumCpp.gamma1pm1_Scaler(value) print(colored('\tPASS', 'green')) print(colored('Testing gamma1pm1 array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) answer = NumCpp.gamma1pm1_Array(cArray) print(colored('\tPASS', 'green')) print(colored('Testing log_gamma scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.log_gamma_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler(sp.loggamma(value), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing log_gamma array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.log_gamma_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.loggamma(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing pnr', 'cyan')) n = np.random.randint(0, 10) r = np.random.randint(0, n + 1) if round(NumCpp.pnr(n, r)) == round(sp.perm(n, r)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing polygamma scaler', 'cyan')) order = np.random.randint(1, 5) value = np.random.rand(1).item() if (roundScaler(NumCpp.polygamma_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.polygamma(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing polygamma array', 'cyan')) order = np.random.randint(1, 5) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.polygamma_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.polygamma(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) # There is no scipy equivalent to this function print(colored('Testing prime scaler', 'cyan')) value = np.random.randint(10000) answer = NumCpp.prime_Scaler(value) print(colored('\tPASS', 'green')) print(colored('Testing prime array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArrayUInt32(shape) data = np.random.randint(0, 10000, [shape.rows, shape.cols]) cArray.setArray(data) answer = NumCpp.prime_Array(cArray) print(colored('\tPASS', 'green')) print(colored('Testing riemann_zeta scaler', 'cyan')) value = np.random.rand(1).item() * 5 + 1 if (roundScaler(NumCpp.riemann_zeta_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.zeta(value, 1).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing riemann_zeta array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) * 5 + 1 cArray.setArray(data) if np.array_equal( roundArray(NumCpp.riemann_zeta_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.zeta(data, 1), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing softmax Axis::None', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.softmax(cArray, NumCpp.Axis.NONE), NUM_DECIMALS_ROUND), roundArray(sp.softmax(data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing spherical_bessel_jn scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.spherical_bessel_jn_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.spherical_jn(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing spherical_bessel_jn array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 10) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.spherical_bessel_jn_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.spherical_jn(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing spherical_bessel_yn scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() if (roundScaler(NumCpp.spherical_bessel_yn_Scaler(order, value), NUM_DECIMALS_ROUND) == roundScaler( sp.spherical_yn(order, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing spherical_bessel_yn array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) order = np.random.randint(0, 10) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.spherical_bessel_yn_Array(order, cArray), NUM_DECIMALS_ROUND), roundArray(sp.spherical_yn(order, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) # There is no equivalent scipy functions print(colored('Testing spherical_hankel_1 scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() result = NumCpp.spherical_hankel_1(order, value) print(colored('\tPASS', 'green')) print(colored('Testing spherical_hankel_2 scaler', 'cyan')) order = np.random.randint(0, 10) value = np.random.rand(1).item() result = NumCpp.spherical_hankel_2(order, value) print(colored('\tPASS', 'green')) print(colored('Testing trigamma scaler', 'cyan')) value = np.random.rand(1).item() if (roundScaler(NumCpp.trigamma_Scaler(value), NUM_DECIMALS_ROUND) == roundScaler( sp.polygamma(1, value).item(), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red')) print(colored('Testing trigamma array', 'cyan')) shapeInput = np.random.randint(20, 100, [ 2, ]) shape = NumCpp.Shape(shapeInput[0].item(), shapeInput[1].item()) cArray = NumCpp.NdArray(shape) data = np.random.rand(shape.rows, shape.cols) cArray.setArray(data) if np.array_equal( roundArray(NumCpp.trigamma_Array(cArray), NUM_DECIMALS_ROUND), roundArray(sp.polygamma(1, data), NUM_DECIMALS_ROUND)): print(colored('\tPASS', 'green')) else: print(colored('\tFAIL', 'red'))
i_a0 = np.where(R[0] >= a0)[0][0] i_a1 = np.where(R[0] >= a1)[0][0] i_rs = np.where(R[0] >= rs)[0][0] U = np.zeros(np.shape(X)) disp_m = np.zeros(np.shape(U)) mlist = list(range(-N, N + 1)) k0 = omega / bbeta0 k1 = omega / bbeta1 for m in range(-N, N + 1): print('m=', m) A = np.array([[spf.jvp(m, k0 * a0), spf.yvp(m, k0 * a0), 0, 0, 0], [ spf.jn(m, k0 * a1), spf.yn(m, k0 * a1), -spf.jn(m, k1 * a1), -spf.yn(m, k1 * a1), 0 ], [ spf.jvp(m, k0 * a1), spf.yvp(m, k0 * a1), -mu1 / mu0 * bbeta0 / bbeta1 * spf.jvp(m, k1 * a1), -mu1 / mu0 * bbeta0 / bbeta1 * spf.yvp(m, k1 * a1), 0 ], [ 0, 0, spf.jn(m, k1 * rs), spf.yn(m, k1 * rs), -spf.hankel2(m, k1 * rs)
a, b = opt.radi pr = np.linspace(10, 50, 1000) m = 5 n = 10 print(jn_zeros(m, n)[-1]) print(jnp_zeros(m, n)[-1]) print(yn_zeros(m, n)[-1]) print(ynp_zeros(m, n)[-1]) x0_mn_1 = jn_zeros(m, 5)[-1] x1_mn_1 = jnp_zeros(m, 5)[-1] x0_mn_2 = jn_zeros(m, 7)[-1] x1_mn_2 = jnp_zeros(m, 7)[-1] d_1 = jvp(m, pr, 0) * yvp(m, x1_mn_1, 1) - \ yvp(m, pr, 0) * jvp(m, x1_mn_1, 1) d_2 = jvp(m, pr, 0) * yvp(m, x1_mn_2, 1) - \ yvp(m, pr, 0) * jvp(m, x1_mn_2, 1) obj = plot2d(aspect="auto") obj.axs.plot(pr, d_1) obj.axs.plot(pr, d_2) obj.SavePng_Serial() obj.new_2Dfig(aspect="auto") obj.axs.plot(pr, jvp(m, pr, 0) * yvp(m, x1_mn_1, 1)) obj.axs.plot(pr, jvp(m, pr, 0) * yvp(m, x1_mn_2, 1)) obj.SavePng_Serial() obj.new_2Dfig(aspect="auto")
def coeq(v0, nu, fiber): r1, r2 = fiber.rho n1, n2, n3 = fiber.n na = sqrt(max(fiber.n)**2 - n3**2) K0 = v0 / (na * r2) beta = K0 * n3 if n1 > n3: u1 = K0**2 * (n1**2 - n3**2) s1 = 1 else: u1 = K0**2 * (n3**2 - n1**2) s1 = -1 if n2 > n3: u2 = K0**2 * (n2**2 - n3**2) s2 = 1 else: u2 = K0**2 * (n3**2 - n2**2) s2 = -1 s = -s1 * s2 u1r1 = u1 * r1 u2r1 = u2 * r1 u2r2 = u2 * r2 X = (u2r1**2 + s * u1r1**2) * nu * beta if s1 == 1: Y = jvp(nu, u1r1) / jn(nu, u1r1) else: Y = ivp(nu, u1r1) / iv(nu, u1r1) ju2r1 = jn(nu, u2r1) if s2 == 1 else iv(nu, u2r1) nu2r1 = yn(nu, u2r1) if s2 == 1 else kn(nu, u2r1) jpu2r1 = jvp(nu, u2r1) if s2 == 1 else ivp(nu, u2r1) npu2r1 = yvp(nu, u2r1) if s2 == 1 else kvp(nu, u2r1) ju2r2 = jn(nu, u2r2) if s2 == 1 else iv(nu, u2r2) nu2r2 = yn(nu, u2r2) if s2 == 1 else kn(nu, u2r2) j1u2r2 = jn(nu + 1, u2r2) n1u2r2 = yn(nu + 1, u2r2) M = numpy.empty((4, 4)) M[0, 0] = X * ju2r1 M[0, 1] = X * nu2r1 M[0, 2] = -K0 * (jpu2r1 * u1r1 + s * Y * ju2r1 * u2r1) * u1r1 * u2r1 M[0, 3] = -K0 * (npu2r1 * u1r1 + s * Y * nu2r1 * u2r1) * u1r1 * u2r1 M[1, 0] = -K0 * (n2**2 * jpu2r1 * u1r1 + s * n1**2 * Y * ju2r1 * u2r1) * u1r1 * u2r1 M[1, 1] = -K0 * (n2**2 * npu2r1 * u1r1 + s * n1**2 * Y * nu2r1 * u2r1) * u1r1 * u2r1 M[1, 2] = X * ju2r1 M[1, 3] = X * nu2r1 D201 = nu * n3 / u2r2 * (j1u2r2 * nu2r2 - ju2r2 * yn(nu + 1, u2r2)) D202 = -( (n2**2 + n3**2) * nu * n1u2r2 * nu2r2 / u2r2 + n3**2 * nu * nu2r2**2 / (nu - 1)) D203 = -(n2**2 * nu * ju2r2 * n1u2r2 / u2r2 + n3**2 * nu * nu2r2 * j1u2r2 / u2r2 + n3**2 * nu * (j1u2r2 * nu2r2 + n1u2r2 * ju2r2) / (2 * (nu - 1))) D212 = -(n2**2 * nu * nu2r2 * j1u2r2 / u2r2 + n3**2 * nu * ju2r2 * n1u2r2 / u2r2 + n3**2 * nu * (n1u2r2 * ju2r2 + j1u2r2 * nu2r2) / (2 * (nu - 1))) D213 = -( (n2**2 + n3**2) * nu * j1u2r2 * ju2r2 / u2r2 + n3**2 * nu * ju2r2**2 / (nu - 1)) D223 = nu * n2**2 * n3 / u2r2 * (j1u2r2 * nu2r2 - ju2r2 * n1u2r2) D30 = M[1, 1] * D201 - M[1, 2] * D202 + M[1, 3] * D203 D31 = M[1, 0] * D201 - M[1, 2] * D212 + M[1, 3] * D213 D32 = M[1, 0] * D202 - M[1, 1] * D212 + M[1, 3] * D223 D33 = M[1, 0] * D203 - M[1, 1] * D213 + M[1, 2] * D223 return M[0, 0] * D30 - M[0, 1] * D31 + M[0, 2] * D32 - M[0, 3] * D33
def coeq(v0, nu, fiber): r1, r2 = fiber.rho n1, n2, n3 = fiber.n na = sqrt(max(fiber.n)**2 - n3**2) K0 = v0 / (na * r2) beta = K0 * n3 if n1 > n3: u1 = K0**2 * (n1**2 - n3**2) s1 = 1 else: u1 = K0**2 * (n3**2 - n1**2) s1 = -1 if n2 > n3: u2 = K0**2 * (n2**2 - n3**2) s2 = 1 else: u2 = K0**2 * (n3**2 - n2**2) s2 = -1 s = -s1 * s2 u1r1 = u1 * r1 u2r1 = u2 * r1 u2r2 = u2 * r2 X = (u2r1**2 + s * u1r1**2) * nu * beta if s1 == 1: Y = jvp(nu, u1r1) / jn(nu, u1r1) else: Y = ivp(nu, u1r1) / iv(nu, u1r1) ju2r1 = jn(nu, u2r1) if s2 == 1 else iv(nu, u2r1) nu2r1 = yn(nu, u2r1) if s2 == 1 else kn(nu, u2r1) jpu2r1 = jvp(nu, u2r1) if s2 == 1 else ivp(nu, u2r1) npu2r1 = yvp(nu, u2r1) if s2 == 1 else kvp(nu, u2r1) ju2r2 = jn(nu, u2r2) if s2 == 1 else iv(nu, u2r2) nu2r2 = yn(nu, u2r2) if s2 == 1 else kn(nu, u2r2) j1u2r2 = jn(nu+1, u2r2) n1u2r2 = yn(nu+1, u2r2) M = numpy.empty((4, 4)) M[0, 0] = X * ju2r1 M[0, 1] = X * nu2r1 M[0, 2] = -K0 * (jpu2r1 * u1r1 + s * Y * ju2r1 * u2r1) * u1r1 * u2r1 M[0, 3] = -K0 * (npu2r1 * u1r1 + s * Y * nu2r1 * u2r1) * u1r1 * u2r1 M[1, 0] = -K0 * (n2**2 * jpu2r1 * u1r1 + s * n1**2 * Y * ju2r1 * u2r1) * u1r1 * u2r1 M[1, 1] = -K0 * (n2**2 * npu2r1 * u1r1 + s * n1**2 * Y * nu2r1 * u2r1) * u1r1 * u2r1 M[1, 2] = X * ju2r1 M[1, 3] = X * nu2r1 D201 = nu * n3 / u2r2 * (j1u2r2 * nu2r2 - ju2r2 * yn(nu+1, u2r2)) D202 = -((n2**2 + n3**2) * nu * n1u2r2 * nu2r2 / u2r2 + n3**2 * nu * nu2r2**2 / (nu - 1)) D203 = -(n2**2 * nu * ju2r2 * n1u2r2 / u2r2 + n3**2 * nu * nu2r2 * j1u2r2 / u2r2 + n3**2 * nu * (j1u2r2 * nu2r2 + n1u2r2 * ju2r2) / (2 * (nu - 1))) D212 = -(n2**2 * nu * nu2r2 * j1u2r2 / u2r2 + n3**2 * nu * ju2r2 * n1u2r2 / u2r2 + n3**2 * nu * (n1u2r2 * ju2r2 + j1u2r2 * nu2r2) / (2 * (nu - 1))) D213 = -((n2**2 + n3**2) * nu * j1u2r2 * ju2r2 / u2r2 + n3**2 * nu * ju2r2**2 / (nu - 1)) D223 = nu * n2**2 * n3 / u2r2 * (j1u2r2 * nu2r2 - ju2r2 * n1u2r2) D30 = M[1, 1] * D201 - M[1, 2] * D202 + M[1, 3] * D203 D31 = M[1, 0] * D201 - M[1, 2] * D212 + M[1, 3] * D213 D32 = M[1, 0] * D202 - M[1, 1] * D212 + M[1, 3] * D223 D33 = M[1, 0] * D203 - M[1, 1] * D213 + M[1, 2] * D223 return M[0, 0] * D30 - M[0, 1] * D31 + M[0, 2] * D32 - M[0, 3] * D33