You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I've discovered that I cannot get area units to be simplified correctly. All the print results of the equations below should be identical. Is there anything I'm doing wrong with the custom area unit that I'm not aware of perhaps? Or is there an alternative way of natively handling area units? Much appreciated.
Conclusion:
f1 is simplified to kilonewtons correctly. However, my basic input unit should be mm^2 and not two inputs with mm unit each.
f2 and f3 are not simplified correctly due to the custom area unit mm2. The units mm2 are retained.
Below is an example of equations that are identical apart from the units being assigned:
f1 = custom scaled Pa unit multiplied with two variables having a basic unit mm assigned
f2 = custom scaled Pa unit multiplied by the custom area unit
f3 = basic canonical unit Pa multiplied by the custom area unit
The script is returning
f_simplified1: 9443.0*megapascal*millimeter**2
converted_value1: 9.443*kilonewton
f_simplified2: 9443.0*megapascal*square_millimeter
converted_value2: 9443000.0*kilonewton*millimeter**2
f_simplified3: 9443000000*pascal*square_millimeter
converted_value3: 9443000*kilonewton*millimeter**2
from sympy.physics.units import *
from sympy import *
kN = kilonewton = Quantity("kilonewton", abbrev="kN")
kilonewton.set_global_relative_scale_factor(kilo, newton)
MPa = megapascal = Quantity("megapascal", abbrev="MPa")
megapascal.set_global_relative_scale_factor(mega, Pa)
mm2 = square_millimeter = Quantity("square_millimeter", abbrev="mm * mm")
square_millimeter.set_global_relative_scale_factor(millimeter**2, meter**2)
# Given values
n = 1 # dimensionless
f_pj1 = 7.1 * MPa
f_pj2 = 7.1 * MPa
f_pj3 = 7100000 * Pa
A_w1 = 1330 * mm
A_s1 = 1 * mm
A_w2 = 1330 * mm2
A_w3 = 1330 * mm2
# Calculating the result
f1 = n * f_pj1 * A_w1 * A_s1
f2 = n * f_pj2 * A_w2
f3 = n * f_pj3 * A_w3
# Simplifying the result
f_simplified1 = simplify(f1)
f_simplified2 = simplify(f2)
f_simplified3 = simplify(f3)
converted_value1 = convert_to(f_simplified1, kilonewton)
converted_value2 = convert_to(f_simplified2, kilonewton)
converted_value3 = convert_to(f_simplified3, kilonewton)
print(f'f_simplified1: {f_simplified1}')
print(f'converted_value1: {converted_value1}')
print(f'f_simplified2: {f_simplified2}')
print(f'converted_value2: {converted_value2}')
print(f'f_simplified3: {f_simplified3}')
print(f'converted_value3: {converted_value3}')
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Recently I've discovered that I cannot get area units to be simplified correctly. All the print results of the equations below should be identical. Is there anything I'm doing wrong with the custom area unit that I'm not aware of perhaps? Or is there an alternative way of natively handling area units? Much appreciated.
Conclusion:
Below is an example of equations that are identical apart from the units being assigned:
Beta Was this translation helpful? Give feedback.
All reactions