def Bfield_CircularCurrentLoopV(I0, D, POS):

    R = D / 2  #radius

    N = len(D)  # vector size

    X, Y, Z = POS[:, 0], POS[:, 1], POS[:, 2]

    RR, PHI = sqrt(X**2 + Y**2), arctan2(Y, X)  # cylindrical coordinates

    deltaP = sqrt((RR + R)**2 + Z**2)
    deltaM = sqrt((RR - R)**2 + Z**2)
    kappa = deltaP**2 / deltaM**2
    kappaBar = 1 - kappa

    # allocate solution vector
    field_R = empty([N])

    # avoid discontinuity of Br on z-axis
    maskRR0 = RR == np.zeros([N])
    field_R[maskRR0] = 0
    # R-component computation
    notM = np.invert(maskRR0)
    field_R[notM] = -2 * 1e-4 * (Z[notM] / RR[notM] / deltaM[notM]) * (
        ellipticKV(kappaBar[notM]) - (2 - kappaBar[notM]) /
        (2 - 2 * kappaBar[notM]) * ellipticEV(kappaBar[notM]))

    # Z-component computation
    field_Z = -2 * 1e-4 * (1 / deltaM) * (
        -ellipticKV(kappaBar) + (2 - kappaBar - 4 * (R / deltaM)**2) /
        (2 - 2 * kappaBar) * ellipticEV(kappaBar))

    # transformation to cartesian coordinates
    Bcy = np.array([field_R, np.zeros(N), field_Z]).T
    AX = np.zeros([N, 3])
    AX[:, 2] = 1
    Bkart = angleAxisRotationV_priv[1, 1](PHI / pi * 180, AX, Bcy)

    return (Bkart.T * I0).T * 1000  # to mT
Esempio n. 2
0
def test_ellipticSpecialCases():
    X = np.linspace(0, .9999, 33)
    Y = np.linspace(0, .9999, 33)[::-1]

    solV = ellipticKV(X)
    solC = np.array([ellipticK(x) for x in X])
    assert np.amax(abs(solV - solC)) < 1e-15

    solV = ellipticEV(X)
    solC = np.array([ellipticE(x) for x in X])
    assert np.amax(abs(solV - solC)) < 1e-15

    solV = ellipticPiV(X, Y)
    solC = np.array([ellipticPi(x, y) for x, y in zip(X, Y)])
    assert np.amax(abs(solV - solC)) < 1e-15