Exemplo n.º 1
0
def test_compare_calculate_trajectory_iterator_cartesian_kerrnewman(
        test_input):
    t, a, Q, q, end_lambda, step_size = test_input
    M = 2e24

    x_vec = np.array([1e6, 1e6, 20.5])
    v_vec = np.array([1e4, 1e4, -30.])

    mkn_cov = KerrNewman(coords="BL", M=M, a=a, Q=Q, q=q)
    x_4vec = four_position(t, x_vec)
    mkn_cov_mat = mkn_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mkn_cov_mat, t, x_vec, v_vec, time_like=True)

    OdeMethodKwargs = {"stepsize": step_size}
    return_cartesian = True

    geod = Geodesic(metric=mkn_cov,
                    init_vec=init_vec,
                    end_lambda=end_lambda,
                    step_size=step_size,
                    return_cartesian=return_cartesian)

    traj = geod.trajectory

    traj_iter = geod.calculate_trajectory_iterator(
        OdeMethodKwargs=OdeMethodKwargs, return_cartesian=return_cartesian)

    traj_iter_list = list()
    for _, val in zip(range(20), traj_iter):
        traj_iter_list.append(val[1])
    traj_iter_arr = np.array(traj_iter_list)

    assert_allclose(traj[:20], traj_iter_arr)
Exemplo n.º 2
0
def test_calculate_trajectory_iterator_RuntimeWarning_kerrnewman():
    M = 0.5 * 5.972e24
    a = 0.
    Q = 0.
    q = 0.
    t = 0.

    x_vec = np.array([306, np.pi / 2, np.pi / 2])
    v_vec = np.array([0., 0.01, 10.])

    mkn_cov = KerrNewman(coords="BL", M=M, a=a, Q=Q, q=q)
    x_4vec = four_position(t, x_vec)
    mkn_cov_mat = mkn_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mkn_cov_mat, t, x_vec, v_vec, time_like=True)

    end_lambda = 200.
    step_size = 0.4e-6
    OdeMethodKwargs = {"stepsize": step_size}

    geod = Geodesic(metric=mkn_cov,
                    init_vec=init_vec,
                    end_lambda=end_lambda,
                    step_size=step_size)

    with warnings.catch_warnings(record=True) as w:
        it = geod.calculate_trajectory_iterator(
            OdeMethodKwargs=OdeMethodKwargs, )
        for _, _ in zip(range(1000), it):
            pass
        assert len(w) >= 1
Exemplo n.º 3
0
def test_christoffels_kerrnewman(test_input):
    """
    Compares output produced by optimized function, with that, produced via general method (formula)

    """
    bl, M, a = test_input
    Q = 1.0 * u.C
    x_vec = bl.position()

    # Output produced by the optimized function
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q)
    chl1 = mkn.christoffels(x_vec)

    # Calculated using formula
    g_contra = mkn.metric_contravariant(x_vec)
    dgdx = mkn._dg_dx_bl(x_vec)
    chl2 = np.zeros(shape=(4, 4, 4), dtype=float)
    tmp = np.array([i for i in range(4 ** 3)])
    for t in tmp:
        i = int(t / (4 ** 2)) % 4
        k = int(t / 4) % 4
        index = t % 4
        for m in range(4):
            chl2[i, k, index] += g_contra[i, m] * (
                dgdx[index, m, k] + dgdx[k, m, index] - dgdx[m, k, index]
            )
    chl2 = np.multiply(chl2, 0.5)

    assert_allclose(chl2, chl1, rtol=1e-10)
Exemplo n.º 4
0
def test_calculate_trajectory1_kerrnewman():
    # This needs more investigation
    # the test particle should not move as gravitational & electromagnetic forces are balanced
    t = 0.
    M = 0.5 * 5.972e24
    a = 0.
    Q = 11604461683.91822052001953125
    q = _G * M / _Cc

    r = 1e6
    end_lambda = 1000.0
    step_size = 0.5

    x_vec = np.array([r, 0.5 * np.pi, 0.])
    v_vec = np.array([0., 0., 0.])

    mkn_cov = KerrNewman(coords="BL", M=M, a=a, Q=Q, q=q)
    x_4vec = four_position(t, x_vec)
    mkn_cov_mat = mkn_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mkn_cov_mat, t, x_vec, v_vec, time_like=True)

    geod = Geodesic(metric=mkn_cov,
                    init_vec=init_vec,
                    end_lambda=end_lambda,
                    step_size=step_size,
                    return_cartesian=False)

    ans = geod.trajectory

    assert_allclose(ans[0][1], ans[-1][1], 1e-2)
