Esempio n. 1
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
Esempio n. 2
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)
Esempio n. 3
0
def test_Geodesics_repr_returns_members(dummy_data):
    body, t, _, end_lambda, stepsize = dummy_data
    geo = Geodesic(body, time=t, end_lambda=end_lambda, step_size=stepsize)
    assert (
        geo.__repr__() ==
        "body name= (obj) , metric=(Schwarzschild) , parent name=(attractor) , parent mass=(6e+24 kg)"
    )
Esempio n. 4
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)
Esempio n. 5
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
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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
Esempio n. 10
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)
Esempio n. 11
0
def test_Geodesics_has_trajectory(dummy_data):
    metric, init_vec, end_lambda, step_size = dummy_data
    geo = Geodesic(metric=metric,
                   init_vec=init_vec,
                   end_lambda=end_lambda,
                   step_size=step_size)

    assert isinstance(geo.trajectory, np.ndarray)
Esempio n. 12
0
def test_order_NotImplementedError():

    with pytest.raises(NotImplementedError):
        geod = Geodesic(
            metric="Kerr",
            metric_params=(0.9,),
            position=[2.15, np.pi / 2, 0.],
            momentum=[0., 0., 1.5],
            time_like=True,
            steps=4,
            delta=0.5,
            order=5
        )
Esempio n. 13
0
def test_runtime_warning2():
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")

        geod = Geodesic(
            metric="Kerr",
            metric_params=(0.9,),
            position=[2.15, np.pi / 2, 0.],
            momentum=[0., 0., 1.5],
            time_like=True,
            steps=4,
            delta=0.5,
            omega=0.01  # Stable integration
        )

        assert len(w) == 0
Esempio n. 14
0
def perihelion():
    Attractor = Body(name="BH", mass=6e24 * u.kg, parent=None)
    sph_obj = SphericalDifferential(
        130 * u.m,
        np.pi / 2 * u.rad,
        -np.pi / 8 * u.rad,
        0 * u.m / u.s,
        0 * u.rad / u.s,
        1900 * u.rad / u.s,
    )
    Object = Body(differential=sph_obj, parent=Attractor)
    geodesic = Geodesic(body=Object,
                        time=0 * u.s,
                        end_lambda=0.002,
                        step_size=5e-8)
    return geodesic
Esempio n. 15
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])

    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 = 0.002
    step_size = 5e-8

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

    return geod
Esempio n. 16
0
def dummy_data():
    obj = SphericalDifferential(
        130 * u.m,
        np.pi / 2 * u.rad,
        -np.pi / 8 * u.rad,
        0 * u.m / u.s,
        0 * u.rad / u.s,
        1900 * u.rad / u.s,
    )
    att = Body(name="attractor", mass=6e24 * u.kg, parent=None)
    b1 = Body(name="obj", differential=obj, parent=att)
    t = 0 * u.s
    start_lambda = 0.0
    end_lambda = 0.002
    step_size = 5e-8
    geo = Geodesic(b1, time=t, end_lambda=end_lambda, step_size=step_size)
    return geo
Esempio n. 17
0
def test_runtime_warning_python(dummy_time_python):
    q0, p0, a, end_lambda, step_size, julia = dummy_time_python

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

        geod = Geodesic(position=q0,
                        momentum=p0,
                        a=a,
                        end_lambda=end_lambda,
                        step_size=step_size,
                        time_like=True,
                        return_cartesian=True,
                        julia=julia)

        assert len(w) == 1  # 1 warning to be shown
        assert issubclass(w[-1].category, RuntimeWarning)
Esempio n. 18
0
def test_runtime_warning1():
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")

        geod = Geodesic(
            metric="Kerr",
            metric_params=(0.9,),
            position=[2.15, np.pi / 2, 0.],
            momentum=[0., 0., 1.5],
            time_like=True,
            steps=4,
            delta=0.5,
            omega=1.  # Unstable integration
        )

        assert len(w) == 2  # 2 warnings to be shown
        assert issubclass(w[-1].category, RuntimeWarning)
