def test_inv_can_transf_matrix(): dimsys = DimensionSystem((length, mass, time)) assert dimsys.inv_can_transf_matrix == eye(3) dimsys = DimensionSystem((length, velocity, action)) assert dimsys.inv_can_transf_matrix == Matrix([[2, 1, 1], [1, 0, 0], [-1, 0, -1]])
def test_print_dim_base(): mksa = DimensionSystem( (length, time, mass, current), (action,), {action: {mass: 1, length: 2, time: -1}}) L, M, T = symbols("L M T") assert mksa.print_dim_base(action) == L**2*M/T
def test_print_dim_base(): mksa = DimensionSystem( (length, time, mass, current), (action,), {action: {mass: 1, length: 2, time: -1}}) L, M, T = symbols("L M T") assert mksa.print_dim_base(action) == L**2*M/T
def test_str_repr(): assert str(DimensionSystem((length, time), name="MS")) == "MS" dimsys = DimensionSystem((length, time)) assert str(dimsys) == 'DimensionSystem(Dimension(length, L), Dimension(time, T))' assert (repr(DimensionSystem((length, time), name="MS")) == '<DimensionSystem: (Dimension(length, L), Dimension(time, T))>')
def test_extend(): ms = DimensionSystem((length, time), (velocity,)) mks = ms.extend((mass,), (action,)) res = DimensionSystem((length, time, mass), (velocity, action)) assert mks.base_dims == res.base_dims assert mks.derived_dims == res.derived_dims
def test_extend(): ms = DimensionSystem((length, time), (velocity, )) mks = ms.extend((mass, ), (action, )) res = DimensionSystem((length, time, mass), (velocity, action)) assert mks.base_dims == res.base_dims assert mks.derived_dims == res.derived_dims
def test_definition(): base = (length, time) ms = DimensionSystem(base, (velocity,), "MS", "MS system") assert ms._base_dims == DimensionSystem.sort_dims(base) assert set(ms._dims) == set(base + (velocity,)) assert ms.name == "MS" assert ms.descr == "MS system"
def test_can_transf_matrix(): dimsys = DimensionSystem((length, mass, time)) assert dimsys.can_transf_matrix == eye(3) dimsys = DimensionSystem((length, velocity, action)) assert dimsys.can_transf_matrix == eye(3) dimsys = DimensionSystem((length, time), (velocity, ), {velocity: { length: 1, time: -1 }}) assert dimsys.can_transf_matrix == eye(2)
def test_dim_vector(): dimsys = DimensionSystem((length, mass, time), (velocity, action)) assert dimsys.dim_vector(length) == Matrix([1, 0, 0]) assert dimsys.dim_vector(velocity) == Matrix([1, 0, -1]) dimsys = DimensionSystem((length, velocity, action), (mass, time)) assert dimsys.dim_vector(length) == Matrix([0, 1, 0]) assert dimsys.dim_vector(velocity) == Matrix([0, 0, 1]) assert dimsys.dim_vector(time) == Matrix([0, 1, -1])
def test_sort_dims(): with warns_deprecated_sympy(): assert DimensionSystem.sort_dims((length, velocity, time)) == ( length, time, velocity, )
def test_dim(): dimsys = DimensionSystem( (length, mass, time), (velocity, action), {velocity: {length: 1, time: -1}, action: {mass: 1, length: 2, time: -1}} ) assert dimsys.dim == 3
def test_get_dim(): ms = DimensionSystem((length, time), (velocity,)) assert ms.get_dim("L") == length assert ms.get_dim("length") == length assert ms.get_dim(length) == length assert ms["L"] == ms.get_dim("L") raises(KeyError, lambda: ms["M"])
def test_definition(): # want to test if the system can have several units of the same dimension dm = Quantity("dm", length, Rational(1, 10)) base = (m, s) base_dim = (m.dimension, s.dimension) ms = UnitSystem(base, (c, dm), "MS", "MS system") assert set(ms._base_units) == set(base) assert set(ms._units) == set((m, s, c, dm)) #assert ms._units == DimensionSystem._sort_dims(base + (velocity,)) assert ms.name == "MS" assert ms.descr == "MS system" assert ms._system._base_dims == DimensionSystem.sort_dims(base_dim) assert set(ms._system._dims) == set(base_dim + (velocity,))
def test_sort_dims(): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=SymPyDeprecationWarning) assert (DimensionSystem.sort_dims( (length, velocity, time)) == (length, time, velocity))
def test_call(): mksa = DimensionSystem((length, time, mass, current), (action, )) with warns_deprecated_sympy(): assert mksa(action) == mksa.print_dim_base(action)
def test_list_dims(): dimsys = DimensionSystem((length, time, mass)) assert dimsys.list_can_dims == (length, mass, time)
# -*- coding: utf-8 -*- """ Naturalunit system. The natural system comes from "setting c = 1, hbar = 1". From the computer point of view it means that we use velocity and action instead of length and time. Moreover instead of mass we use energy. """ from __future__ import division from sympy.physics.units.definitions import eV, hbar, c from sympy.physics.units.dimensions import DimensionSystem from sympy.physics.units.dimensions import length, mass, time, momentum,\ force, energy, power, frequency, action, velocity from sympy.physics.units.unitsystem import UnitSystem from sympy.physics.units.prefixes import PREFIXES, prefix_unit dims = (length, mass, time, momentum, force, energy, power, frequency) # dimension system _natural_dim = DimensionSystem(base=(action, energy, velocity), dims=dims, name="Natural system") units = prefix_unit(eV, PREFIXES) # unit system natural = UnitSystem(base=(hbar, eV, c), units=units, name="Natural system")
def test_call(): mksa = DimensionSystem((length, time, mass, current), (action,)) assert mksa(action) == mksa.print_dim_base(action)
def test_is_consistent(): assert DimensionSystem((length, time)).is_consistent is True
def test_inv_can_transf_matrix(): dimsys = DimensionSystem((length, mass, time)) assert dimsys.inv_can_transf_matrix == eye(3)
""" Naturalunit system. The natural system comes from "setting c = 1, hbar = 1". From the computer point of view it means that we use velocity and action instead of length and time. Moreover instead of mass we use energy. """ from __future__ import division from sympy.physics.units.definitions import c, eV, hbar from sympy.physics.units.dimensions import (DimensionSystem, action, energy, force, frequency, length, mass, momentum, power, time, velocity) from sympy.physics.units.prefixes import PREFIXES, prefix_unit from sympy.physics.units.unitsystem import UnitSystem # dimension system _natural_dim = DimensionSystem(base_dims=(action, energy, velocity), derived_dims=(length, mass, time, momentum, force, power, frequency)) units = prefix_unit(eV, PREFIXES) # unit system natural = UnitSystem(base=(hbar, eV, c), units=units, name="Natural system")
def test_sort_dims(): with warns_deprecated_sympy(): assert (DimensionSystem.sort_dims((length, velocity, time)) == (length, time, velocity))
def test_dim(): dimsys = DimensionSystem((length, mass, time), (velocity, action)) assert dimsys.dim == 3
def test_sort_dims(): assert (DimensionSystem.sort_dims((length, velocity, time)) == (length, time, velocity))
def test_list_dims(): dimsys = DimensionSystem((length, time, mass)) assert dimsys.list_can_dims == ("length", "mass", "time")
def test_dim_can_vector(): dimsys = DimensionSystem([length, mass, time], [velocity, action], {velocity: { length: 1, time: -1 }}) assert dimsys.dim_can_vector(length) == Matrix([1, 0, 0]) assert dimsys.dim_can_vector(velocity) == Matrix([1, 0, -1]) dimsys = DimensionSystem((length, velocity, action), (mass, time), {time: { length: 1, velocity: -1 }}) assert dimsys.dim_can_vector(length) == Matrix([0, 1, 0]) assert dimsys.dim_can_vector(velocity) == Matrix([0, 0, 1]) assert dimsys.dim_can_vector(time) == Matrix([0, 1, -1]) dimsys = DimensionSystem((length, mass, time), (velocity, action), { velocity: { length: 1, time: -1 }, action: { mass: 1, length: 2, time: -1 } }) assert dimsys.dim_vector(length) == Matrix([1, 0, 0]) assert dimsys.dim_vector(velocity) == Matrix([1, 0, -1])
def test_call(): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=SymPyDeprecationWarning) mksa = DimensionSystem((length, time, mass, current), (action,)) assert mksa(action) == mksa.print_dim_base(action)
def test_call(): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=SymPyDeprecationWarning) mksa = DimensionSystem((length, time, mass, current), (action, )) assert mksa(action) == mksa.print_dim_base(action)
def test_call(): mksa = DimensionSystem((length, time, mass, current), (action,)) with warns_deprecated_sympy(): assert mksa(action) == mksa.print_dim_base(action)
def test_sort_dims(): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=SymPyDeprecationWarning) assert (DimensionSystem.sort_dims((length, velocity, time)) == (length, time, velocity))
def test_error_definition(): raises(ValueError, lambda: DimensionSystem((current, charge, time))) raises(ValueError, lambda: DimensionSystem((length, time, velocity)))