Exemplo n.º 5
0
def test_em_tensor_contravariant():
    """
    Tests skew-symmetric property of EM Tensor

    Theoretical background is required to write extensive tests. \
    Right now only skew-symmetric property is being checked.

    """
    M, a, Q = 1e22 * u.kg, 0.7 * u.one, 45.0 * u.C

    bl = BoyerLindquistDifferential(
        t=0. * u.s,
        r=5.5 * u.m,
        theta=2 * np.pi / 5 * u.rad,
        phi=0. * u.rad,
        v_r=200. * u.m / u.s,
        v_th=9. * u.rad / u.s,
        v_p=10. * u.rad / u.s
    )

    x_vec = bl.position()

    # Using function from module
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q)
    mkn_em_contra = mkn.em_tensor_contravariant(x_vec)

    assert_allclose(0., mkn_em_contra + np.transpose(mkn_em_contra), atol=1e-8)
Exemplo n.º 6
0
def test_compare_calculate_trajectory_iterator_bl(pos_vec, vel_vec, q, M, a, Q,
                                                  el, ss):
    cl1 = KerrNewman.from_BL(pos_vec, vel_vec, q, 0 * u.s, M, a, Q)
    cl2 = KerrNewman.from_BL(pos_vec, vel_vec, q, 0 * u.s, M, a, Q)
    ans1 = cl1.calculate_trajectory(end_lambda=el,
                                    OdeMethodKwargs={"stepsize": ss})[1]
    it = cl2.calculate_trajectory_iterator(OdeMethodKwargs={"stepsize": ss})
    ans2 = list()
    for _, val in zip(range(20), it):
        ans2.append(val[1])
    ans2 = np.array(ans2)
    print(ans1)
    assert_allclose(ans1[:20], ans2)
Exemplo n.º 7
0
def test_compare_kerr_kerrnewman_dmetric_dx(test_input):
    """
    Tests, if the metric derivatives for Kerr & Kerr-Newman metrics match, when Q -> 0

    """
    bl, M, a = test_input
    x_vec = bl.position()

    mk = Kerr(coords=bl, M=M, a=a)
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=0. * u.C)
    mkdx = mk._dg_dx_bl(x_vec)
    mkndx = mkn._dg_dx_bl(x_vec)

    assert_allclose(mkdx, mkndx, rtol=1e-8)
Exemplo n.º 8
0
def test_compare_kerr_kerrnewman_christoffels(test_input):
    """
    Compares KerrNewman Christoffel Symbols, with that of Kerr metric, when Q -> 0

    """
    bl, M, a = test_input
    x_vec = bl.position()

    mk = Kerr(coords=bl, M=M, a=a)
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=0. * u.C)
    mk_chl = mk.christoffels(x_vec)
    mkn_chl = mkn.christoffels(x_vec)

    assert_allclose(mk_chl, mkn_chl, rtol=1e-8)
Exemplo n.º 9
0
def test_compare_kerr_kerrnewman_christoffels(test_input):
    """
    Compares KerrNewman Christoffel Symbols, with that of Kerr metric, when Q -> 0

    """
    r, theta, M, a = test_input
    x_vec = np.array([0., r, theta, 0.])

    mk = Kerr(coords="BL", M=M, a=a)
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=0.)
    mk_chl = mk.christoffels(x_vec)
    mkn_chl = mkn.christoffels(x_vec)

    assert_allclose(mk_chl, mkn_chl, rtol=1e-8)
Exemplo n.º 10
0
def test_compare_kerr_kerrnewman_dmetric_dx(test_input):
    """
    Tests, if the metric derivatives for Kerr & Kerr-Newman metrics match, when Q -> 0

    """
    r, theta, M, a = test_input
    x_vec = np.array([0., r, theta, 0.])

    mk = Kerr(coords="BL", M=M, a=a)
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=0.)
    mkdx = mk._dg_dx_bl(x_vec)
    mkndx = mkn._dg_dx_bl(x_vec)

    assert_allclose(mkdx, mkndx, rtol=1e-10)
