From 9874241bd85ab55742bad1740723796b97fc6883 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Mon, 10 Sep 2018 19:15:13 +1000 Subject: [PATCH] Add scaling_exponent() function --- scaling/froude.py | 17 +++++++++++++++++ tests/froude_test.py | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/scaling/froude.py b/scaling/froude.py index ba017b2..2091ae6 100644 --- a/scaling/froude.py +++ b/scaling/froude.py @@ -95,3 +95,20 @@ def dimensions(unit): s += '{}^{:g} '.format(symbol, exponent) 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 diff --git a/tests/froude_test.py b/tests/froude_test.py index de2b008..d5c713d 100644 --- a/tests/froude_test.py +++ b/tests/froude_test.py @@ -15,3 +15,8 @@ def test_unit_dimensions(): assert froude.dimensions('kg') == 'M^1' assert froude.dimensions('s') == 'T^1' 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