Exemplo n.º 1
0
    def test_dimensions_of_expressions(self):
        a = Quantity("a")
        SI.set_quantity_dimension(a, length)

        t = Quantity("t")
        SI.set_quantity_dimension(t, time)

        res = a**2 / t
        # we can now determine the physical dimension of res
        res_dim = SI.get_dimensional_expr(res)
        self.assertTrue(dimsys_SI.equivalent_dims(res_dim, length**2 / time))

        # In parameter dicts we can describe values along with units
        a_val = Quantity("a_val")
        SI.set_quantity_dimension(a_val, length)
        SI.set_quantity_scale_factor(a_val, 5 * meter)

        parameter_dict = {a: 5 * meter, t: 4 * second}

        res_val = res.subs(parameter_dict)
        # we can now determine the physical dimension of res_val
        # and check it against the expected
        print(SI.get_dimensional_expr(res_val))
        self.assertTrue(
            dimsys_SI.equivalent_dims(SI.get_dimensional_expr(res),
                                      SI.get_dimensional_expr(res_val)))
Exemplo n.º 2
0
def test_get_dimensional_expr_with_function():
    v_w1 = Quantity('v_w1')
    v_w2 = Quantity('v_w2')
    v_w1.set_global_relative_scale_factor(1, meter / second)
    v_w2.set_global_relative_scale_factor(1, meter / second)

    assert SI.get_dimensional_expr(sin(v_w1)) == \
        sin(SI.get_dimensional_expr(v_w1))
    assert SI.get_dimensional_expr(sin(v_w1 / v_w2)) == 1
Exemplo n.º 3
0
def test_dimensional_expr_of_derivative():
    l = Quantity("l")
    t = Quantity("t")
    t1 = Quantity("t1")
    l.set_global_relative_scale_factor(36, km)
    t.set_global_relative_scale_factor(1, hour)
    t1.set_global_relative_scale_factor(1, second)
    x = Symbol("x")
    y = Symbol("y")
    f = Function("f")
    dfdx = f(x, y).diff(x, y)
    dl_dt = dfdx.subs({f(x, y): l, x: t, y: t1})
    assert (SI.get_dimensional_expr(dl_dt) == SI.get_dimensional_expr(
        l / t / t1) == Symbol("length") / Symbol("time")**2)
    assert (SI._collect_factor_and_dimension(dl_dt) ==
            SI._collect_factor_and_dimension(l / t / t1) ==
            (10, length / time**2))
Exemplo n.º 4
0
def test_dimensional_expr_of_derivative():
    l = Quantity('l')
    t = Quantity('t')
    t1 = Quantity('t1')
    l.set_global_relative_scale_factor(36, km)
    t.set_global_relative_scale_factor(1, hour)
    t1.set_global_relative_scale_factor(1, second)
    x = Symbol('x')
    y = Symbol('y')
    f = Function('f')
    dfdx = f(x, y).diff(x, y)
    dl_dt = dfdx.subs({f(x, y): l, x: t, y: t1})
    assert SI.get_dimensional_expr(dl_dt) ==\
        SI.get_dimensional_expr(l / t / t1) ==\
        Symbol("length")/Symbol("time")**2
    assert SI._collect_factor_and_dimension(dl_dt) ==\
        SI._collect_factor_and_dimension(l / t / t1) ==\
        (10, length/time**2)
Exemplo n.º 5
0
 def v_unit(t):
     # Note:
     # At the moment t has to be a scalar
     cond_1 = simplify(t) == 0
     cond_2 = dimsys_SI.equivalent_dims(SI.get_dimensional_expr(t),
                                        time)
     assert cond_1 | cond_2
     omega = 2 * pi / second
     # phi = 0
     phi = pi / 8
     V_0 = 20 * meter / second
     V_range = 5 * meter / second
     return V_0 + V_range * sin(omega * t + phi)
Exemplo n.º 6
0
def test_quantity_abs():
    v_w1 = Quantity('v_w1')
    v_w2 = Quantity('v_w2')
    v_w3 = Quantity('v_w3')

    v_w1.set_global_relative_scale_factor(1, meter / second)
    v_w2.set_global_relative_scale_factor(1, meter / second)
    v_w3.set_global_relative_scale_factor(1, meter / second)

    expr = v_w3 - Abs(v_w1 - v_w2)

    assert SI.get_dimensional_expr(v_w1) == (length / time).name

    Dq = Dimension(SI.get_dimensional_expr(expr))

    with warns_deprecated_sympy():
        Dq1 = Dimension(Quantity.get_dimensional_expr(expr))
        assert Dq == Dq1

    assert SI.get_dimension_system().get_dimensional_dependencies(Dq) == {
        'length': 1,
        'time': -1,
    }
    assert meter == sqrt(meter**2)
Exemplo n.º 7
0
def test_quantity_postprocessing():
    q1 = Quantity('q1')
    q2 = Quantity('q2')

    SI.set_quantity_dimension(q1, length*pressure**2*temperature/time)
    SI.set_quantity_dimension(q2, energy*pressure*temperature/(length**2*time))

    assert q1 + q2
    q = q1 + q2
    Dq = Dimension(SI.get_dimensional_expr(q))
    assert SI.get_dimension_system().get_dimensional_dependencies(Dq) == {
        'length': -1,
        'mass': 2,
        'temperature': 1,
        'time': -5,
    }
Exemplo n.º 8
0
def test_quantity_postprocessing():
    q1 = Quantity("q1")
    q2 = Quantity("q2")

    SI.set_quantity_dimension(q1, length * pressure**2 * temperature / time)
    SI.set_quantity_dimension(
        q2, energy * pressure * temperature / (length**2 * time))

    assert q1 + q2
    q = q1 + q2
    Dq = Dimension(SI.get_dimensional_expr(q))
    assert SI.get_dimension_system().get_dimensional_dependencies(Dq) == {
        "length": -1,
        "mass": 2,
        "temperature": 1,
        "time": -5,
    }