Beispiel #1
0
 def Cyz(self):
     
    
     sum=np.sum(( iv(self.n,self.l) - ivp(self.n,self.l) )*( self.zeta(self.n)*self.Z(self.n) + self.zeta(-self.n)*self.Z(-self.n) ))
 
     firstTerm = ( iv(0,self.l) - ivp(0,self.l) )*( self.zeta(0)*self.Z(0) + self.zeta(0)*self.Z(0) )
     return -self.Byz()*(sum + 0.5*firstTerm )
Beispiel #2
0
    def dKyy_du(self, u):

        sum = np.sum(
            self.dlam_du(u) *
            (self.n**2 * ivp(self.n, self.l) + 4 * self.l *
             (iv(self.n, self.l) - ivp(self.n, self.l)) + 2 * self.l**2 *
             (ivp(self.n, self.l) - ivp(self.n, self.l, 2))) *
            (self.Z(self.n) + self.Z(-self.n)) +
            (self.dzetan_du(u, self.n) * self.Zp(self.n) +
             self.dzetan_du(u, -self.n) * self.Zp(-self.n)) *
            (self.n**2 * iv(self.n, self.l) + 2 * self.l**2 *
             (iv(self.n, self.l) - ivp(self.n, self.l))))

        nn = 0
        firstTerm = self.dlam_du(u) * (
            nn**2 * ivp(nn, self.l) + 4 * self.l *
            (iv(nn, self.l) - ivp(nn, self.l)) + 2 * self.l**2 *
            (ivp(nn, self.l) - ivp(nn, self.l, 2))) * (
                self.Z(nn) + self.Z(-nn)
            ) + (self.dzetan_du(u, nn) * self.Zp(nn) + self.dzetan_du(u, -nn) *
                 self.Zp(-nn)) * (nn**2 * iv(nn, self.l) + 2 * self.l**2 *
                                  (iv(nn, self.l) - ivp(nn, self.l)))

        return self.pdByy_du(u) * (self.Kyy() -
                                   1) + self.Byy() * (sum + 0.5 * firstTerm)
Beispiel #3
0
def det_M1(η, m):
    c = η + 1 / η
    return lambda z: (
        sp.ivp(m, η * z, 2) * sp.hankel1(m, z)
        + c * sp.ivp(m, η * z) * sp.h1vp(m, z)
        + sp.iv(m, η * z) * sp.h1vp(m, z, 2)
    )
def rootsAnnSec(m, rMin, rMax, aMin, aMax):
    f0 = lambda k: ivp(m, η * k) * hankel1(m, k) / η + iv(m, η * k) * h1vp(
        m, k)
    f1 = (lambda k: ivp(m, η * k, 2) * hankel1(m, k) + c * ivp(m, η * k) *
          h1vp(m, k) + iv(m, η * k) * h1vp(m, k, 2))

    A = AnnulusSector(center=0.0, radii=(rMin, rMax), phiRange=(aMin, aMax))
    z = A.roots(f0, df=f1)
    return z.roots
Beispiel #5
0
    def dCxy_du(self, u):
        sum = np.sum(self.n *
                     (self.dlam_du(u) *
                      (ivp(self.n, self.l, 1) - ivp(self.n, self.l, 2)) *
                      (self.Z(self.n) - self.Z(-self.n)) +
                      (self.dzetan_du(u, self.n) * self.Zp(self.n) -
                       self.dzetan_du(u, -self.n) * self.Zp(-self.n)) *
                      (iv(self.n, self.l) - ivp(self.n, self.l))))

        return self.pdBxy_du(u) * self.Cxy() - self.Bxy() * sum