Exemplo n.º 11
0
def test_singularities_ks_raises_NotImplementedError():
    """
    Tests, if a NotImplementedError is raised, when KerrSchild coordinates \
    are used with ``singularities()``

    """
    mkn = KerrNewman(coords="KS", M=1e22, a=0.5, Q=0.)

    try:
        mkn_sing = mkn.singularities()
        assert False

    except NotImplementedError:
        assert True
Exemplo n.º 12
0
def test_em_tensor_covariant():
    """
    Tests, if the calculated Maxwell Tensor is the same as that from the formula
    Formula for testing from https://arxiv.org/abs/gr-qc/0409025

    """
    M, a, Q = 2e22 * u.kg, 0.5 * u.one, 10.0 * u.C

    bl = BoyerLindquistDifferential(t=0. * u.s,
                                    r=1.5 * u.m,
                                    theta=3 * np.pi / 5 * u.rad,
                                    phi=0. * u.rad,
                                    v_r=0. * u.m / u.s,
                                    v_th=0. * u.rad / u.s,
                                    v_p=0. * u.rad / u.s)

    x_vec = bl.position()
    r, theta = x_vec[1], x_vec[2]

    alpha = BaseMetric.alpha(M, a)

    # Using function from module
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q)
    mkn_em_cov = mkn.em_tensor_covariant(x_vec)

    # Checking Skew-Symmetry of Covariant Maxwell Tensor
    assert_allclose(0., mkn_em_cov + np.transpose(mkn_em_cov), atol=1e-8)

    th, r2, alpha2 = theta, r**2, alpha**2

    # Unit Scaling factor for Charge
    scale_Q = np.sqrt(_G * _Cc) / _c**2

    # Electric and Magnetic Fields
    D_r = (scale_Q * Q.value *
           (r2 - (alpha * np.cos(th))**2)) / ((r2 +
                                               (alpha * np.cos(th))**2)**2)
    D_th = ((alpha2) * (-(scale_Q * Q.value)) * np.sin(2 * th)) / (
        (r2 + (alpha * np.cos(th))**2)**2)
    H_r = (2 * alpha * (scale_Q * Q.value) *
           (r2 + alpha2) * np.cos(th)) / (r * ((r2 +
                                                (alpha * np.cos(th))**2)**2))
    H_th = ((alpha * (scale_Q * Q.value) * np.sin(th) *
             (r2 - (alpha * np.cos(th))**2)) /
            (r * ((r2 + (alpha * np.cos(th))**2)**2)))

    assert_allclose(D_r, mkn_em_cov[0, 1], rtol=1e-8)
    assert_allclose(r * D_th, mkn_em_cov[0, 2], rtol=1e-8)
    assert_allclose(-r * np.sin(theta) * H_th, mkn_em_cov[1, 3], rtol=1e-8)
    assert_allclose((r**2) * np.sin(theta) * H_r, mkn_em_cov[2, 3], rtol=1e-8)
Exemplo n.º 13
0
def test_calculate_trajectory_iterator_RuntimeWarning_kerrnewman():
    M = 0.5 * 5.972e24 * u.kg
    a = 0. * u.one
    Q = 0. * u.C
    q = 0. * u.C / u.kg

    bl = BoyerLindquistDifferential(
        t=0.0 * u.s,
        r=306.0 * u.m,
        theta=np.pi / 2 * u.rad,
        phi=np.pi / 2 * u.rad,
        v_r=0.0 * u.m / u.s,
        v_th=-0.01 * u.rad / u.s,
        v_p=10.0 * u.rad / u.s,
    )

    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q, q=q)

    end_lambda = 200.
    step_size = 0.4e-6
    OdeMethodKwargs = {"stepsize": step_size}

    geod = Timelike(metric=mkn,
                    coords=bl,
                    end_lambda=end_lambda,
                    step_size=step_size)

    with warnings.catch_warnings(record=True) as w:
        it = geod.calculate_trajectory_iterator(
            OdeMethodKwargs=OdeMethodKwargs, )
        for _, _ in zip(range(1000), it):
            pass
        assert len(w) >= 1
