示例#1
0
def test_tensorproduct_ValueError():
    x, y = symbols("x y")
    test_list = [[x, y], [y, x]]
    obj1 = BaseRelativityTensor(test_list, syms=[x, y], config="ll")
    obj2 = BaseRelativityTensor(test_list, syms=[x, y], config="ul")
    # contract along 'l' and 'l'
    tensor_product(obj1, obj2, 0, 1)
示例#2
0
def test_lambdify_with_args():
    x, y = symbols("x y")
    T = BaseRelativityTensor([x + y, x], (x, y), config="l")
    args, f = T.tensor_lambdify(y, x)
    arr = np.array(f(2, 1))
    cmp_arr = np.array([3, 1])
    assert_allclose(arr, cmp_arr, rtol=0.0, atol=1e-7)
    for e1, e2 in zip(args, (y, x)):
        assert simplify(e1 - e2) == 0
示例#3
0
def test_tensor_product():
    x, y = symbols("x y")
    test_list = [[x, y], [y, x]]
    obj1 = BaseRelativityTensor(test_list, syms=[x, y], config="ll")
    obj2 = BaseRelativityTensor(test_list, syms=[x, y], config="ul")
    # contract along 'l' and 'u'
    obj3 = tensor_product(obj1, obj2, 1, 0)
    product_arr = [[x**2 + y**2, 2 * x * y], [2 * x * y, x**2 + y**2]]
    obj4 = BaseRelativityTensor(product_arr, syms=[x, y], config="ll")
    assert obj3.tensor() == obj4.tensor()
    assert obj3.syms == obj4.syms
    assert obj3.config == obj4.config
    # tensor_product with no contraction
    obj5 = tensor_product(obj1, obj2)
    assert obj5.config == "llul"
示例#4
0
def test_BaseRelativilyTensor_TypeError():
    # pass non list, tuple, set to variables
    t1, _, functions = arbitrary_tensor1()
    t2 = BaseRelativityTensor(t1.arr,
                              t1.symbols(),
                              config=t1.config,
                              variables="value",
                              functions=functions)
示例#5
0
def arbitrary_tensor1():
    symbolstr = "x0 x1 x2 x3"
    syms = symbols(symbolstr)
    a, c = symbols("a c")
    f1, f2, f3 = Function("f1")(a, syms[2]), Function("f2")(c), Function("f3")
    list2d = np.zeros((4, 4), dtype=int).tolist()
    list2d[0][0] = 1 - (a * f1 / syms[1])
    list2d[1][1] = -1 / ((1 - (a / syms[1])) * (c ** 2))
    list2d[2][2] = -1 * (syms[1] ** 2) / (c ** 2)
    list2d[3][3] = -1 * (syms[1] ** 2) * (sin(syms[2]) ** 2) / (c ** 2)
    list2d[0][3] = list2d[3][0] = 5 * f2
    list2d[2][1] = list2d[1][2] = f3
    return BaseRelativityTensor(list2d, syms, config="ll"), [a, c], [f1, f2, f3]
示例#6
0
def test_BaseRelativityTensor_automatic_calculation_of_free_variables():
    t1, variables, functions = arbitrary_tensor1()
    t2 = BaseRelativityTensor(t1.arr,
                              t1.symbols(),
                              config=t1.config,
                              variables=variables,
                              functions=functions)
    assert len(t1.variables) == len(t2.variables) and len(
        t1.variables) == len(variables)
    assert len(t1.functions) == len(t2.functions) and len(
        t1.functions) == len(functions)
    for v, f in zip(t1.variables, t1.functions):
        assert ((v in t2.variables) and (v in variables)
                and (f in t2.functions) and (f in functions))
示例#7
0
def test_ValueError2():
    x, y, z = symbols("x y z")
    test_list = [[x, y], [y, x]]
    # pass 2x2 array when 3x3 implied by argument syms
    obj = BaseRelativityTensor(test_list, [x, y, z])