Beispiel #6
0
    def dKzz_du(self, u):



        sum= np.sum(self.dlam_du(u) * ivp(self.n,self.l)*( self.zeta(self.n)*self.Zp(self.n)+self.zeta(-self.n)*self.Zp(-self.n))\
                + iv(self.n,self.l)*( self.dzetan_du(u,self.n)*(self.Zp(self.n)+self.zeta(self.n)*self.Zpp(self.n)) + self.dzetan_du(u,-self.n)*( self.Zp(-self.n)+self.zeta(-self.n)*self.Zpp(-self.n) )  ))

        nn = 0
        firstTerm = self.dlam_du(u) * ivp(nn,self.l)*( self.zeta(nn)*self.Zp(nn)+self.zeta(-nn)*self.Zp(-nn))\
                + iv(nn,self.l)*( self.dzetan_du(u,nn)*(self.Zp(nn)+self.zeta(nn)*self.Zpp(nn)) + self.dzetan_du(u,-nn)*( self.Zp(-nn)+self.zeta(-nn)*self.Zpp(-nn) ) )

        return self.pdBzz_du(u) * (self.Kzz() -
                                   1) - self.Bzz() * (sum + 0.5 * firstTerm)
Beispiel #7
0
def test_cylindrical_bessel_i_prime():
    order = np.random.randint(0, 10)
    value = np.random.rand(1).item()
    assert (roundScaler(NumCpp.bessel_in_prime_Scaler(order, value), NUM_DECIMALS_ROUND) ==
            roundScaler(sp.ivp(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, 10)
    data = np.random.rand(shape.rows, shape.cols)
    cArray.setArray(data)
    assert np.array_equal(roundArray(NumCpp.bessel_in_prime_Array(order, cArray), NUM_DECIMALS_ROUND),
                          roundArray(sp.ivp(order, data), NUM_DECIMALS_ROUND))
Beispiel #8
0
 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
Beispiel #9
0
 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
Beispiel #10
0
    def prime(self, r):

        w = self.w(r)

        return (self.V_WCA_prime(r) - 2 * self.l0 *
                spec.ivp(0, self.l0 * w * r) / spec.i0(self.l0 * w * r) *
                (w + r * self.w_prime(r)))
Beispiel #11
0
    def mag_field_function2(a, b, z, cart=False):
        '''give r,phi,z, (or x,y,z) and return br,bphi,bz (or bx,by,bz)'''
        if cart:
            r = np.sqrt(a**2 + b**2)
            phi = np.arctan2(b, a)
        else:
            r = a
            phi = b

        iv = np.empty((ns, ms))
        ivp = np.empty((ns, ms))
        for n in range(ns):
            iv[n, :] = special.iv(n, kms[n, :] * np.abs(r))
            ivp[n, :] = special.ivp(n, kms[n, :] * np.abs(r))

        br = 0.0
        bphi = 0.0
        bz = 0.0
        for n in range(ns):
            for m in range(ms):
                br += np.cos(n*phi-Ds[n])*ivp[n][m]*kms[n][m]*\
                        (As[n][m]*np.cos(kms[n][m]*z) + Bs[n][m]*np.sin(kms[n][m]*z))
                bz += np.cos(n*phi-Ds[n])*iv[n][m]*kms[n][m]*\
                        (-As[n][m]*np.sin(kms[n][m]*z) + Bs[n][m]*np.cos(kms[n][m]*z))
                if abs(r) > 1e-10:
                    bphi += n*(-np.sin(n*phi-Ds[n]))*\
                            (1/abs(r))*iv[n][m]*(As[n][m]*np.cos(kms[n][m]*z) + Bs[n][m]*np.sin(kms[n][m]*z))

        if cart:
            bx = br * np.cos(phi) - bphi * np.sin(phi)
            by = br * np.sin(phi) + bphi * np.cos(phi)
            return (bx, by, bz)
        else:
            return (br, bphi, bz)
Beispiel #12
0
    def k_2(self, dumk1):

        temp = -1 / (3 * np.sqrt(self.Pi))

        temp -= dumk1 * special.ivp(1, np.sqrt(self.Pi) * self.r0, 1)

        return temp / special.kvp(1, np.sqrt(self.Pi) * self.r0, 1)
Beispiel #13
0
def coeff_w_m(η, m, k):
    M = np.array(
        [[sp.iv(m, η * k), -sp.hankel1(m, k)], [sp.ivp(m, η * k) / η, sp.h1vp(m, k)]]
    )
    V = np.array([[sp.jv(m, k)], [-sp.jvp(m, k)]])
    S = np.linalg.solve(M, V)
    return (S[0, 0], S[1, 0])
Beispiel #14
0
    def __delta(self, nu, u1r1, u2r1, s1, s2, s3, n1sq, n2sq, n3sq):
        """s3 is sign of Delta"""
        if s1 < 0:
            f = ivp(nu, u1r1) / (iv(nu, u1r1) * u1r1)  # c
        else:
            jnnuu1r1 = jn(nu, u1r1)
            if jnnuu1r1 == 0:  # Avoid zero division error
                return float("inf")
            f = jvp(nu, u1r1) / (jnnuu1r1 * u1r1)  # a b d

        if s1 == s2:
            # b d
            kappa1 = -(n1sq + n2sq) * f / n2sq
            kappa2 = (n1sq * f * f / n2sq -
                      nu**2 * n3sq / n2sq * (1 / u1r1**2 - 1 / u2r1**2)**2)
        else:
            # a c
            kappa1 = (n1sq + n2sq) * f / n2sq
            kappa2 = (n1sq * f * f / n2sq -
                      nu**2 * n3sq / n2sq * (1 / u1r1**2 + 1 / u2r1**2)**2)

        d = kappa1**2 - 4 * kappa2
        if d < 0:
            return numpy.nan
        return u2r1 * (nu / u2r1**2 + (kappa1 + s3 * sqrt(d)) * 0.5)
Beispiel #15
0
    def mag_field_function(a, b, z, cart=False):
        '''give r,phi,z, (or x,y,z) and return br,bphi,bz (or bx,by,bz)'''
        if cart:
            r = np.sqrt(a**2 + b**2)
            phi = np.arctan2(b, a)
        else:
            r = a
            phi = b

        # print(r,phi,z)

        cms1 = np.zeros(ms)
        iv = np.zeros((ms, ns))
        ivp = np.zeros((ms, ns))

        for m in range(ms):
            cms1[m] = ((m + 1) * np.pi / L1)
            for n in range(ns):
                iv[m][n] = special.iv(n, cms1[m] * r)
                ivp[m][n] = special.ivp(n, cms1[m] * r)

        # print(iv)
        # print(ivp)

        # iv = np.empty((ns,ms))
        # ivp = np.empty((ns,ms))
        # for n in range(ns):
        #     iv[n,:] = special.iv(n,kms[n,:]*np.abs(r))
        #     ivp[n,:] = special.ivp(n,kms[n,:]*np.abs(r))

        br = 0.0
        bphi = 0.0
        bz = 0.0

        for n in range(ns):
            for m in range(ms):
                # km = (m+1)*np.pi / L1
                br += (Ds[n]*np.sin(n*phi) + (1-Ds[n])*np.cos(n*phi)) * \
                        ivp[m][n]*cms1[m]*(As[m][n]*np.cos(cms1[m]*z) + Bs[m][n]*np.sin(cms1[m]*z))
                if abs(r) > 1e-10:
                    bphi += n*(Ds[n]*np.cos(n*phi) - (1-Ds[n])*np.sin(n*phi)) * \
                            (1/r)*iv[m][n]*(As[m][n]*np.cos(cms1[m]*z) + Bs[m][n]*np.sin(cms1[m]*z))
                bz += (Ds[n]*np.sin(n*phi) + (1-Ds[n])*np.cos(n*phi)) * \
                        iv[m][n]*cms1[m]*(-As[m][n]*np.sin(cms1[m]*z) + Bs[m][n]*np.cos(cms1[m]*z))

        bz += k3

        # for n in range(ns):
        #     for m in range(ms):
        #         br += (Cs[n]*np.cos(n*phi)+Ds[n]*np.sin(n*phi))*ivp[n][m]*kms[n][m]*(As[n][m]*np.cos(kms[n][m]*z) + Bs[n][m]*np.sin(-kms[n][m]*z))
        #         if abs(r)>1e-10:
        #             bphi += n*(-Cs[n]*np.sin(n*phi)+Ds[n]*np.cos(n*phi))*(1/abs(r))*iv[n][m]*(As[n][m]*np.cos(kms[n][m]*z) + Bs[n][m]*np.sin(-kms[n][m]*z))
        #         bz += -(Cs[n]*np.cos(n*phi)+Ds[n]*np.sin(n*phi))*iv[n][m]*kms[n][m]*(As[n][m]*np.sin(kms[n][m]*z) + Bs[n][m]*np.cos(-kms[n][m]*z))

        if cart:
            bx = br * np.cos(phi) - bphi * np.sin(phi)
            by = br * np.sin(phi) + bphi * np.cos(phi)
            return (bx, by, bz)
        else:
            return (br, bphi, bz)
Beispiel #16
0
    def mag_field_function(a,b,z,cart=False):
        '''give r,phi,z, (or x,y,z) and return br,bphi,bz (or bx,by,bz)'''
        if cart:
            r = np.sqrt(a**2+b**2)
            phi = np.arctan2(b,a)
        else:
            r = a
            phi = b

        iv = np.empty((ns,ms))
        ivp = np.empty((ns,ms))
        for n in range(ns):
            iv[n,:] = special.iv(n,kms[n,:]*np.abs(r))
            ivp[n,:] = special.ivp(n,kms[n,:]*np.abs(r))

        br = 0.0
        bphi = 0.0
        bz = 0.0
        for n in range(ns):
            for m in range(ms):
                br += (Cs[n]*np.cos(n*phi)+Ds[n]*np.sin(n*phi))*ivp[n][m]*kms[n][m]*(As[n][m]*np.cos(kms[n][m]*z) + Bs[n][m]*np.sin(-kms[n][m]*z))
                if abs(r)>1e-10:
                    bphi += n*(-Cs[n]*np.sin(n*phi)+Ds[n]*np.cos(n*phi))*(1/abs(r))*iv[n][m]*(As[n][m]*np.cos(kms[n][m]*z) + Bs[n][m]*np.sin(-kms[n][m]*z))
                bz += -(Cs[n]*np.cos(n*phi)+Ds[n]*np.sin(n*phi))*iv[n][m]*kms[n][m]*(As[n][m]*np.sin(kms[n][m]*z) + Bs[n][m]*np.cos(-kms[n][m]*z))

        if cart:
            bx = br*np.cos(phi)-bphi*np.sin(phi)
            by = br*np.sin(phi)+bphi*np.cos(phi)
            return (bx,by,bz)
        else:
            return (br,bphi,bz)
Beispiel #17
0
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)
Beispiel #18
0
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)
Beispiel #19
0
    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))
