Add scaling_exponent() function

master
Dan Howe 6 years ago
parent 5b62568883
commit 9874241bd8

@ -95,3 +95,20 @@ def dimensions(unit):
s += '{}^{:g} '.format(symbol, exponent) s += '{}^{:g} '.format(symbol, exponent)
return s.strip() return s.strip()
def scaling_exponent(unit):
"""Convert prototype value(s) to model value(s) in specified units.
Args:
unit (str): unit of quantity to be scaled
Returns:
scaling factor
"""
# Calculate Froude scaling factor
scaling_exponent = (UREG(unit).dimensionality['[length]'] * LENGTH_EXPONENT
+ UREG(unit).dimensionality['[time]'] * TIME_EXPONENT +
UREG(unit).dimensionality['[mass]'] * MASS_EXPONENT)
return scaling_exponent

@ -15,3 +15,8 @@ def test_unit_dimensions():
assert froude.dimensions('kg') == 'M^1' assert froude.dimensions('kg') == 'M^1'
assert froude.dimensions('s') == 'T^1' assert froude.dimensions('s') == 'T^1'
assert froude.dimensions('N') == 'L^1 M^1 T^-2' assert froude.dimensions('N') == 'L^1 M^1 T^-2'
def test_scaling_exponent():
assert froude.scaling_exponent('m') == 1
assert froude.scaling_exponent('kg') == 3
assert froude.scaling_exponent('s') == 0.5

Loading…
Cancel
Save