示例#1
0
def test_issue_22164():
    warnings.simplefilter("error")
    dm = Quantity("dm")
    SI.set_quantity_dimension(dm, length)
    SI.set_quantity_scale_factor(dm, 1)

    bad_exp = Quantity("bad_exp")
    SI.set_quantity_dimension(bad_exp, length)
    SI.set_quantity_scale_factor(bad_exp, 1)

    expr = dm**bad_exp

    # deprecation warning is not expected here
    SI._collect_factor_and_dimension(expr)
示例#2
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))
示例#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)
示例#4
0
def test_issue_20288():
    from sympy.core.numbers import E
    from sympy.physics.units import energy
    u = Quantity('u')
    v = Quantity('v')
    SI.set_quantity_dimension(u, energy)
    SI.set_quantity_dimension(v, energy)
    u.set_global_relative_scale_factor(1, joule)
    v.set_global_relative_scale_factor(1, joule)
    expr = 1 + exp(u**2 / v**2)
    assert SI._collect_factor_and_dimension(expr) == (1 + E, Dimension(1))
示例#5
0
def test_factor_and_dimension():
    assert (3000, Dimension(1)) == SI._collect_factor_and_dimension(3000)
    assert (1001, length) == SI._collect_factor_and_dimension(meter + km)
    assert (2, length /
            time) == SI._collect_factor_and_dimension(meter / second +
                                                      36 * km / (10 * hour))

    x, y = symbols("x y")
    assert (x + y / 100,
            length) == SI._collect_factor_and_dimension(x * m + y * centimeter)

    cH = Quantity("cH")
    SI.set_quantity_dimension(cH, amount_of_substance / volume)

    pH = -log(cH)

    assert (1, volume /
            amount_of_substance) == SI._collect_factor_and_dimension(exp(pH))

    v_w1 = Quantity("v_w1")
    v_w2 = Quantity("v_w2")

    v_w1.set_global_relative_scale_factor(Rational(3, 2), meter / second)
    v_w2.set_global_relative_scale_factor(2, meter / second)

    expr = Abs(v_w1 / 2 - v_w2)
    assert (Rational(5, 4),
            length / time) == SI._collect_factor_and_dimension(expr)

    expr = Rational(5, 2) * second / meter * v_w1 - 3000
    assert (-(2996 + Rational(1, 4)),
            Dimension(1)) == SI._collect_factor_and_dimension(expr)

    expr = v_w1**(v_w2 / v_w1)
    assert (
        (Rational(3, 2))**Rational(4, 3),
        (length / time)**Rational(4, 3),
    ) == SI._collect_factor_and_dimension(expr)

    with warns_deprecated_sympy():
        assert (3000,
                Dimension(1)) == Quantity._collect_factor_and_dimension(3000)
示例#6
0
 def check_unit_consistency(expr):
     SI._collect_factor_and_dimension(expr)