Beispiel #20
0
    def dKxx_du(self, u):

        sum = np.sum(self.n**2 *
                     (self.dlam_du(u) * ivp(self.n, self.l) *
                      (self.Z(self.n) + self.Z(-self.n)) + iv(self.n, self.l) *
                      (self.dzetan_du(u, self.n) * self.Zp(self.n) +
                       self.dzetan_du(u, -self.n) * self.Zp(-self.n))))
        return self.pdBxx_du(u) * (self.Kxx() - 1) + self.Bxx() * sum
Beispiel #21
0
 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]))
Beispiel #22
0
def main():
    l=np.arange(0.0, 4.0, 0.1)
    for m in range(5):
        plt.plot(l, ivp(m, l), label = 'm={}'.format(m))
    plt.title('Derivative of modified Bessel function of order $m$ (even w. $m$)')
    plt.xlabel('$\lambda$')
    plt.ylabel('$I_m^{\prime}(\lambda$)')
    plt.legend(loc = 'upper left')
    plt.savefig('Imprime.pdf')
Beispiel #23
0
 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]))
Beispiel #24
0
    def dCxz_du(self, u):

        sum = np.sum(
            self.n *
            (self.dlam_du(u) * ivp(self.n, self.l, 1) *
             (-self.Zp(self.n) + self.Zp(-self.n)) + iv(self.n, self.l) *
             (-self.dzetan_du(u, self.n) * self.Zpp(self.n) +
              self.dzetan_du(u, -self.n) * self.Zpp(-self.n))) / 2)

        return self.pdBxz_du(u) * self.Cxz() - self.Bxz() * sum
