Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def test_calculate_trajectory_kerr(x_vec, v_vec, t, M, a, end_lambda,
                                   step_size):
    mk_cov = Kerr(coords="BL", M=M, a=a)
    x_4vec = four_position(t, x_vec)
    mk_cov_mat = mk_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mk_cov_mat, t, x_vec, v_vec, time_like=True)

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

    ans = geod.trajectory

    testarray = list()
    for i in ans:
        x = i[:4]
        g = mk_cov.metric_covariant(x)
        testarray.append(g[0][0] * (i[4]**2) + g[1][1] * (i[5]**2) + g[2][2] *
                         (i[6]**2) + g[3][3] * (i[7]**2) +
                         2 * g[0][3] * i[4] * i[7])
    testarray = np.array(testarray, dtype=float)

    assert_allclose(testarray, 1., 1e-4)
Ejemplo n.º 3
0
def test_compare_metrics_under_limits():
    """
    Tests if KerrNewman Metric reduces to Kerr Metric, in the limit Q -> 0 and to Schwarzschild \
    Metric, in the limits, a -> 0 & Q -> 0

    """
    r, theta = 99.9, 5 * np.pi / 6
    M = 6.73317655e26

    x_vec = np.array([0., r, theta, 0.])
    ms = Schwarzschild(M=M)
    mk = Kerr(coords="BL", M=M, a=0.5)
    mk0 = Kerr(coords="BL", M=M, a=0.)
    mkn = KerrNewman(coords="BL", M=M, a=0.5, Q=0.)
    mkn0 = KerrNewman(coords="BL", M=M, a=0., Q=0.)

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

    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)
Ejemplo n.º 4
0
def test_four_velocity(v_vec, time_like):
    """
    Tests, if the 4-Velocity in KerrNewman Metric is the same as that in Kerr Metric, \
    in the limit Q -> 0 and if it becomes the same as that in Schwarzschild \
    Metric, in the limits, a -> 0 & Q -> 0

    """
    M = 1e24
    x_vec = np.array([1.0, np.pi / 2, 0.1])

    x_vec = np.array([1.0, np.pi / 2, 0.1])

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

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

    v4vec_s = four_velocity(ms_mat, v_vec, time_like)
    v4vec_k = four_velocity(mk_mat, v_vec, time_like)
    v4vec_k0 = four_velocity(mk0_mat, v_vec, time_like)
    v4vec_kn = four_velocity(mkn_mat, v_vec, time_like)
    v4vec_kn0 = four_velocity(mkn0_mat, v_vec, time_like)

    assert_allclose(v4vec_s, v4vec_k0, rtol=1e-8)
    assert_allclose(v4vec_k, v4vec_kn, rtol=1e-8)
    assert_allclose(v4vec_kn0, v4vec_s, rtol=1e-8)
Ejemplo n.º 5
0
def test_compare_vt_schwarzschild_kerr_kerrnewman():
    """
    Tests, whether the timelike component of 4-Velocity in KerrNewman Metric is the same as that \
    in Kerr Metric, in the limit Q -> 0 and if it becomes the same as that in Schwarzschild \
    Metric, in the limits, a -> 0 & Q -> 0

    """
    M = 1e24
    x_vec = np.array([1.0, np.pi / 2, 0.1])
    v_vec = np.array([-0.1, -0.01, 0.05])

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

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

    vt_s = v_t(ms_mat, v_vec)
    vt_k = v_t(mk_mat, v_vec)
    vt_k0 = v_t(mk0_mat, v_vec)
    vt_kn = v_t(mkn_mat, v_vec)
    vt_kn0 = v_t(mkn0_mat, v_vec)

    assert_allclose(vt_s, vt_k0, rtol=1e-8)
    assert_allclose(vt_k, vt_kn, rtol=1e-8)
    assert_allclose(vt_kn0, vt_s, rtol=1e-8)
Ejemplo n.º 6
0
def test_calculate_trajectory_iterator_RuntimeWarning_kerr():
    t = 0.
    M = 1e25
    a = 0.

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

    mk_cov = Kerr(coords="BL", M=M, a=a)
    x_4vec = four_position(t, x_vec)
    mk_cov_mat = mk_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mk_cov_mat, t, x_vec, v_vec, time_like=True)

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

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

    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
Ejemplo n.º 7
0
def test_calculate_trajectory_iterator_kerr(x_vec, v_vec, t, M, a, end_lambda,
                                            step_size, OdeMethodKwargs,
                                            return_cartesian):

    mk_cov = Kerr(coords="BL", M=M, a=a)
    x_4vec = four_position(t, x_vec)
    mk_cov_mat = mk_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mk_cov_mat, t, x_vec, v_vec, time_like=True)

    geod = Geodesic(metric=mk_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(50), traj_iter):
        traj_iter_list.append(val[1])
    traj_iter_arr = np.array(traj_iter_list)

    assert_allclose(traj[:50, :], traj_iter_arr, rtol=1e-10)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def test_calculate_trajectory3_kerr():
    # 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.
    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:]

    mk_cov = Kerr(coords="BL", M=M, a=a)
    x_4vec = four_position(t, x_vec)
    mk_cov_mat = mk_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(mk_cov_mat, t, x_vec, v_vec, time_like=True)

    end_lambda = 3.154e7

    geod = Geodesic(
        metric=mk_cov,
        init_vec=init_vec,
        end_lambda=end_lambda,
        step_size=end_lambda / 2e3,
    )

    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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def test_calculate_trajectory_kerr(bl, M, a, end_lambda, step_size):
    mk = Kerr(coords=bl, M=M, a=a)

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

    ans = geod.trajectory

    testarray = list()
    for i in ans:
        x = i[:4]
        g = mk.metric_covariant(x)
        testarray.append(g[0][0] * (i[4]**2) + g[1][1] * (i[5]**2) + g[2][2] *
                         (i[6]**2) + g[3][3] * (i[7]**2) +
                         2 * g[0][3] * i[4] * i[7])
    testarray = np.array(testarray)

    assert_allclose(testarray, _c**2, 1e-8)