Exemplo n.º 14
0
def test_calculate_trajectory1_kerrnewman():
    # This needs more investigation
    # the test particle should not move as gravitational & electromagnetic forces are balanced
    M = 0.5 * 5.972e24 * u.kg
    a = 0. * u.one
    Q = 11604461683.91822052001953125 * u.C
    q = _G * M.value / _Cc * u.C / u.kg

    r = 1e6
    end_lambda = 1000.0
    step_size = 0.5

    bl = BoyerLindquistDifferential(
        t=0.0 * u.s,
        r=r * u.m,
        theta=np.pi / 2 * u.rad,
        phi=0.0 * u.rad,
        v_r=0.0 * u.m / u.s,
        v_th=0.0 * u.rad / u.s,
        v_p=0.0 * u.rad / u.s,
    )

    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q, q=q)

    geod = Timelike(metric=mkn,
                    coords=bl,
                    end_lambda=end_lambda,
                    step_size=step_size,
                    return_cartesian=False)

    ans = geod.trajectory

    assert_allclose(ans[0][1], ans[-1][1], 1e-2)
Exemplo n.º 15
0
def test_compare_calculate_trajectory_iterator_bl(test_input):
    pos_vec = [1000.0 * u.km, 0.6 * np.pi * u.rad, np.pi / 8 * u.rad]
    vel_vec = [10000 * u.m / u.s, -0.01 * u.rad / u.s, 0.0 * u.rad / u.s]
    M = 0.5 * 5.972e24 * u.kg
    q, a, Q, el, ss = test_input
    cl1 = KerrNewman.from_BL(pos_vec, vel_vec, q, 0 * u.s, M, a, Q)
    cl2 = KerrNewman.from_BL(pos_vec, vel_vec, q, 0 * u.s, M, a, Q)
    ans1 = cl1.calculate_trajectory(end_lambda=el,
                                    OdeMethodKwargs={"stepsize": ss})[1]
    it = cl2.calculate_trajectory_iterator(OdeMethodKwargs={"stepsize": ss})
    ans2 = list()
    for _, val in zip(range(20), it):
        ans2.append(val[1])
    ans2 = np.array(ans2)
    print(ans1)
    assert_allclose(ans1[:20], ans2)
Exemplo n.º 16
0
def test_em_tensor_contravariant():
    """
    Tests skew-symmetric property of EM Tensor

    Theoretical background is required to write extensive tests. \
    Right now only skew-symmetric property is being checked.

    """
    r, theta = 5.5, 2 * np.pi / 5
    M, a, Q = 1e22, 0.7, 45.0

    # Using function from module
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=Q)
    mkn_em_contra = mkn.em_tensor_contravariant(r, theta, M, a, Q)

    assert_allclose(0., mkn_em_contra + np.transpose(mkn_em_contra), atol=1e-8)
Exemplo n.º 17
0
def test_wrong_or_no_units_in_init(M, a, Q, q):
    """
    Tests, if wrong or no units are flagged as error, while instantiation

    """
    sph = SphericalDifferential(
        t=10000.0 * u.s,
        r=130.0 * u.m,
        theta=np.pi / 2 * u.rad,
        phi=-np.pi / 8 * u.rad,
        v_r=0.0 * u.m / u.s,
        v_th=0.0 * u.rad / u.s,
        v_p=0.0 * u.rad / u.s,
    )

    bl = BoyerLindquistDifferential(
        t=10000.0 * u.s,
        r=130.0 * u.m,
        theta=np.pi / 2 * u.rad,
        phi=-np.pi / 8 * u.rad,
        v_r=0.0 * u.m / u.s,
        v_th=0.0 * u.rad / u.s,
        v_p=0.0 * u.rad / u.s,
    )

    try:
        bm = BaseMetric(coords=sph, M=M, a=a, Q=Q)
        ms = Schwarzschild(coords=sph, M=M)
        mk = Kerr(coords=bl, M=M, a=a)
        mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q, q=q)

        assert False

    except (u.UnitsError, TypeError):
        assert True
Exemplo n.º 18
0
def test_singularities_raises_NotImplementedError(sph, bl):
    """
    Tests, if ``singularities()`` raises a NotImplementedError, \
    when there is a coordinate mismatch between supplied coordinate \
    object and the coordinate object, metric was instantiated with

    """
    M = 5e27 * u.kg
    a = 0. * u.one
    Q = 0. * u.C

    theta = np.pi / 4

    ms = Schwarzschild(coords=bl, M=M)
    mk = Kerr(coords=sph, M=M, a=a)
    mkn = KerrNewman(coords=sph, M=M, a=a, Q=Q)

    def mssing(ms):
        mssing = ms.singularities()

    def mksing(mk):
        mksing = mk.singularities()

    def mknsing(mkn):
        mknsing = mkn.singularities()

    with pytest.raises(NotImplementedError):
        mssing(ms)

    with pytest.raises(NotImplementedError):
        mksing(mk)

    with pytest.raises(NotImplementedError):
        mknsing(mkn)