def calcInt():
    plaTrue = ε > -1.0

    if plaTrue:
        Int = open(f"eps_{ε}_int", "w")
        Pla = open(f"eps_{ε}_pla", "w")
    else:
        Int = open(f"eps_{ε}_int", "w")

    for m in range(65):
        print(f"m = {m}")

        f0 = lambda k: ivp(m, η * k) * hankel1(m, k) / η + iv(m, η * k) * h1vp(
            m, k)
        f1 = (lambda k: ivp(m, η * k, 2) * hankel1(m, k) + c * ivp(m, η * k) *
              h1vp(m, k) + iv(m, η * k) * h1vp(m, k, 2))

        t = np.linspace(0.2, 65.0, num=1024)
        k = 1j * t
        rf = np.real(f0(k))

        ind = np.where(rf[1:] * rf[:-1] < 0.0)[0]
        roots = np.zeros(np.shape(ind), dtype=complex)
        for a, i in enumerate(ind):
            C = Circle(center=1j * (t[i] + t[i + 1]) / 2.0,
                       radius=(t[i + 1] - t[i]))
            z = C.roots(f0, df=f1)
            roots[a] = z.roots[0]

        if plaTrue:
            if m:
                writeFile(Int, m, roots[1:])
                writeFile(Pla, m, roots[[0]])
            else:
                writeFile(Int, m, roots)
        else:
            writeFile(Int, m, roots)

    if plaTrue:
        Int.close()
        Pla.close()
    else:
        Int.close()
