예제 #1
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)
예제 #2
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)
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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)
예제 #7
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)
def test_calculate_trajectory2():
    # based on the revolution of earth around sun
    # data from https://en.wikipedia.org/wiki/Earth%27s_orbit
    M = 1.989e30 * u.kg
    distance_at_perihelion = 147.10e6 * u.km
    speed_at_perihelion = 30.29 * u.km / u.s
    angular_vel = (speed_at_perihelion / distance_at_perihelion) * u.rad
    sph_obj = SphericalDifferential(
        distance_at_perihelion,
        np.pi / 2 * u.rad,
        0 * u.rad,
        0 * u.km / u.s,
        0 * u.rad / u.s,
        angular_vel,
    )
    end_lambda = ((1 * u.year).to(u.s)).value
    cl = Schwarzschild.from_spherical(sph_obj, M)
    ans = cl.calculate_trajectory(
        start_lambda=0.0,
        end_lambda=end_lambda,
        OdeMethodKwargs={"stepsize": end_lambda / 2e3},
    )[1]
    # velocity should be 29.29 km/s at apehelion(where r is max)
    i = np.argmax(ans[:, 1])  # index whre radial distance is max
    v_apehelion = (((ans[i][1] * ans[i][7]) * (u.m / u.s)).to(u.km /
                                                              u.s)).value
    assert_allclose(v_apehelion, 29.29, rtol=0.01)
예제 #9
0
def test_differentials():
    parent = Sun
    name = "Earth"
    R = 6731 * u.km
    mass = 5.97219e24 * u.kg
    differential1 = CartesianDifferential(0 * u.km, 0 * u.km, 0 * u.km,
                                          0 * u.km / u.s, 0 * u.km / u.s,
                                          0 * u.km / u.s)
    differential2 = SphericalDifferential(0 * u.km, 0 * u.rad, 0 * u.rad,
                                          0 * u.km / u.s, 0 * u.rad / u.s,
                                          0 * u.rad / u.s)
    a = Body(name=name,
             mass=mass,
             R=R,
             differential=differential1,
             parent=parent)
    b = Body(name=name,
             mass=mass,
             R=R,
             differential=differential2,
             parent=parent)
    assert isinstance(a.pos_vec, list)
    assert isinstance(a.vel_vec, list)
    assert isinstance(b.pos_vec, list)
    assert isinstance(b.vel_vec, list)
예제 #10
0
def sph():
    return SphericalDifferential(t=0. * u.s,
                                 r=0.1 * 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=0. * u.rad / u.s)
예제 #11
0
def spherical_differential():
    return SphericalDifferential(
        1e3 * u.s,
        10e3 * u.m,
        1.5707963267948966 * u.rad,
        0.7853981633974483 * u.rad,
        10e3 * u.m / u.s,
        -20.0 * u.rad / u.s,
        20.0 * u.rad / u.s
    )
예제 #12
0
def sph():
    return 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,
    )
예제 #13
0
def dummy_data():
    sph_obj = SphericalDifferential(
        306 * u.m,
        np.pi / 2 * u.rad,
        np.pi / 2 * u.rad,
        0 * u.m / u.s,
        0 * u.rad / u.s,
        951.0 * u.rad / u.s,
    )
    t = 0 * u.s
    m = 4e24 * u.kg
    start_lambda = 0.0
    end_lambda = 0.002
    step_size = 0.5e-6
    return sph_obj, t, m, start_lambda, end_lambda, step_size
예제 #14
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
예제 #15
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
예제 #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
    return b1, t, start_lambda, end_lambda, step_size
예제 #17
0
def dummy_data():
    M = 6e24 * u.kg

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

    ms = Schwarzschild(coords=sph, M=M)

    end_lambda = 0.002
    step_size = 5e-8

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

    return geod
예제 #18
0
def test_calculate_trajectory_iterator_RuntimeWarning2():
    sph_obj = SphericalDifferential(
        306 * u.m,
        np.pi / 2 * u.rad,
        np.pi / 3 * u.rad,
        0 * u.m / u.s,
        0.01 * u.rad / u.s,
        10 * u.rad / u.s,
    )
    M = 1e25 * u.kg
    start_lambda = 0.0
    OdeMethodKwargs = {"stepsize": 0.4e-6}
    cl = Schwarzschild.from_spherical(sph_obj, M)
    with warnings.catch_warnings(record=True) as w:
        it = cl.calculate_trajectory_iterator(
            start_lambda=start_lambda,
            OdeMethodKwargs=OdeMethodKwargs,
            stop_on_singularity=False,
        )
        for _, _ in zip(range(1000), it):
            pass
        assert len(w) >= 1
