示例#1
0
def test_prefix_unit():
    from sympy.physics.unitsystems import Unit, Dimension

    length = Dimension(length=1)
    m = Unit(length, abbrev="m")

    pref = {"m": PREFIXES["m"], "c": PREFIXES["c"], "d": PREFIXES["d"]}

    res = [Unit(length, abbrev="m", prefix=PREFIXES["m"]),
           Unit(length, abbrev="m", prefix=PREFIXES["c"]),
           Unit(length, abbrev="m", prefix=PREFIXES["d"])]

    assert set(prefix_unit(m, pref)) == set(res)
def test_prefix_unit():
    from sympy.physics.unitsystems import Unit, Dimension

    length = Dimension(length=1)
    m = Unit(length, abbrev="m")

    pref = {"m": PREFIXES["m"], "c": PREFIXES["c"], "d": PREFIXES["d"]}

    res = [
        Unit(length, abbrev="m", prefix=PREFIXES["m"]),
        Unit(length, abbrev="m", prefix=PREFIXES["c"]),
        Unit(length, abbrev="m", prefix=PREFIXES["d"])
    ]

    assert set(prefix_unit(m, pref)) == set(res)
示例#3
0
文件: mks.py 项目: Carreau/sympy
# derived units
v = Unit(velocity)
a = Unit(acceleration)
p = Unit(momentum)
J = Unit(energy, factor=10 ** 3, abbrev="J")
N = Unit(force, factor=10 ** 3, abbrev="N")
W = Unit(power, factor=10 ** 3, abbrev="W")
Pa = Unit(pressure, factor=10 ** 3, abbrev="Pa")
Hz = Unit(frequency, abbrev="Hz")

# constants
# Newton constant
G = Constant(qsimplify(m ** 3 * kg ** -1 * s ** -2).as_unit, factor=6.67384e-11, abbrev="G")
# speed of light
c = Constant(velocity, factor=299792458, abbrev="c")

units = [m, g, s, J, N, W, Pa, Hz]
all_units = []

# Prefixes of units like g, J, N etc get added using `prefix_unit`
# in the for loop, but the actual units have to be added manually.
all_units.extend([g, J, N, W, Pa, Hz])

for u in units:
    all_units.extend(prefix_unit(u, PREFIXES))
all_units.extend([v, a, p, G, c])

# unit system
mks = UnitSystem(base=(m, kg, s), units=all_units, name="MKS")
示例#4
0
# derived units
v = Unit(velocity)
a = Unit(acceleration)
p = Unit(momentum)
J = Unit(energy, factor=10**3, abbrev="J")
N = Unit(force, factor=10**3, abbrev="N")
W = Unit(power, factor=10**3, abbrev="W")
Pa = Unit(pressure, factor=10**3, abbrev="Pa")
Hz = Unit(frequency, abbrev="Hz")

# constants
# Newton constant
G = Constant(qsimplify(m**3*kg**-1*s**-2).as_unit, factor=6.67384e-11, abbrev="G")
# speed of light
c = Constant(velocity, factor=299792458, abbrev="c")

units = [m, g, s, J, N, W, Pa, Hz]
all_units = []

# Prefixes of units like g, J, N etc get added using `prefix_unit`
# in the for loop, but the actual units have to be added manually.
all_units.extend([g, J, N, W, Pa, Hz])

for u in units:
    all_units.extend(prefix_unit(u, PREFIXES))
all_units.extend([v, a, p, G, c])

# unit system
mks = UnitSystem(base=(m, kg, s), units=all_units, name="MKS")
示例#5
0
# base dimensions
action = Dimension(name="action", symbol="A", length=2, mass=1, time=-1)
energy = Dimension(name="energy", symbol="E", length=2, mass=1, time=-2)
velocity = Dimension(name="velocity", symbol="V", length=1, time=-1)

# derived dimensions
length = Dimension(name="length", symbol="L", length=1)
mass = Dimension(name="mass", symbol="M", mass=1)
time = Dimension(name="time", symbol="T", time=1)
acceleration = Dimension(name="acceleration", length=1, time=-2)
momentum = Dimension(name="momentum", mass=1, length=1, time=-1)
force = Dimension(name="force", symbol="F", mass=1, length=1, time=-2)
power = Dimension(name="power", length=2, mass=1, time=-3)
frequency = Dimension(name="frequency", symbol="f", time=-1)

dims = (length, mass, time, momentum, force, energy, power, frequency)

# dimension system
natural_dim = DimensionSystem(base=(action, energy, velocity), dims=dims,
                              name="Natural system")

# base units
hbar = Constant(action, factor=1.05457266e-34, abbrev="hbar")
eV = Unit(energy, factor=1.60219e-19, abbrev="eV")
c = Constant(velocity, factor=299792458, abbrev="c")

units = prefix_unit(eV, PREFIXES)

# unit system
natural = UnitSystem(base=(hbar, eV, c), units=units, name="Natural system")
示例#6
0
action = Dimension(name="action", symbol="A", length=2, mass=1, time=-1)
energy = Dimension(name="energy", symbol="E", length=2, mass=1, time=-2)
velocity = Dimension(name="velocity", symbol="V", length=1, time=-1)

# derived dimensions
length = Dimension(name="length", symbol="L", length=1)
mass = Dimension(name="mass", symbol="M", mass=1)
time = Dimension(name="time", symbol="T", time=1)
acceleration = Dimension(name="acceleration", length=1, time=-2)
momentum = Dimension(name="momentum", mass=1, length=1, time=-1)
force = Dimension(name="force", symbol="F", mass=1, length=1, time=-2)
power = Dimension(name="power", length=2, mass=1, time=-3)
frequency = Dimension(name="frequency", symbol="f", time=-1)

dims = (length, mass, time, momentum, force, energy, power, frequency)

# dimension system
natural_dim = DimensionSystem(base=(action, energy, velocity),
                              dims=dims,
                              name="Natural system")

# base units
hbar = Constant(action, factor=1.05457266e-34, abbrev="hbar")
eV = Unit(energy, factor=1.60219e-19, abbrev="eV")
c = Constant(velocity, factor=299792458, abbrev="c")

units = prefix_unit(eV, PREFIXES)

# unit system
natural = UnitSystem(base=(hbar, eV, c), units=units, name="Natural system")
示例#7
0
文件: si.py 项目: chaffra/sympy
qe = Constant(C, factor=1.60217733e-19, abbrev='q')

#permeability of vacuum
mu_0 = Constant(usimplify(N/A**2), factor=4e-7*math.pi, abbrev=r'\mu_0')

#permittivity of vacuum
eps_0 = Constant(usimplify(1/mu_0/c**2), abbrev=r'\epsilon_0')

eV = Unit(usimplify(qe*V), abbrev="eV")

#electron mass
m_e = Unit(kg,factor=9.10938356e-31, abbrev=r'm_e')

units = [m, g, s, A, K, J, N, W, Pa, Hz, eV, C, V]
all_units = []

# Prefixes of units like g, J, N etc get added using `prefix_unit`
# in the for loop, but the actual units have to be added manually.
all_units.extend([g, J, N, W, Pa, Hz, eV, C, V])

for u in units:
    all_units.extend(prefix_unit(u, PREFIXES, exclude=['kg']))

all_units.extend([v, a, p, G, c, boltzmann, h, hbar, qe])

# unit system
si = UnitSystem(base=(m, kg, s, A, K), units=all_units, name="SI")

for unit in all_units:
    setattr(sys.modules[__name__], unit.__repr__(), unit)