Exemplo n.º 1
0
def test_str_repr():
    """
    Tests, if the ``__str__`` and ``__repr__`` messages match

    """
    t = 0.
    M = 1e25

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

    ms_cov = Schwarzschild(M=M)
    x_4vec = four_position(t, x_vec)
    ms_cov_mat = ms_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(ms_cov_mat, t, x_vec, v_vec, time_like=True)

    end_lambda = 1.
    step_size = 0.4e-6

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

    assert str(geod) == repr(geod)
Exemplo n.º 2
0
def test_calculate_trajectory_iterator_schwarzschild(x_vec, v_vec, t, M,
                                                     end_lambda, step_size,
                                                     OdeMethodKwargs,
                                                     return_cartesian):
    ms_cov = Schwarzschild(M=M)
    x_4vec = four_position(t, x_vec)
    ms_cov_mat = ms_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(ms_cov_mat, t, x_vec, v_vec, time_like=True)

    geod = Geodesic(metric=ms_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)
Exemplo n.º 3
0
def test_calculate_trajectory2_schwarzschild():
    # based on the revolution of earth around sun
    # data from https://en.wikipedia.org/wiki/Earth%27s_orbit
    t = 0.
    M = 1.989e30
    distance_at_perihelion = 147.10e9
    speed_at_perihelion = 30290
    angular_vel = (speed_at_perihelion / distance_at_perihelion)

    x_vec = np.array([distance_at_perihelion, np.pi / 2, 0])
    v_vec = np.array([0.0, 0.0, angular_vel])

    ms_cov = Schwarzschild(M=M)
    x_4vec = four_position(t, x_vec)
    ms_cov_mat = ms_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(ms_cov_mat, t, x_vec, v_vec, time_like=True)

    end_lambda = 3.154e7

    geod = Geodesic(metric=ms_cov,
                    init_vec=init_vec,
                    end_lambda=end_lambda,
                    step_size=end_lambda / 2e3,
                    return_cartesian=False)

    ans = geod.trajectory

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

    assert_allclose(v_aphelion, 29.29, rtol=0.01)