Exemplo n.º 19
0
def test_calculate_trajectory0():
    # Based on the revolution of earth around sun
    # Data from https://en.wikipedia.org/wiki/Earth%27s_orbit
    # Initialialized with cartesian coordinates
    # Function returning cartesian coordinates
    M = 1.989e30 * u.kg
    q = 0 * u.C / u.kg
    Q = 0 * u.C
    distance_at_perihelion = 147.10e6 * u.km
    speed_at_perihelion = 30.29 * u.km / u.s
    cart_obj = CartesianDifferential(
        distance_at_perihelion / np.sqrt(2),
        distance_at_perihelion / np.sqrt(2),
        0 * u.km,
        -1 * speed_at_perihelion / np.sqrt(2),
        speed_at_perihelion / np.sqrt(2),
        0 * u.km / u.h,
    )
    a = 0 * u.m
    end_lambda = ((1 * u.year).to(u.s)).value
    cl = KerrNewman.from_cartesian(cart_obj, q, M, a, Q)
    ans = cl.calculate_trajectory(
        start_lambda=0.0,
        end_lambda=end_lambda,
        return_cartesian=True,
        OdeMethodKwargs={"stepsize": end_lambda / 1.5e3},
    )[1]
    # velocity should be 29.29 km/s at apehelion(where r is max)
    R = np.sqrt(ans[:, 1]**2 + ans[:, 2]**2 + ans[:, 3]**2)
    i = np.argmax(R)  # index whre radial distance is max
    v_apehelion = ((np.sqrt(ans[i, 5]**2 + ans[i, 6]**2 + ans[i, 7]**2) *
                    (u.m / u.s)).to(u.km / u.s)).value
    assert_allclose(v_apehelion, 29.29, rtol=0.01)
Exemplo n.º 20
0
def test_compare_kerr_kerrnewman_metric():
    """
    Tests, if covariant & contravariant forms of Kerr & Kerr-Newman metrics match, when Q -> 0

    """
    r, theta, M, a = 0.1, 4 * np.pi / 5, 1e23, 0.99
    x_vec = np.array([0., r, theta, 0.])

    mk = Kerr(coords="BL", M=M, a=a)
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=0.)
    mk_contra = mk.metric_contravariant(x_vec)
    mkn_contra = mkn.metric_contravariant(x_vec)
    mk_cov = mk.metric_covariant(x_vec)
    mkn_cov = mkn.metric_covariant(x_vec)

    assert_allclose(mk_contra, mkn_contra, rtol=1e-10)
    assert_allclose(mk_cov, mkn_cov, rtol=1e-10)
Exemplo n.º 21
0
def test_electromagnetic_potential_from_em_potential_vector(test_input):
    """
    Tests, if the calculated EM 4-Potential is the same as that from the formula

    """
    r, theta, M, a = test_input
    Q = 15.5

    # Using function from module
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=Q)
    mkn_pot = mkn.em_potential_covariant(r, theta, M=M, a=0., Q=Q)

    # Calculated using formula
    calc_pot = np.zeros((4, ), dtype=float)
    calc_pot[0] = (Q / ((_c**2) * r)) * np.sqrt(_G * _Cc)

    assert_allclose(mkn_pot, calc_pot, rtol=1e-8)
Exemplo n.º 22
0
def test_calculate_trajectory0_kerrnewman():
    # Based on the revolution of earth around sun
    # Data from https://en.wikipedia.org/wiki/Earth%27s_orbit
    # Initialized with cartesian coordinates
    # Function returning cartesian coordinates
    t = 0.
    M = 1.989e30
    a = 0.
    Q = 0.
    q = 0.
    distance_at_perihelion = 147.10e9
    speed_at_perihelion = 30290

    x_sph = CartesianConversion(distance_at_perihelion / np.sqrt(2),
                                distance_at_perihelion / np.sqrt(2), 0.,
                                -speed_at_perihelion / np.sqrt(2),
                                speed_at_perihelion / np.sqrt(2),
                                0.).convert_spherical()

    x_vec = x_sph[:3]
    v_vec = x_sph[3:]

    mkn_cov = KerrNewman(coords="BL", M=M, a=a, Q=Q, q=q)
    x_4vec = four_position(t, x_vec)
    mkn_cov_mat = mkn_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mkn_cov_mat, t, x_vec, v_vec, time_like=True)

    end_lambda = 3.154e7

    geod = Geodesic(
        metric=mkn_cov,
        init_vec=init_vec,
        end_lambda=end_lambda,
        step_size=end_lambda / 1.5e3,
    )

    ans = geod.trajectory

    # velocity should be 29.29 km/s at aphelion(where r is max)
    R = np.sqrt(ans[:, 1]**2 + ans[:, 2]**2 + ans[:, 3]**2)
    i = np.argmax(R)  # index where radial distance is max
    v_aphelion = ((np.sqrt(ans[i, 5]**2 + ans[i, 6]**2 + ans[i, 7]**2) *
                   (u.m / u.s)).to(u.km / u.s)).value

    assert_allclose(v_aphelion, 29.29, rtol=0.01)
