Ejemplo n.º 1
0
def test_cartesian_differential_v_t(cartesian_differential):
    """
    Tests v_t for CartesianDifferential specifically

    """

    # Defining Minkowski Metric
    def metric_covariant(x_vec):
        g = np.zeros((4, 4))
        g[0, 0] = 1
        g[1, 1] = g[2, 2] = g[3, 3] = -1

        return g

    mink = BaseMetric(coords=cartesian_differential,
                      M=1e24 * u.kg,
                      a=0 * u.one,
                      Q=0 * u.C,
                      name="Minkowski Metric",
                      metric_cov=metric_covariant)

    v4 = cartesian_differential.velocity(mink)

    assert_allclose(v4 @ mink.metric_covariant(np.ones(4)) @ v4,
                    _c**2,
                    rtol=1e-8)
Ejemplo n.º 2
0
def test_alpha_raises_error(a):
    """
    Tests, if AssertionError is raised for invalid 'a' inputs

    """
    try:
        BaseMetric.alpha(a, 3e20)
        assert False
    except ValueError:
        assert True
Ejemplo n.º 3
0
def test_unperturbed_metric_covariant():
    """
    Tests, if unperturbed metric is returned

    """
    met = BaseMetric(coords="BL", M=1e22, a=0.75, Q=1., metric_cov=dummy_met, perturbation=None)

    met_calc = dummy_met(np.ones(4, dtype=float))

    assert_allclose(met.metric_covariant(np.ones(4, dtype=float)), met_calc, rtol=1e-10)
Ejemplo n.º 4
0
def test_perturbation():
    """
    Tests, if the ``pertubation`` is added correctly

    """
    met = BaseMetric(coords="BL", M=1e22, a=0.75, Q=1., metric_cov=dummy_met, perturbation=dummy_perturb)

    met_calc = 3.4 * np.ones((4, 4), dtype=float)

    assert_allclose(met.metric_covariant(np.ones(4, dtype=float)), met_calc, rtol=1e-10)
Ejemplo n.º 5
0
def test_r_ks_raises_NotImplementedError():
    """
    Tests, if ``r_ks()`` raises a NotImplementedError, when invoked

    """
    try:
        BaseMetric.r_ks(1., 1., 1., 0.8)
        assert False

    except NotImplementedError:
        assert True
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def convert_bl(self, **kwargs):
        """
        Converts to Boyer-Lindquist Coordinates

        Parameters
        ----------
        **kwargs : dict
            Keyword Arguments
            Expects two arguments, ``M and ``a``, as described below

        Other Parameters
        ----------------
        M : float
            Mass of the gravitating body, \
            around which, spacetime has been defined
        a : float
            Spin Parameter of the gravitating body, \
            around which, spacetime has been defined

        Returns
        -------
        tuple
            4-Tuple or 7-Tuple, containing the components in \
            Boyer-Lindquist Coordinates

        Raises
        ------
        KeyError
            If ``kwargs`` does not contain both ``M`` \
            and ``a`` as keyword arguments

        """
        try:
            M, a = kwargs["M"], kwargs["a"]
        except KeyError:
            raise KeyError(
                "Two keyword arguments are expected: Mass, 'M' and Spin Parameter, 'a'."
            )

        alpha = BaseMetric.alpha(M=M, a=a)

        return cartesian_to_bl_fast(
            self.t_si,
            self.x_si,
            self.y_si,
            self.z_si,
            alpha,
            self.v_x_si,
            self.v_y_si,
            self.v_z_si,
            self._velocities_provided,
        )
Ejemplo n.º 8
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)
Ejemplo n.º 9
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

    """
    r, theta = 1.5, 3 * np.pi / 5
    M, a, Q = 2e22, 0.5, 10.0
    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(r, theta, M, a, Q)

    # 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 *
           (r2 - (alpha * np.cos(th))**2)) / ((r2 +
                                               (alpha * np.cos(th))**2)**2)
    D_th = ((alpha2) *
            (-(scale_Q * Q)) * np.sin(2 * th)) / ((r2 +
                                                   (alpha * np.cos(th))**2)**2)
    H_r = (2 * alpha * (scale_Q * Q) *
           (r2 + alpha2) * np.cos(th)) / (r * ((r2 +
                                                (alpha * np.cos(th))**2)**2))
    H_th = ((alpha * (scale_Q * Q) * 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)