Exemplo n.º 4
0
def test_compare_vt_schwarzschild():
    """
    Tests, if the value of timelike component of 4-Velocity in Schwarzschild spacetime, \
    calculated using ``einsteinpy.coordindates.utils.v0()`` is the same as that calculated by \
    brute force

    """
    # Calculated using v0()
    M = 1e24 * u.kg
    sph = SphericalDifferential(0. * u.s, 1. * u.m, np.pi / 2 * u.rad,
                                0.1 * u.rad, -0.1 * u.m / u.s,
                                -0.01 * u.rad / u.s, 0.05 * u.rad / u.s)

    ms = Schwarzschild(coords=sph, M=M)
    x_vec = sph.position()
    ms_mat = ms.metric_covariant(x_vec)
    v_vec = sph.velocity(ms)

    sph.v_t = (ms, )  # Setting v_t
    vt_s = sph.v_t  # Getting v_t

    # Calculated by brute force
    A = ms_mat[0, 0]
    C = ms_mat[1, 1] * v_vec[1]**2 + ms_mat[2, 2] * v_vec[2]**2 + ms_mat[
        3, 3] * v_vec[3]**2 - _c**2
    D = -4 * A * C
    vt_sb = np.sqrt(D) / (2 * A)

    assert_allclose(vt_s.value, vt_sb, rtol=1e-8)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def test_calculate_trajectory_iterator_RuntimeWarning_schwarzschild():
    t = 0.
    M = 1e25

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

    ms_cov = Schwarzschild(M=M)
    x_4vec = four_position(t, x_vec)
    ms_cov_mat = ms_cov.metric_covariant(x_4vec)
    init_vec = stacked_vec(ms_cov_mat, t, x_vec, v_vec, time_like=True)

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

    geod = Geodesic(metric=ms_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
Exemplo n.º 7
0
def test_calculate_trajectory_iterator_RuntimeWarning_schwarzschild():
    M = 1e25 * u.kg
    sph = SphericalDifferential(
        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,
    )
    ms = Schwarzschild(coords=sph, M=M)

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

    geod = Timelike(metric=ms,
                    coords=sph,
                    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
Exemplo n.º 8
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.º 9
0
def test_f_vec_bl_schwarzschild():
    M = 6.73317655e26 * u.kg
    sph = SphericalDifferential(
        t=0. * u.s,
        r=1e6 * u.m,
        theta=4 * 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=2e6 * u.rad / u.s
    )
    f_vec_expected = np.array(
        [
            3.92128321e+03, 0.00000000e+00, 0.00000000e+00, 2.00000000e+06,
            -0.00000000e+00, 1.38196394e+18, -1.90211303e+12, -0.00000000e+00
        ]
    )

    ms = Schwarzschild(coords=sph, M=M)
    state = np.hstack((sph.position(), sph.velocity(ms)))

    f_vec = ms._f_vec(0., state)
    f_vec

    assert isinstance(f_vec, np.ndarray)
    assert_allclose(f_vec_expected, f_vec, rtol=1e-8)
Exemplo n.º 10
0
def test_v_t_raises_CoordinateError(cartesian_differential,
                                    spherical_differential, bl_differential):
    M = 1e24 * u.kg
    a = 0. * u.one
    ms = Schwarzschild(coords=spherical_differential, M=M)
    mk = Kerr(coords=bl_differential, M=M, a=a)

    cd, sd, bd = cartesian_differential, spherical_differential, bl_differential

    def cd_s(cd, ms):
        return cd.velocity(metric=ms)

    def bd_s(bd, ms):
        return bd.velocity(metric=ms)

    def cd_k(cd, mk):
        return cd.velocity(metric=mk)

    def sd_k(sd, mk):
        return sd.velocity(metric=mk)

    with pytest.raises(CoordinateError):
        cd_s(cd, ms)

    with pytest.raises(CoordinateError):
        bd_s(bd, ms)

    with pytest.raises(CoordinateError):
        cd_k(cd, mk)

    with pytest.raises(CoordinateError):
        sd_k(sd, mk)
Exemplo n.º 11
0
def test_compare_vt_schwarzschild():
    """
    Tests, if the value of timelike component of 4-Velocity in Schwarzschild spacetime, \
    calculated using ``einsteinpy.coordindates.utils.v_t()`` is the same as, that calculated by \
    brute force

    """
    # Calculated using v_t()
    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)
    ms_mat = ms.metric_covariant(x_vec)

    vt_s = v_t(ms_mat, v_vec)

    # Calculated by brute force
    A = ms_mat[0, 0]
    C = ms_mat[1, 1] * v_vec[0]**2 + ms_mat[2, 2] * v_vec[1]**2 + ms_mat[
        3, 3] * v_vec[2]**2 - 1
    D = -4 * A * C
    vt_sb = np.sqrt(D) / (2 * A)

    assert_allclose(vt_s, vt_sb, rtol=1e-8)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
def perihelion():
    """
    An example to showcase the usage of the various modules in ``einsteinpy``. \
    Here, we assume a Schwarzschild spacetime and obtain & plot the apsidal precession of \
    test particle orbit in it.

    Returns
    -------
    geod: ~einsteinpy.geodesic.Geodesic
        Geodesic defining test particle trajectory

    """
    # Mass of the black hole in SI
    M = 6e24 * u.kg

    # Defining the initial coordinates of the test particle
    # in SI
    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=1900.0 * u.rad / u.s,
    )

    # Schwarzschild Metric Object
    ms = Schwarzschild(coords=sph, M=M)

    # Calculating Geodesic
    geod = Timelike(metric=ms, coords=sph, end_lambda=0.002, step_size=5e-8)

    return geod