Exemplo n.º 23
0
def test_compare_calculate_trajectory_iterator_cartesians(test_input):
    pos_vec = [1000000 * u.m, 1000000 * u.m, 20.5 * u.m]
    vel_vec = [10000 * u.m / u.s, 10000 * u.m / u.s, -30 * u.m / u.s]
    M = 2e24 * u.kg
    q, a, Q, el, ss = test_input
    cl1 = KerrNewman.from_cartesian(pos_vec, vel_vec, q, 0 * u.s, M, a, Q)
    cl2 = KerrNewman.from_cartesian(pos_vec, vel_vec, q, 0 * u.s, M, a, Q)
    ans1 = cl1.calculate_trajectory(end_lambda=el,
                                    OdeMethodKwargs={"stepsize": ss},
                                    return_cartesian=True)[1]
    it = cl2.calculate_trajectory_iterator(OdeMethodKwargs={"stepsize": ss},
                                           return_cartesian=True)
    ans2 = list()
    for _, val in zip(range(20), it):
        ans2.append(val[1])
    ans2 = np.array(ans2)
    print(ans1)
    assert_allclose(ans1[:20], ans2)
Exemplo n.º 24
0
def test_deprecation_warning_for_calculate_trajectory():
    """
    Tests, if a Deprecation Warning is shown, when accessing calculate_trajectory \
    for all metric classes
    """
    M, a, Q = 5e27, 0., 0.
    ms = Schwarzschild(M=M)
    mk = Kerr(coords="BL", M=M, a=a)
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=Q)

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")

        ms.calculate_trajectory()
        mk.calculate_trajectory()
        mkn.calculate_trajectory()

        assert len(w) == 3  # 3 warnings to be shown
        assert issubclass(w[-1].category, DeprecationWarning)
Exemplo n.º 25
0
def test_singularities_for_uncharged_nonrotating_case():
    """
    Tests, if all metric singularities match up across Schwarzschild, Kerr & Kerr-Newman \
    spacetimes, when a -> 0 & Q -> 0, subject to choice to coordinates (here, Spherical and BL)

    """
    theta = np.pi / 4
    M, a, Q = 5e27, 0., 0.

    ms = Schwarzschild(M=M)
    mk = Kerr(coords="BL", M=M, a=a)
    mkn = KerrNewman(coords="BL", M=M, a=a, Q=Q)
    mssing = ms.singularities()
    mksing = mk.singularities()
    mknsing = mkn.singularities()

    mssinglist = [
        mssing["inner_ergosphere"],
        mssing["inner_horizon"],
        mssing["outer_horizon"],
        mssing["outer_ergosphere"]
    ]

    mksinglist = [
        mksing["inner_ergosphere"](theta),
        mksing["inner_horizon"],
        mksing["outer_horizon"],
        mksing["outer_ergosphere"](theta)
    ]

    mknsinglist = [
        mknsing["inner_ergosphere"](theta),
        mknsing["inner_horizon"],
        mknsing["outer_horizon"],
        mknsing["outer_ergosphere"](theta)
    ]

    scr = ms.schwarzschild_radius(M)

    assert_allclose(mssinglist, mksinglist, rtol=1e-4, atol=0.0)
    assert_allclose(mksinglist, mknsinglist, rtol=1e-4, atol=0.0)
    assert_allclose(mknsinglist, mssinglist, rtol=1e-4, atol=0.0)
    assert_allclose(mksinglist[2], scr, rtol=1e-4, atol=0.0)