Esempio n. 19
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)
Esempio n. 20
0
def Plot(Attractor, sph_obj, simLength=0.002):
    '''Plots with given attractor and bodies. Note: increasing simLength gives longer simulation but takes longer to load'''
    plt.close()
    obj = StaticGeodesicPlotter()
    #Adding the body to the attractor
    Object = Body(differential=sph_obj, parent=Attractor)
    #Define geometry i.e. Schwarzschild
    geodesic = Geodesic(body=Object,
                        time=startTime * u.s,
                        end_lambda=simLength,
                        step_size=sSize)
    #Plotting the trajectory
    obj.plot(geodesic)
    plt.title("Plot of Orbit")
    #Plot Visuals
    fig = plt.gcf()
    fig.canvas.set_window_title("Plot of Orbit")
    plt.show()
Esempio n. 21
0
def test_higher_order_traits(order):
    geod = Geodesic(
        metric="Kerr",
        metric_params=(0.5,),
        position=[4., np.pi / 2, 0.],
        momentum=[0., 0., 2.],
        time_like=False,
        steps=10,
        delta=0.5,
        order=order,
        return_cartesian=False,
        suppress_warnings=True
    )

    L = geod.momentum[-1]
    theta = geod.position[2]

    assert_allclose(geod.trajectory[1][:, -1], L, atol=1e-4, rtol=1e-4)
    assert_allclose(geod.trajectory[1][:, 2], theta, atol=1e-6, rtol=1e-6)
Esempio n. 22
0
def dummy_geod():
    q0 = [2.5, np.pi / 2, 0.]
    p0 = [0., -0.2, -2.]
    a = 0.9
    end_lambda = 1.
    step_size = 0.05
    time_like = False
    return_cartesian = True
    julia = False

    geod = Geodesic(position=q0,
                    momentum=p0,
                    a=a,
                    end_lambda=end_lambda,
                    step_size=step_size,
                    time_like=time_like,
                    return_cartesian=return_cartesian,
                    julia=julia)

    return geod
Esempio n. 23
0
def test_calculate_trajectory3_schwarzschild():
    # same test as with test_calculate_trajectory2_schwarzschild(),
    # but initialized with cartesian coordinates
    # and function returning cartesian coordinates
    t = 0.
    M = 1.989e30
    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:]

    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,
    )

    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)
Esempio n. 24
0
def test_calculate_trajectory_kerr_Geodesic(bl, M, a, end_lambda, step_size):
    mk = Kerr(coords=bl, M=M, a=a)

    geod = Geodesic(time_like=True,
                    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)