Beispiel #26
0
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
Beispiel #27
0
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
Beispiel #28
0
    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
Beispiel #29
0
    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
Beispiel #30
0
    def w_minus_prime(self, r):

        if self.r0 == 1:

            return r * 0

        sPi = np.sqrt(self.Pi)

        return (sPi * special.ivp(1, sPi * r, 1) * self.nu_1(r) / r +
                special.i1(sPi * r) * self.nu_1_prime(r) / r +
                sPi * special.kvp(1, sPi * r, 1) * self.nu_2(r) / r +
                special.k1(sPi * r) * self.nu_2_prime(r) / r -
                self.w_minus(r) / r)
Beispiel #31
0
    def dCyz_du(self, u):


        sum=np.sum(self.dlam_du(u)*(ivp(self.n,self.l)-ivp(self.n,self.l,2))*(self.zeta(self.n)*self.Z(self.n)+self.zeta(-self.n)*self.Z(-self.n))\
               +(iv(self.n,self.l)-ivp(self.n,self.l))*(self.dzetan_du(u,self.n)*(self.Z(self.n)+self.zeta(self.n)*self.Zp(self.n)) + self.dzetan_du(u,-self.n)*(self.Z(-self.n)+self.zeta(-self.n)*self.Zp(-self.n))))
        nn = 0
        firstTerm = self.dlam_du(u)*(ivp(nn,self.l)-ivp(nn,self.l,2))*(self.zeta(nn)*self.Z(nn)+self.zeta(-nn)*self.Z(-nn))\
    +(iv(nn,self.l)-ivp(nn,self.l,1))*(self.dzetan_du(u,nn)*(self.Z(nn)+self.zeta(nn)*self.Zp(nn)) + self.dzetan_du(u,-nn)*(self.Z(-nn)+self.zeta(-nn)*self.Zp(-nn)))

        return self.pdByz_du(u) * self.Cyz() - self.Byz() * (sum +
                                                             0.5 * firstTerm)
Beispiel #32
0
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))
Beispiel #33
0
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 det_M_real_modes(Kz, Ω, modo, alfa):  #xz es en fracción de k0

    Kz_real = Kz[0]
    Kz_imag = Kz[1]
    if Kz_imag == 0:
        Kz = Kz_real
    else:
        Kz = Kz_real + 1j * Kz_imag

    V1_star = alfa * (-Ω**2 + Kz**2 + 1)**(1 / 2)
    V2_star = alfa * (-Ω**2 + Kz**2)**(1 / 2)

    X = V1_star * special.ivp(modo, V1_star) / special.iv(modo, V1_star)
    Y = V2_star * special.kvp(modo, V2_star) / special.kv(modo, V2_star)

    rta1 = (Ω**2 - 1) * (Ω**2 - Kz**2)**2 * X**2 + Ω**2 * (Ω**2 - Kz**2 -
                                                           1)**2 * Y**2
    rta2 = (2 * Ω**2 - 1) * (Ω**2 - Kz**2) * (Ω**2 - Kz**2 -
                                              1) * X * Y + modo**2 * Kz**2

    return rta1 - rta2
