Beispiel #1
0
    def test_cartesian_coords(self):
        """Test cartesian coordinate helper"""
        cs = coords.cartesian_coords()
        assert len(cs.base_symbols()) == 4  # 4 dim space
        assert str(cs) == "cartesian"

        cs = coords.cartesian_coords(dim=2)
        assert len(cs.base_symbols()) == 2  # 4 dim space
        assert str(cs) == "cartesian"
Beispiel #2
0
def friedmann_lemaitre_roberston_walker(curvature_constant: Symbol = symbols.k,
                                        cartesian: bool = False):
    """Utility for constructing the FLRW metric in terms of a unit lapse and general
    scale function `a`.

    Args:
        curvature_constant:
            Symbol, default "k", the curvature parameter in reduced polar coordinates
        cartesian:
            bool, default False. If true create a cartesian FLRW and ignore curvature_constant argument

    Returns:
        Metric, the FLRW metric

    References:
        [1] S. Weinberg, Cosmology (Oxford University Press, Oxford ; New York, 2008).
    """
    a = Function('a')(symbols.t)
    if cartesian:
        cs = coords.cartesian_coords()
        dt, dx, dy, dz = cs.base_oneforms()
        form = -c**2 * tpow(
            dt, 2) + a**2 * (tpow(dx, 2) + tpow(dy, 2) + tpow(dz, 2))
    else:
        cs = coords.toroidal_coords()
        _, r, theta, _ = cs.base_symbols()
        dt, dr, dtheta, dphi = cs.base_oneforms()
        form = -c**2 * tpow(dt, 2) + a**2 * (
            1 / (1 - curvature_constant * r**2) * tpow(dr, 2) + r**2 *
            (tpow(dtheta, 2) + sin(theta)**2 * tpow(dphi, 2)))
    return Metric(twoform=form, components=(a, ))
 def test_matrix_to_twoform(self):
     """Test matrix -> Expr"""
     cs = coords.cartesian_coords(dim=2)
     base_forms = cs.base_oneforms()
     a, b = symbols('a b')
     matrix = Matrix([[a**2, 0], [0, b**2]])
     form = utilities.matrix_to_twoform(matrix, base_forms)
     assert repr(
         form) == "a**2*TensorProduct(dt, dt) + b**2*TensorProduct(dx, dx)"
Beispiel #4
0
def minkowski():
    """Utility for constructing the Minkowski metric

    Returns:
        Metric, the Minkowski metric for flat space

    References:
        [1] S. Weinberg, Cosmology (Oxford University Press, Oxford ; New York, 2008).
    """
    cs = coords.cartesian_coords()
    dt, dx, dy, dz = cs.base_oneforms()
    form = -tpow(dt, 2) + tpow(dx, 2) + tpow(dy, 2) + tpow(dz, 2)
    return Metric(twoform=form)
Beispiel #5
0
    def test_simplify_deriv_notation(self):
        """Test simplify deriv notation"""
        cs = coords.cartesian_coords()
        t, x, *_ = cs.base_symbols()
        dt, dx, *_ = cs.base_oneforms()
        F = Function('F')(t)
        G = Function('G')(t, x)

        form = F ** 2 * tpow(dt, 2) + G ** 2 * tpow(dx, 2)
        g = metric.Metric(twoform=form, components=(F, G))

        # Check First-Order Terms
        assert str(metric.simplify_deriv_notation(D(F, t), g, max_order=1)) == "F'(t)"
        assert str(metric.simplify_deriv_notation(D(F, t), g, max_order=1, use_dots=True)) == r"\dot{F}(t)"

        # Check Second-Order Pure Terms
        assert str(metric.simplify_deriv_notation(D(D(F, t), t), g, max_order=2)) == "F''(t)"
        assert str(metric.simplify_deriv_notation(D(D(F, t), t), g, max_order=2, use_dots=True)) == r"\ddot{F}(t)"

        # Check Second-Order Mixed Terms
        assert str(metric.simplify_deriv_notation(D(D(G, t), t), g, max_order=2)) == "G_{t t}(t, x)"
        assert str(metric.simplify_deriv_notation(D(D(G, t), x), g, max_order=2)) == "G_{t x}(t, x)"