Exemplo n.º 15
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.º 16
0
def test_calculate_state_raises_TypeError():
    """
    Tests, if ``_calculate_state`` raises TypeError, in case of \
    coordinate mismatch

    """
    distance_at_perihelion = 147.10e9
    speed_at_perihelion = 29290

    x_sph = CartesianDifferential(
        t=0.0 * u.s,
        x=distance_at_perihelion / np.sqrt(2) * u.m,
        y=distance_at_perihelion / np.sqrt(2) * u.m,
        z=0. * u.m,
        v_x=-speed_at_perihelion / np.sqrt(2) * u.m / u.s,
        v_y=speed_at_perihelion / np.sqrt(2) * u.m / u.s,
        v_z=0 * u.m / u.s)  # .spherical_differential()

    metric = Schwarzschild(coords=x_sph.spherical_differential(),
                           M=1.989e30 * u.kg)

    end_lambda = 3.154e7

    with pytest.raises(TypeError):
        geod = Timelike(
            metric=metric,
            coords=x_sph,
            end_lambda=end_lambda,
            step_size=end_lambda / 2e3,
        )
Exemplo n.º 17
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)
Exemplo n.º 18
0
def test_str_repr():
    """
    Tests, if the ``__str__`` and ``__repr__`` messages match

    """
    M = 1e25 * u.kg
    sph = SphericalDifferential(
        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,
    )
    ms = Schwarzschild(coords=sph, M=M)

    end_lambda = 1.
    step_size = 0.4e-6

    geod = Timelike(metric=ms,
                    coords=sph,
                    end_lambda=end_lambda,
                    step_size=step_size)

    assert str(geod) == repr(geod)
Exemplo n.º 19
0
def test_calculate_trajectory2_schwarzschild():
    # based on the revolution of earth around sun
    # data from https://en.wikipedia.org/wiki/Earth%27s_orbit
    distance_at_perihelion = 147.10e9
    speed_at_perihelion = 29290
    angular_vel = (speed_at_perihelion / distance_at_perihelion)

    sph = SphericalDifferential(
        t=0.0 * u.s,
        r=distance_at_perihelion * 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=angular_vel * u.rad / u.s,
    )
    metric = Schwarzschild(coords=sph, M=1.989e30 * u.kg)

    end_lambda = 3.154e7

    geod = Timelike(metric=metric,
                    coords=sph,
                    end_lambda=end_lambda,
                    step_size=end_lambda / 2e3,
                    return_cartesian=False)

    ans = geod.trajectory

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

    assert_allclose(v_aphelion, 29.29, rtol=0.01)
Exemplo n.º 20
0
def perihelion():
    """
    An example to showcase the usage of the various modules in ``einsteinpy.metric``. \
    Here, we assume a Schwarzschild spacetime and obtain & plot the apsidal precession of \
    test particle orbit in it.

    Returns
    -------
    geod: ~einsteinpy.geodesic.Geodesic
        Geodesic defining test particle trajectory

    """
    M = 6e24  # Mass
    t = 10000  # Coordinate Time (has no effect in this case - Schwarzschild)
    x_vec = np.array([130.0, np.pi / 2, -np.pi / 8])  # 3-Pos
    v_vec = np.array([0.0, 0.0, 1900.0])  # 3-Vel

    # Schwarzschild Metric Object
    ms_cov = Schwarzschild(M=M)
    # Getting Position 4-Vector
    x_4vec = four_position(t, x_vec)
    # Calculating Schwarzschild Metric at x_4vec
    ms_cov_mat = ms_cov.metric_covariant(x_4vec)
    # Getting stacked (Length-8) initial vector, containing 4-Pos and 4-Vel
    init_vec = stacked_vec(ms_cov_mat, t, x_vec, v_vec, time_like=True)

    # Calculating Geodesic
    geod = Geodesic(metric=ms_cov, init_vec=init_vec, end_lambda=0.002, step_size=5e-8)

    return geod
Exemplo n.º 21
0
def test_v_t_getter_setter0(cartesian_differential, spherical_differential,
                            bl_differential):
    M = 1e24 * u.kg
    a = 0. * u.one
    ms = Schwarzschild(coords=spherical_differential, M=M)
    mk = Kerr(coords=bl_differential, M=M, a=a)

    def cd_vt(cartesian_differential, ms):
        cartesian_differential.v_t = (ms, )

    def sd_vt(spherical_differential, mk):
        spherical_differential.v_t = (mk, )

    # This should not raise CoordinateError
    try:
        spherical_differential.v_t = (ms, )
    except CoordinateError:
        pytest.fail("Unexpected TypeError!")

    # These 2 should raise CoordinateError
    with pytest.raises(CoordinateError):
        cd_vt(cartesian_differential, ms)

    with pytest.raises(CoordinateError):
        sd_vt(spherical_differential, mk)