Exemplo n.º 26
0
def test_compare_kerr_kerrnewman_metric(bl):
    """
    Tests, if covariant & contravariant forms of Kerr & Kerr-Newman metrics match, when Q -> 0

    """
    M = 1e23 * u.kg
    a = 0.99 * u.one
    Q = 0. * u.C

    x_vec = bl.position()

    mk = Kerr(coords=bl, M=M, a=a)
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q)
    mk_contra = mk.metric_contravariant(x_vec)
    mkn_contra = mkn.metric_contravariant(x_vec)
    mk_cov = mk.metric_covariant(x_vec)
    mkn_cov = mkn.metric_covariant(x_vec)

    assert_allclose(mk_contra, mkn_contra, rtol=1e-10)
    assert_allclose(mk_cov, mkn_cov, rtol=1e-10)
Exemplo n.º 27
0
def test_electromagnetic_potential_from_em_potential_vector(test_input):
    """
    Tests, if the calculated EM 4-Potential is the same as that from the formula

    """
    bl, M, a = test_input
    Q = 15.5 * u.C

    x_vec = bl.position()
    r = x_vec[1]

    # Using function from module (for a = 0)
    mkn = KerrNewman(coords=bl, M=M, a=0. * u.one, Q=Q)
    mkn_pot = mkn.em_potential_covariant(x_vec)

    # Calculated using formula (for a = 0)
    calc_pot = np.zeros((4,), dtype=float)
    calc_pot[0] = (Q.value / ((_c ** 2) * r)) * np.sqrt(_G * _Cc)

    assert_allclose(mkn_pot, calc_pot, rtol=1e-8)
Exemplo n.º 28
0
def test_calculate_trajectory1(M, r, end_lambda, stepsize):
    # the test particle should not move as gravitational & electromagnetic forces are balanced
    tmp = _G * M.value / _cc
    q = tmp * u.C / u.kg
    print(tmp, 5.900455 * tmp**3)
    Q = 11604461683.91822052001953125 * u.C
    pos_vec = [r, 0.5 * np.pi * u.rad, 0 * u.rad]
    vel_vec = [0 * u.m / u.s, 0 * u.rad / u.s, 0.0 * u.rad / u.s]
    cl = KerrNewman.from_BL(pos_vec, vel_vec, q, 0 * u.s, M, 0.0, Q)
    ans = cl.calculate_trajectory(end_lambda=end_lambda,
                                  OdeMethodKwargs={"stepsize": stepsize})
    assert_allclose(ans[1][0][1], ans[1][-1][1], 1e-2)
Exemplo n.º 29
0
def test_str_repr():
    """
    Tests, if the ``__str__`` and ``__repr__`` messages match

    """
    ms = Schwarzschild(M=1e22)
    mk = Kerr(coords="BL", M=1e22, a=0.5)
    mkn = KerrNewman(coords="BL", M=1e22, a=0.5, Q=0.)

    assert str(ms) == repr(ms)
    assert str(mk) == repr(mk)
    assert str(mkn) == repr(mkn)
Exemplo n.º 30
0
def test_compare_metrics_under_limits(sph, bl):
    """
    Tests if KerrNewman Metric reduces to Kerr Metric, in the limit Q -> 0 and to Schwarzschild \
    Metric, in the limits, a -> 0 & Q -> 0

    """
    M = 6.73317655e26 * u.kg
    a1, a2 = 0.5 * u.one, 0. * u.one
    Q = 0. * u.C

    ms = Schwarzschild(coords=sph, M=M)
    mk = Kerr(coords=bl, M=M, a=a1)
    mk0 = Kerr(coords=bl, M=M, a=a2)
    mkn = KerrNewman(coords=bl, M=M, a=a1, Q=Q)
    mkn0 = KerrNewman(coords=bl, M=M, a=a2, Q=Q)

    x_vec_sph = sph.position()
    x_vec_bl = bl.position()

    ms_mat = ms.metric_covariant(x_vec_sph)
    mk_mat = mk.metric_covariant(x_vec_bl)
    mk0_mat = mk0.metric_covariant(x_vec_bl)
    mkn_mat = mkn.metric_covariant(x_vec_bl)
    mkn0_mat = mkn0.metric_covariant(x_vec_bl)

    assert_allclose(ms_mat, mk0_mat, rtol=1e-8)
    assert_allclose(mk_mat, mkn_mat, rtol=1e-8)
    assert_allclose(mkn0_mat, ms_mat, rtol=1e-8)