Esempio n. 25
0
def run(planet):
    '''
    Defining Variables and Objects
    '''
    grav_constant = 6.67430e-20 * u.km**3 / (u.kg * u.s**2)  # km3 kg-1 s-2
    bodies_list = ['sun', 'mercury', 'venus', 'earth', 'moon']
    all_bodies_list = [
        'sun', 'mercury', 'venus', 'earth', 'moon', 'mars', 'jupiter',
        'saturn', 'uranus', 'neptune'
    ]
    radius = {
        'sun': 696340 * u.km,
        'mercury': 2439.5 * u.km,
        'venus': 6052 * u.km,
        'earth': 6371 * u.km,
        'moon': 3389.5 * u.km,
        'mars': 3389.5 * u.km,
        'jupiter': 142984 / 2 * u.km,
        'saturn': 120536 / 2 * u.km,
        'uranus': 51118 / 2 * u.km,
        'neptune': 49528 / 2 * u.km
    }
    aphelion = {
        'sun': 0 * u.km,
        'mercury': 69.8e6 * u.km,
        'venus': 108.9e6 * u.km,
        'earth': 152.1e6 * u.km,
        'moon': 0.406e6 * u.km,
        'mars': 249.2e6 * u.km,
        'jupiter': 816.6e6 * u.km,
        'saturn': 1514.5e6 * u.km,
        'uranus': 3003.6e6 * u.km,
        'neptune': 4545.7e6 * u.km
    }
    perihelion = {
        'sun': 0 * u.km,
        'mercury': 46.0e6 * u.km,
        'venus': 107.5e6 * u.km,
        'earth': 147.1e6 * u.km,
        'moon': 0.363e6 * u.km,
        'mars': 206.6e6 * u.km,
        'jupiter': 740.5e6 * u.km,
        'saturn': 1352.6e6 * u.km,
        'uranus': 2741.3e6 * u.km,
        'neptune': 4444.5e6 * u.km
    }
    mass = {
        'sun': 1.989e30 * u.kg,
        'mercury': 0.33e24 * u.kg,
        'venus': 4.87e24 * u.kg,
        'earth': 5.972e24 * u.kg,
        'moon': 7.34767309e22 * u.kg,
        'mars': 6.39e23 * u.kg,
        'jupiter': 1898e24 * u.kg,
        'saturn': 568e24 * u.kg,
        'uranus': 86.8e24 * u.kg,
        'neptune': 103e24 * u.kg
    }

    distances_value = {}
    speed_at_perihelion = {}
    omega = {}

    for body in bodies_list:
        distances_value[body] = [0 * u.km, perihelion[body], 0 * u.km]
        if body != 'sun':
            speed_at_perihelion[body] = np.sqrt(grav_constant * mass['sun'] /
                                                perihelion[body])
            omega[body] = (u.rad *
                           speed_at_perihelion[body]) / perihelion[body]
    '''
    Spherical Differentiation Objects and Body Objects
    '''

    # args(name=str, mass=kg, R(radius)=units, differential=coordinates of body,
    #       a=spin factor, q=charge, is_attractor=True/False, parent=who's the parent body)

    sd_obj = {}
    body_obj = {}
    for object in bodies_list:
        if object != 'sun':
            sd_obj[object] = SphericalDifferential(
                perihelion[object], np.pi / 2 * u.rad, np.pi * u.rad,
                0 * u.km / u.s, 0 * u.rad / u.s, omega[object])
            body_obj[object] = Body(name=object,
                                    mass=mass[object],
                                    differential=sd_obj[object],
                                    parent=body_obj['sun'])
        elif object == 'sun':
            body_obj[object] = Body(name="sun", mass=mass[object], parent=None)
        elif object == 'moon':
            body_obj[object] = Body(name=object,
                                    mass=mass[object],
                                    differential=sd_obj[object],
                                    parent=body_obj['earth'])
    '''
    Calculating Trajectory
    '''
    # Set for a year (in seconds)
    end_lambda = {
        'earth': ((1 * u.year).to(u.s)).value,
        'moon': ((1 / 12 * u.year).to(u.s)).value
    }
    # Choosing stepsize for ODE solver to be 5 minutes
    stepsize = {
        'earth': ((5 * u.min).to(u.s)).value,
        'moon': ((5 / 12 * u.min).to(u.s)).value
    }
    '''
    Trajectory to Cartesian
    '''
    def get_schwarz():
        schwarz_obj = {}
        schwarz_ans = {}
        for object in bodies_list:
            if object != 'sun':
                schwarz_obj[object] = Schwarzschild.from_coords(
                    sd_obj[object], mass['sun'])
                schwarz_ans[object] = schwarz_obj[object].calculate_trajectory(
                    end_lambda=end_lambda['earth'],
                    OdeMethodKwargs={"stepsize": stepsize['earth']},
                    return_cartesian=True)
        return schwarz_obj, schwarz_ans

    '''
    Calculating Distance
    '''
    # # At Aphelion   -   r should be 152.1e6 km
    # r = np.sqrt(np.square(ans[1][:, 1]) + np.square(ans[1][:, 2]))
    # i = np.argmax(r)
    # print((r[i] * u.m).to(u.km))
    # #                   speed should be 29.29 km/s
    # print(((ans[1][i][6]) * u.m / u.s).to(u.km / u.s))
    # #                   eccentricity should be 0.0167
    # xlist, ylist = ans[1][:, 1], ans[1][:, 2]
    # i = np.argmax(ylist)
    # x, y = xlist[i], ylist[i]
    # eccentricity = x / (np.sqrt(x ** 2 + y ** 2))
    # print(eccentricity)
    '''
    Animating
    '''
    geodesic = {}
    plotter = {}
    for object in bodies_list:
        if object != 'sun':
            if object == 'moon':
                geodesic[object] = Geodesic(body=body_obj[object],
                                            time=0 * u.s,
                                            end_lambda=end_lambda['moon'],
                                            step_size=stepsize['moon'])
            geodesic[object] = Geodesic(body=body_obj[object],
                                        time=0 * u.s,
                                        end_lambda=end_lambda['earth'],
                                        step_size=stepsize['earth'])

    sgp = StaticGeodesicPlotter()
    sgp.animate(
        geodesic[planet], interval=5
    )  # Objects currently limited to ['sun', 'mercury', 'venus', 'earth', 'moon']
    sgp.show()