Beispiel #35
0
    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)
Beispiel #36
0
    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)
Beispiel #37
0
    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))
Beispiel #38
0
 def derI(n):
     return special.ivp(modo, xt(n) * ρ_barra)
Beispiel #39
0
    def EH_fields(self, ri, ro, nu, neff, wl, EH, tm=False):
        dr = 1e-10
        if ri == 0:
            # set initial condition
            ri = dr
            n = self.index(ri, wl)
            u = self.u(ri, neff, wl)
            if neff < n:
                ez = jn(nu, u)
                ezp = jvp(nu, u) * u / ri
            else:
                ez = iv(nu, u)
                ezp = ivp(nu, u) * u / ri
            hz = 0
            hzp = 0
            eza = 0
            ezap = 0
            hza = ez
            hzap = ezp
        elif nu == 0:
            ez, hz = EH
        else:
            ez, eza = EH[0]
            hz, hza = EH[1]
            # find derivatives...

        nu2 = nu * nu
        beta = wl.k0 * neff
        beta2 = beta * beta

        def f(r, y):
            """
            Bures (3.139)

            """
            assert r != 0
            r2 = r * r
            p = (wl.k0 * self.index(r, wl))**2 - beta2

            np = self.indexp(r, wl)
            n = self.index(r, wl)

            yp = numpy.empty(4)
            yp[0] = y[2]
            yp[1] = y[3]
            yp[2] = (y[0] * (nu2 / r2 - p) +
                     y[2] * (2 * beta2 / p * np / n - 1 / r) -
                     y[1] * constants.eta0 * (2 * nu * beta * wl.k0 * np /
                                              (r * p * n)))
            yp[3] = (y[1] * (nu2 / r2 - p) +
                     y[3] * (2 * wl.k0**2 * n * np / p - 1 / r) -
                     y[0] * constants.Y0 * (2 * nu * beta * wl.k0 * n * np /
                                            (r * p)))
            return yp

        def jac(r, y):
            r2 = r * r
            p = (wl.k0 * self.index(r, wl))**2 - beta2

            np = self.indexp(r, wl)
            n = self.index(r, wl)

            m = numpy.empty((4, 4))
            m[0, :] = (0, 0, 1, 0)
            m[1, :] = (0, 0, 0, 1)
            m[2, :] = ((nu2 / r2 - p),
                       -(constants.eta0 * (2 * nu * beta * wl.k0 * np /
                                           (r * p * n))),
                       (2 * wl.k0**2 * n * np / p - 1 / r),
                       0)
            m[3, :] = (-constants.Y0 * (2 * nu * beta * wl.k0 * n * np /
                                        (r * p)),
                       0,
                       (nu2 / r2 - p),
                       (2 * wl.k0**2 * n * np / p - 1 / r))
            return m

        s = ode(f, jac).set_integrator("dopri5")

        if nu == 0:
            s.set_initial_value([ez, hz, ezp, hzp], ri)
            ez, hz, ezp, hzp = s.integrate(ro)

            EH = ez, hz
            Ezp = numpy.array([ezp])
            Hzp = numpy.array([hzp])
        else:
            s.set_initial_value([ez, hz, ezp, hzp], ri)
            ez, hz, ezp, hzp = s.integrate(ro)

            s.set_initial_value([eza, hza, ezap, hzap], ri)
            eza, hza, ezap, hzap = s.integrate(ro)

            EH[0] = ez, eza
            EH[1] = hz, hza

            Ezp = numpy.array([ezp, ezap])
            Hzp = numpy.array([hzp, hzap])

        # calc ephi and hphi
        u = self.u(ro, neff, wl)
        n = self.index(ro, wl)
        beta = wl.k0 * neff
        c = 1 / (wl.k0**2 * (n*n - neff*neff))

        EH[2] = c * (beta * EH[0] * nu / ro -
                     constants.eta0 * wl.k0 * Hzp)
        EH[3] = c * (-beta * EH[1] * nu / ro +
                     constants.Y0 * wl.k0 * n * n * Ezp)

        return EH
Beispiel #40
0
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