Exemplo n.º 22
0
def test_velocity2(spherical_differential, bl_differential):
    M = 1e24 * u.kg
    a = 0. * u.one
    ms = Schwarzschild(coords=spherical_differential, M=M)
    mk = Kerr(coords=bl_differential, M=M, a=a)

    sd, bd = spherical_differential, bl_differential
    assert_allclose(sd.velocity(metric=ms)[1:], [sd.v_r.value, sd.v_th.value, sd.v_p.value])
    assert_allclose(bd.velocity(metric=mk)[1:], [bd.v_r.value, bd.v_th.value, bd.v_p.value])
Exemplo n.º 23
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.º 24
0
def dummy_input(sph, bl):
    M = 5e27 * u.kg
    a = 0. * u.one
    Q = 0. * u.C

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

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

    return ms, mk, mkn, x_vec_sph, x_vec_bl
Exemplo n.º 25
0
def dummy_data():
    M = 6e24
    t = 0.
    x_vec = np.array([130.0, np.pi / 2, -np.pi / 8])
    v_vec = np.array([0.0, 0.0, 1900.0])

    metric = Schwarzschild(M=M)
    x_4vec = four_position(t, x_vec)
    metric_mat = metric.metric_covariant(x_4vec)
    init_vec = stacked_vec(metric_mat, t, x_vec, v_vec, time_like=True)

    end_lambda = 0.002
    step_size = 5e-8

    return metric, init_vec, end_lambda, step_size
Exemplo n.º 26
0
def test_str_repr(sph, bl):
    """
    Tests, if the ``__str__`` and ``__repr__`` messages match

    """
    M = 1e22 * u.kg
    a = 0.5 * u.one
    Q = 0. * u.C
    ms = Schwarzschild(coords=sph, M=M)
    mk = Kerr(coords=bl, M=M, a=a)
    mkn = KerrNewman(coords=bl, M=M, a=a, Q=Q)

    assert str(ms) == repr(ms)
    assert str(mk) == repr(mk)
    assert str(mkn) == repr(mkn)
Exemplo n.º 27
0
def dummy_data():
    sph = SphericalDifferential(
        t=0.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=1900.0 * u.rad / u.s,
    )
    metric = Schwarzschild(coords=sph, M=6e24 * u.kg)

    end_lambda = 0.002
    step_size = 5e-8

    return sph, metric, end_lambda, step_size
Exemplo n.º 28
0
def test_velocity(spherical_differential, bl_differential):
    M = 1e24 * u.kg
    a = 0. * u.one
    ms = Schwarzschild(coords=spherical_differential, M=M)
    mk = Kerr(coords=bl_differential, M=M, a=a)

    def with_numpy_array(differential_obj, metric):
        assert_allclose(
            differential_obj.values()[4:],
            differential_obj.velocity(metric=metric)[1:],
            1e-10,
            1e-15,
        )

    with_numpy_array(spherical_differential, ms)
    with_numpy_array(bl_differential, mk)
Exemplo n.º 29
0
def test_v_t_getter_setter1(cartesian_differential, spherical_differential, bl_differential):
    M = 1e24 * u.kg
    a = 0. * u.one
    ms = Schwarzschild(coords=spherical_differential, M=M)
    mk = Kerr(coords=bl_differential, M=M, a=a)

    def bd_vt(bl_differential, ms):
        bl_differential.v_t = (ms,)

    # This should not raise TypeError
    try:
        bl_differential.v_t = (mk,)
    except TypeError:
        pytest.fail("Unexpected TypeError!")

    # This should raise TypeError
    with pytest.raises(TypeError):
        bd_vt(bl_differential, ms)
Exemplo n.º 30
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)