示例#1
0
    def test_toroidal_coords(self):
        """Test toroidal coordinate helper"""
        cs = coords.toroidal_coords()
        assert len(cs.base_symbols()) == 4  # 4 dim space
        assert str(cs) == "toroidal"

        cs = coords.toroidal_coords(dim=2)
        assert len(cs.base_symbols()) == 2  # 4 dim space
        assert str(cs) == "toroidal"
示例#2
0
 def _dummy_metric(self):
     """Make a dummy metric"""
     cs = coords.toroidal_coords(dim=2)
     dt, dr = cs.base_oneforms()
     a, b = symbols('a b')
     form = a * tpow(dt, 2) + b * tpow(dr, 2)
     return metric.Metric(twoform=form, components=(a, b))
示例#3
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, ))
示例#4
0
 def test_from_twoform(self):
     """Test from twoform"""
     cs = coords.toroidal_coords(dim=2)
     dt, dr = cs.base_oneforms()
     a, b = symbols('a b')
     form = a * tpow(dt, 2) + b * tpow(dr, 2)
     cs_p = coords.CoordSystem.from_twoform(form)
     assert cs == cs_p
示例#5
0
 def test_create_from_matrix(self):
     """Test creation from a matrix"""
     cs = coords.toroidal_coords(dim=2)
     a, b = symbols('a b')
     matrix = Array([[a, 0], [0, b]])
     with pytest.raises(ValueError):
         metric.Metric(matrix=matrix)
     g = metric.Metric(matrix=matrix, coord_system=cs)
     assert isinstance(g, metric.Metric)
示例#6
0
def general_inhomogeneous_isotropic(use_natural_units: bool = True):
    """Utility for constructing a general inhomogeneous, but still isotropic, metric (GIIM). The metric
    components M, N, L, S all depend on time and radius, but not theta or phi (hence isotropy).

    Returns:
        Metric, the GIIM metric
    """
    cs = coords.toroidal_coords()
    t, r, theta, _ = cs.base_symbols()
    dt, dr, dtheta, dphi = cs.base_oneforms()

    # Create generic isotropic metric component functions
    M = Function('M')(t, r)
    N = Function('N')(t, r)
    L = Function('L')(t, r)
    S = Function('S')(t, r)

    form = - c ** 2 * N ** 2 * tpow(dt, 2) + \
           L ** 2 * tpow(dr + c * M * dt, 2) + \
           S ** 2 * (tpow(dtheta, 2) + sin(theta) ** 2 * tpow(dphi, 2))
    if use_natural_units:
        form = constants.subs_natural(form)
    return Metric(twoform=form, components=(M, N, L, S))