コード例 #1
0
def test_scalar_curvature_godel():
    x0, x1, x2, x3 = sympy.symbols('x_0 x_1 x_2 x_3')
    basis = [x0, x1, x2, x3]
    e = sympy.exp(1)
    a = sympy.Symbol('a')
    matrix = (a**2) * sympy.Matrix([[1, 0, e**x1, 0], [0, -1, 0, 0],
                                    [e**x1, 0,
                                     (e**(2 * x1)) / 2, 0], [0, 0, 0, -1]])
    metric = gr.get_tensor_from_matrix(matrix, basis)
    cs = gr.get_chrisoffel_symbols_from_metric(metric)
    R = gr.get_scalar_curvature(cs, metric)
    R = R[(), ()]
    assert R == 1.0 / a**2
コード例 #2
0
def test_christoffel_symbols1_godel():
    x0, x1, x2, x3 = sympy.symbols('x_0 x_1 x_2 x_3')
    basis = [x0, x1, x2, x3]
    e = sympy.exp(1)
    matrix = sympy.Matrix([[1, 0, e**x1, 0], [0, -1, 0, 0],
                           [e**x1, 0, (e**(2 * x1)) / 2, 0], [0, 0, 0, -1]])
    metric = gr.get_tensor_from_matrix(matrix, basis)
    christoffel_symbols_1 = gr.get_chrisoffel_symbols_from_metric(metric)
    christoffel_symbols_2 = {
        ((0, ), (0, 1)): 1,
        ((0, ), (1, 2)): (e**x1) / 2,
        ((1, ), (0, 2)): (e**x1) / 2,
        ((1, ), (2, 2)): (e**(2 * x1)) / 2,
        ((2, ), (0, 1)): -e**(-x1),
    }
    christoffel_symbols_2 = gr._dict_completer(christoffel_symbols_2, 1, 2, 4)
    assert christoffel_symbols_1.get_all_values() == christoffel_symbols_2
コード例 #3
0
def test_lower_index1():
    _type = (2, 1)
    basis = [t, x, y, z]
    dim = len(basis)
    c_indices = gr.get_all_multiindices(2, 4)
    ct_indices = gr.get_all_multiindices(1, 4)
    dict_of_values = {(a, b): 2**a[0] * 3**a[1] * 5**b[0]
                      for a in c_indices for b in ct_indices}
    tensor = gr.Tensor(basis, _type, dict_of_values)
    metric = gr.get_tensor_from_matrix(sympy.diag(-1, 1, 1, 1), basis)
    lowered_tensor_1 = gr.lower_index(tensor, metric, 1)

    _type2 = (1, 2)
    ct_indices_2 = gr.get_all_multiindices(1, 4)
    c_indices_2 = gr.get_all_multiindices(2, 4)
    dict_of_values_2 = {(a, b): sum(
        [metric[(), (r, b[0])] * tensor[(a[0], r), b[1]] for r in range(dim)])
                        for a in ct_indices_2 for b in c_indices_2}
    lowered_tensor_2 = gr.Tensor(basis, _type2, dict_of_values_2)
    assert lowered_tensor_1 == lowered_tensor_2
コード例 #4
0
def test_raise_index1():
    _type = (2, 1)
    basis = [t, x, y, z]
    dim = len(basis)
    c_indices = gr.get_all_multiindices(2, 4)
    ct_indices = gr.get_all_multiindices(1, 4)
    dict_of_values = {(a, b): 2**a[0] * 3**a[1] * 5**b[0]
                      for a in c_indices for b in ct_indices}
    tensor = gr.Tensor(basis, _type, dict_of_values)
    metric = gr.get_tensor_from_matrix(sympy.diag(-1, 1, 1, 1), basis)
    raised_tensor_1 = gr.raise_index(tensor, metric, 0)
    inv_metric = gr.get_matrix_from_tensor(metric).inv()

    _type2 = (3, 0)
    c_indices_2 = gr.get_all_multiindices(3, 4)
    ct_indices_2 = gr.get_all_multiindices(0, 4)
    dict_of_values_2 = {(a, b): sum(
        [inv_metric[r, a[2]] * tensor[(a[0], a[1]), r] for r in range(dim)])
                        for a in c_indices_2 for b in ct_indices_2}
    raised_tensor_2 = gr.Tensor(basis, _type2, dict_of_values_2)
    assert raised_tensor_1 == raised_tensor_2
コード例 #5
0
def test_tensor_from_matrix1():
    A = sympy.diag(-1, 1, 1, 1)
    basis = [t, x, y, z]
    tensor = gr.get_tensor_from_matrix(A, basis)
    assert tensor[(), (0, 0)] == -1