예제 #19
0
def BodySetup(radius, theta, phi, v_Radius, v_Theta, v_Phi):
    '''Creates test particle with initial position and velocity vectors of test partcle in spherical coordinates
        Prefix v is velocity in respective directions'''
    return SphericalDifferential(radius * u.m, theta * u.rad, phi * u.rad,
                                 v_Radius * u.m / u.s, v_Theta * u.rad / u.s,
                                 v_Phi * u.rad / u.s)
예제 #20
0
from einsteinpy import constant
from einsteinpy.coordinates import CartesianDifferential, SphericalDifferential
from einsteinpy.metric import Schwarzschild
from einsteinpy.utils import schwarzschild_radius, schwarzschild_utils

_c = constant.c.value


@pytest.mark.parametrize(
    "coords, time, M, start_lambda, end_lambda, OdeMethodKwargs",
    [
        (
            SphericalDifferential(
                306 * u.m,
                np.pi / 2 * u.rad,
                np.pi / 2 * u.rad,
                0 * u.m / u.s,
                0 * u.rad / u.s,
                951.0 * u.rad / u.s,
            ),
            0 * u.s,
            4e24 * u.kg,
            0.0,
            0.002,
            {
                "stepsize": 0.5e-6
            },
        ),
        (
            SphericalDifferential(
                1 * u.km,
                0.15 * u.rad,
예제 #21
0
data

# In[1]:

import numpy as np
import astropy.units as u
from einsteinpy.plotting import ScatterGeodesicPlotter
from einsteinpy.coordinates import SphericalDifferential
from einsteinpy.metric import Schwarzschild

# In[2]:

M = 6e24 * u.kg
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)

# In[3]:

swc = Schwarzschild.from_spherical(sph_obj, M, 0 * u.s)

vals = swc.calculate_trajectory(end_lambda=0.002,
                                OdeMethodKwargs={"stepsize": 5e-8})[1]

time = vals[:, 0]
r = vals[:, 1]
# Currently not being used (might be useful in future)
# theta = vals[:, 2]
phi = vals[:, 3]
예제 #22
0
                   coords=sph,
                   end_lambda=end_lambda,
                   step_size=step_size)

    assert isinstance(geo.trajectory, np.ndarray)


@pytest.mark.parametrize(
    "sph, M, end_lambda, step_size",
    [
        (
            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.0 * u.rad / u.s,
                v_p=951.0 * u.rad / u.s,
            ),
            4e24 * u.kg,
            0.002,
            0.5e-6,
        ),
        (
            SphericalDifferential(
                t=0.0 * u.s,
                r=1e3 * u.m,
                theta=0.15 * u.rad,
                phi=np.pi / 2 * u.rad,
                v_r=0.1 * _c * u.m / u.s,
예제 #23
0
    def calculate_trajectory(
        self,
        start_lambda=0.0,
        end_lambda=10.0,
        stop_on_singularity=True,
        OdeMethodKwargs={"stepsize": 1e-3},
        return_cartesian=False,
    ):
        """
        Calculate trajectory in manifold according to geodesic equation

        Parameters
        ----------
        start_lambda : float
            Starting lambda(proper time), defaults to 0, (lambda ~= t)
        end_lamdba : float
            Lambda(proper time) where iteartions will stop, defaults to 100000
        stop_on_singularity : bool
            Whether to stop further computation on reaching singularity, defaults to True
        OdeMethodKwargs : dict
            Kwargs to be supplied to the ODESolver, defaults to {'stepsize': 1e-3}
            Dictionary with key 'stepsize' along with an float value is expected.
        return_cartesian : bool
            True if coordinates and velocities are required in cartesian coordinates(SI units), defaults to False

        Returns
        -------
        ~numpy.ndarray
            N-element array containing proper time.
        ~numpy.ndarray
            (n,8) shape array of [t, x1, x2, x3, velocity_of_time, v1, v2, v3] for each proper time(lambda).

        """
        ODE = RK45(fun=self.f_vec,
                   t0=start_lambda,
                   y0=self.initial_vec,
                   t_bound=end_lambda,
                   **OdeMethodKwargs)

        vecs = list()
        lambdas = list()
        crossed_event_horizon = False
        _scr = self.scr.value * 1.001

        while ODE.t < end_lambda:
            vecs.append(ODE.y)
            lambdas.append(ODE.t)
            ODE.step()
            if (not crossed_event_horizon) and (ODE.y[1] <= _scr):
                warnings.warn("particle reached Schwarzchild Radius. ",
                              RuntimeWarning)
                if stop_on_singularity:
                    break
                else:
                    crossed_event_horizon = True

        vecs, lambdas = np.array(vecs), np.array(lambdas)

        if not return_cartesian:
            return lambdas, vecs
        else:
            cart_vecs = list()
            for v in vecs:
                si_vals = (SphericalDifferential(
                    v[1] * u.m,
                    v[2] * u.rad,
                    v[3] * u.rad,
                    v[5] * u.m / u.s,
                    v[6] * u.rad / u.s,
                    v[7] * u.rad / u.s,
                ).cartesian_differential().si_values())
                cart_vecs.append(
                    np.hstack((v[0], si_vals[:3], v[4], si_vals[3:])))
            return lambdas, np.array(cart_vecs)
예제 #24
0
    def calculate_trajectory_iterator(
        self,
        start_lambda=0.0,
        stop_on_singularity=True,
        OdeMethodKwargs={"stepsize": 1e-3},
        return_cartesian=False,
    ):
        """
        Calculate trajectory in manifold according to geodesic equation
        Yields an iterator

        Parameters
        ----------
        start_lambda : float
            Starting lambda, defaults to 0.0, (lambda ~= t)
        stop_on_singularity : bool
            Whether to stop further computation on reaching singularity, defaults to True
        OdeMethodKwargs : dict
            Kwargs to be supplied to the ODESolver, defaults to {'stepsize': 1e-3}
            Dictionary with key 'stepsize' along with an float value is expected.
        return_cartesian : bool
            True if coordinates and velocities are required in cartesian coordinates(SI units), defaults to Falsed

        Yields
        ------
        float
            proper time
        ~numpy.ndarray
            array of [t, x1, x2, x3, velocity_of_time, v1, v2, v3] for each proper time(lambda).

        """
        ODE = RK45(fun=self.f_vec,
                   t0=start_lambda,
                   y0=self.initial_vec,
                   t_bound=1e300,
                   **OdeMethodKwargs)

        crossed_event_horizon = False
        _scr = self.scr.value * 1.001

        while True:
            if not return_cartesian:
                yield ODE.t, ODE.y
            else:
                v = ODE.y
                si_vals = (SphericalDifferential(
                    v[1] * u.m,
                    v[2] * u.rad,
                    v[3] * u.rad,
                    v[5] * u.m / u.s,
                    v[6] * u.rad / u.s,
                    v[7] * u.rad / u.s,
                ).cartesian_differential().si_values())
                yield ODE.t, np.hstack((v[0], si_vals[:3], v[4], si_vals[3:]))
            ODE.step()
            if (not crossed_event_horizon) and (ODE.y[1] <= _scr):
                warnings.warn("particle reached Schwarzchild Radius. ",
                              RuntimeWarning)
                if stop_on_singularity:
                    break
                else:
                    crossed_event_horizon = True
예제 #25
0
def sph():
    return SphericalDifferential(0. * u.s, 1. * u.m, np.pi / 2 * u.rad,
                                 0.1 * u.rad, 0. * u.m / u.s,
                                 0.1 * u.rad / u.s, 951 * u.rad / u.s)
예제 #26
0
def sph2():
    return 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)
예제 #27
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()
예제 #28
0
import numpy as np
from project import write_out
from astropy import units as u
from einsteinpy.coordinates import SphericalDifferential, CartesianDifferential
from einsteinpy.metric import Schwarzschild

M = 5.972e24 * u.kg
sph_coord = SphericalDifferential(306.0 * u.m, np.pi/2 * u.rad, -np.pi/6*u.rad,
                          1000*u.m/u.s, 0*u.rad/u.s, 1900*u.rad/u.s)
obj = Schwarzschild.from_coords(sph_coord, M , 0* u.s)

end_tau = 0.01 # approximately equal to coordinate time
stepsize = 0.3e-6
ans = obj.calculate_trajectory(end_lambda=end_tau, OdeMethodKwargs={"stepsize":stepsize})
x = []
y = []
z = []
for i in range(len(ans[1])):
    x.append(ans[1][i][1])
    y.append(ans[1][i][2])
    z.append(ans[1][i][3])
write_out([ans[0]] + [x] + [y] + [z], 'spherical', "solveEinstein_randphi2.txt")