Esempio n. 26
0
def test_Geodesics_has_trajectory(dummy_data):
    body, t, _, end_lambda, stepsize = dummy_data
    geo = Geodesic(body, time=t, end_lambda=end_lambda, step_size=stepsize)
    assert isinstance(geo.trajectory, np.ndarray)
Esempio n. 27
0
def test_Geodesics_conserves_the_attractor(dummy_data):
    body, t, _, end_lambda, stepsize = dummy_data
    geo = Geodesic(body, time=t, end_lambda=end_lambda, step_size=stepsize)
    assert geo.attractor == body.parent
# ans = sph_obj.calculate_trajectory(end_lambda=end_tau, OdeMethodKwargs={"stepsize": step_size}, return_cartesian=True)


'''
Bodies  -   Can define the attractor and the corresponding revolving bodies
            Plotting and geodesic calculation is easier
'''
# defining some bodies:
spin_factor = 0.3 * u.m
attractor = Body(name='BH', mass=1.989e30 * u.kg, a=spin_factor)
bl_obj = BoyerLindquistDifferential(50e5 * u.km, np.pi/2 * u.rad, np.pi * u.rad,
                                    0 * u.km / u.s, 0 * u.rad / u.s, 0 * u.rad / u.s,
                                    spin_factor)
particle = Body(differential=bl_obj, parent=attractor)
geodesic = Geodesic(body=particle, end_lambda=((1 * u.year).to(u.s)).value / 930,
                    step_size=((0.02 * u.min).to(u.s)).value,
                    metric=Kerr)
geodesic.trajectory     # returns the trajectory values

# Plotting the trajectory values
obj = GeodesicPlotter()
obj.plot(geodesic)
obj.show()


'''
Symbolic Calculations   -   Currently SchwarzschildMetric() cannot be called from package: einsteinpy.symbolic
'''
# m = SchwarzschildMetric()
# ch = ChristoffelSymbols.from_metric(m)
# print(ch[1, 2, :])
Esempio n. 29
0
import numpy as np
import sympy
from astropy import units as u

'''
Variables
'''
attractor = Body(name="BH", mass=6e24 * u.kg, parent=None)
sph_obj = SphericalDifferential(130 * u.m,
                                np.pi/2 * u.rad,
                                -np.pi/8 * u.rad,
                                0 * u.m / u.s,
                                0 * u.rad / u.s,
                                1900 * u.rad / u.s)
object = Body(differential=sph_obj, parent=attractor)
geodesic = Geodesic(body=object, time=0 * u.s, end_lambda=0.002, step_size=5e-8)


'''
Plotting Animation
'''
obj = StaticGeodesicPlotter()
obj.animate(geodesic, interval=10)
obj.show()