Skip to content
Snippets Groups Projects
Commit 0668d0fd authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

readable function names

parent 5310a825
No related branches found
No related tags found
1 merge request!59readable function names
...@@ -3,42 +3,42 @@ import numpy as np ...@@ -3,42 +3,42 @@ import numpy as np
from ntrfc.fluid.fluid import mach_number, total_pressure from ntrfc.fluid.fluid import mach_number, total_pressure
def p_t_is_from_mach(kappa, mach_number, static_pressure): def total_pressure_from_mach_number(kappa, mach_number, static_pressure):
# Calculates total pressure in isentropic flow # Calculates total pressure in isentropic flow
# Source: https://www.grc.nasa.gov/www/BGH/isentrop.html # Source: https://www.grc.nasa.gov/www/BGH/isentrop.html
total_pressure = static_pressure * pow(1.0 + (kappa - 1.0) / 2.0 * pow(mach_number, 2.0), (kappa / (kappa - 1.0))) total_pressure = static_pressure * pow(1.0 + (kappa - 1.0) / 2.0 * pow(mach_number, 2.0), (kappa / (kappa - 1.0)))
return total_pressure return total_pressure
def p_is_from_mach(kappa, ma, p_t_is): def static_pressure_from_mach_number(kappa, ma, p_t_is):
# Calculates static pressure in isentropic flow # Calculates static pressure in isentropic flow
# Source: https://www.grc.nasa.gov/www/BGH/isentrop.html # Source: https://www.grc.nasa.gov/www/BGH/isentrop.html
p_is = p_t_is / pow(1.0 + (kappa - 1.0) / 2.0 * pow(ma, 2.0), (kappa / (kappa - 1.0))) p_is = p_t_is / pow(1.0 + (kappa - 1.0) / 2.0 * pow(ma, 2.0), (kappa / (kappa - 1.0)))
return p_is return p_is
def temp_t_is(kappa, ma, T): def total_temperature_from_mach_number(kappa, ma, T):
# Calculates total temperature in isentropic flow # Calculates total temperature in isentropic flow
# Source: https://www.grc.nasa.gov/www/BGH/isentrop.html # Source: https://www.grc.nasa.gov/www/BGH/isentrop.html
T_t_is = T / (((1.0 + (kappa - 1.0) * 0.5 * ma ** 2.0)) ** (-1.0)) T_t_is = T / (((1.0 + (kappa - 1.0) * 0.5 * ma ** 2.0)) ** (-1.0))
return T_t_is return T_t_is
def temp_is(kappa, ma, Tt): def static_temperature_from_mach_number(kappa, ma, Tt):
# Calculates static temperature in isentropic flow # Calculates static temperature in isentropic flow
# Source: https://www.grc.nasa.gov/www/BGH/isentrop.html # Source: https://www.grc.nasa.gov/www/BGH/isentrop.html
T = Tt / (1 + ((kappa - 1) / 2.0) * ma ** 2) T = Tt / (1 + ((kappa - 1) / 2.0) * ma ** 2)
return T return T
def mach_is_x(kappa, p_blade, p_frestream): def local_isentropic_mach_number(kappa, p_blade, p_frestream):
# Calculates local isentropic Mach number # Calculates local isentropic Mach number
y = np.sqrt(2 / (kappa - 1) * ((p_frestream / p_blade) ** ((kappa - 1) / kappa) - 1)) y = np.sqrt(2 / (kappa - 1) * ((p_frestream / p_blade) ** ((kappa - 1) / kappa) - 1))
return y return y
def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, gas_constant, static_temperature): def calculate_isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, gas_constant, static_temperature):
""" """
Calculates the isentropic Mach number. Calculates the isentropic Mach number.
...@@ -55,8 +55,8 @@ def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, ga ...@@ -55,8 +55,8 @@ def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, ga
""" """
# Calculate the total pressure # Calculate the total pressure
total_pressure = p_t_is_from_mach(kappa, mach_number(mach, kappa, gas_constant, static_temperature), total_pressure = total_pressure_from_mach_number(kappa, mach_number(mach, kappa, gas_constant, static_temperature),
static_pressure) static_pressure)
# Calculate the dynamic pressure # Calculate the dynamic pressure
dynamic_pressure = total_pressure - isentropic_pressure dynamic_pressure = total_pressure - isentropic_pressure
...@@ -68,34 +68,10 @@ def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, ga ...@@ -68,34 +68,10 @@ def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, ga
return isentropic_mach_number return isentropic_mach_number
def ma_is(outflow_static_pressure, isentropic_exponent, pressure, velocity, gas_constant, temperature):
"""
Calculate the isentropic Mach number at the outflow of a system.
Parameters:
outflow_static_pressure (float): static pressure at the outflow (Pa)
isentropic_exponent (float): isentropic exponent of the gas
pressure (float): pressure at a reference point in the flow (Pa)
density (float): density at the reference point (kg/m^3)
velocity (float): velocity at the reference point (m/s)
gas_constant (float): gas constant of the gas (J/kg*K)
temperature (float): temperature at the reference point (K)
Returns:
float: isentropic Mach number at the outflow
"""
reference_point_total_pressure = total_pressure(isentropic_exponent,
mach_number(velocity, isentropic_exponent, gas_constant,
temperature), pressure)
q2th = reference_point_total_pressure - outflow_static_pressure
isentropic_mach_number = np.sqrt(2.0 / (isentropic_exponent - 1.0) * (
pow(1.0 + (q2th / outflow_static_pressure), (isentropic_exponent - 1.0) / isentropic_exponent) - 1.0))
return isentropic_mach_number
def isentropic_reynolds_number(kappa, specific_gas_constant, chord_length, sutherland_reference_viscosity, def calculate_isentropic_reynolds_number(kappa, specific_gas_constant, chord_length, sutherland_reference_viscosity,
mach_number, pressure, temperature, mach_number, pressure, temperature,
sutherland_reference_temperature): sutherland_reference_temperature):
""" """
Calculates the isentropic Reynolds number at a point in a gas flow. Calculates the isentropic Reynolds number at a point in a gas flow.
...@@ -114,14 +90,14 @@ def isentropic_reynolds_number(kappa, specific_gas_constant, chord_length, suthe ...@@ -114,14 +90,14 @@ def isentropic_reynolds_number(kappa, specific_gas_constant, chord_length, suthe
Returns: Returns:
- the isentropic Reynolds number at the point - the isentropic Reynolds number at the point
""" """
total_temperature = isentropic_total_temperature(kappa, mach_number, temperature) total_temperature = calculate_isentropic_total_temperature(kappa, mach_number, temperature)
iso_temperature = total_temperature / (1 + (kappa - 1) / 2 * mach_number ** 2) iso_temperature = total_temperature / (1 + (kappa - 1) / 2 * mach_number ** 2)
y = (kappa / specific_gas_constant) ** 0.5 * chord_length / sutherland_reference_viscosity * ( y = (kappa / specific_gas_constant) ** 0.5 * chord_length / sutherland_reference_viscosity * (
mach_number * pressure * (iso_temperature + sutherland_reference_temperature) / iso_temperature ** 2) mach_number * pressure * (iso_temperature + sutherland_reference_temperature) / iso_temperature ** 2)
return y return y
def isentropic_total_temperature(kappa, mach_number, temperature): def calculate_isentropic_total_temperature(kappa, mach_number, temperature):
""" """
Calculates the isentropic total temperature at a point in a gas. Calculates the isentropic total temperature at a point in a gas.
......
...@@ -3,7 +3,7 @@ import tempfile ...@@ -3,7 +3,7 @@ import tempfile
import numpy as np import numpy as np
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from ntrfc.fluid.isentropic import mach_is_x from ntrfc.fluid.isentropic import local_isentropic_mach_number
from ntrfc.geometry.plane import massflowave_plane from ntrfc.geometry.plane import massflowave_plane
from ntrfc.math.vectorcalc import vecAbs, vecAngle from ntrfc.math.vectorcalc import vecAbs, vecAngle
from ntrfc.turbo.bladeloading import calc_inflow_cp from ntrfc.turbo.bladeloading import calc_inflow_cp
...@@ -107,7 +107,7 @@ def blade_loading_mais(case_instance, pressurevar="pMean", densityvar="rhoMean", ...@@ -107,7 +107,7 @@ def blade_loading_mais(case_instance, pressurevar="pMean", densityvar="rhoMean",
for idx, pts1 in enumerate(psmeshpoints.points): for idx, pts1 in enumerate(psmeshpoints.points):
ps_xc[idx] = pts1[0] / camber_length ps_xc[idx] = pts1[0] / camber_length
bladepressure = psmeshpoints.point_data[pressurevar][idx] bladepressure = psmeshpoints.point_data[pressurevar][idx]
ps_cp[idx] = mach_is_x(kappa, bladepressure, totalpressure_inlet) ps_cp[idx] = local_isentropic_mach_number(kappa, bladepressure, totalpressure_inlet)
ss_xc = np.zeros(ssmeshpoints.number_of_points) ss_xc = np.zeros(ssmeshpoints.number_of_points)
ss_cp = np.zeros(ssmeshpoints.number_of_points) ss_cp = np.zeros(ssmeshpoints.number_of_points)
...@@ -115,7 +115,7 @@ def blade_loading_mais(case_instance, pressurevar="pMean", densityvar="rhoMean", ...@@ -115,7 +115,7 @@ def blade_loading_mais(case_instance, pressurevar="pMean", densityvar="rhoMean",
for idx, pts1 in enumerate(ssmeshpoints.points): for idx, pts1 in enumerate(ssmeshpoints.points):
ss_xc[idx] = pts1[0] / camber_length ss_xc[idx] = pts1[0] / camber_length
bladepressure = ssmeshpoints.point_data[pressurevar][idx] bladepressure = ssmeshpoints.point_data[pressurevar][idx]
ss_cp[idx] = mach_is_x(kappa, bladepressure, totalpressure_inlet) ss_cp[idx] = local_isentropic_mach_number(kappa, bladepressure, totalpressure_inlet)
plt.figure() plt.figure()
plt.title("blade loading") plt.title("blade loading")
......
...@@ -29,27 +29,18 @@ def test_sutherland_viscosity(): ...@@ -29,27 +29,18 @@ def test_sutherland_viscosity():
assert np.isclose(dynamic_viscosity, expected_dynamic_viscosity, rtol=1e-10, atol=1e-10) assert np.isclose(dynamic_viscosity, expected_dynamic_viscosity, rtol=1e-10, atol=1e-10)
def test_ma_is():
from ntrfc.fluid.isentropic import ma_is
# Test input where outflow_static_pressure = 100, isentropic_exponent = 1.4, pressure = 50, velocity = 20,
# gas_constant = 287, temperature = 300
expected_output = 1.71
output = ma_is(10000, 1.4, 50000, 20, 287, 300)
assert abs(output - expected_output) < 1e-2
def test_isentropic_reynolds_number(): def test_isentropic_reynolds_number():
from ntrfc.fluid.isentropic import isentropic_reynolds_number from ntrfc.fluid.isentropic import calculate_isentropic_reynolds_number
# Test input where kappa = 1.4, specific_gas_constant = 287, chord_length = 1, sutherland_reference_viscosity = 1.46e-5, # Test input where kappa = 1.4, specific_gas_constant = 287, chord_length = 1, sutherland_reference_viscosity = 1.46e-5,
# mach_number = 0.65, pressure = 50, temperature = 300, sutherland_reference_temperature = 110.4 # mach_number = 0.65, pressure = 50, temperature = 300, sutherland_reference_temperature = 110.4
expected_output = 708.95 expected_output = 708.95
output = isentropic_reynolds_number(1.4, 287, 1, 1.46e-5, 0.65, 50, 300, 110.4) output = calculate_isentropic_reynolds_number(1.4, 287, 1, 1.46e-5, 0.65, 50, 300, 110.4)
assert abs(output - expected_output) < 1e-2 assert abs(output - expected_output) < 1e-2
def test_isentropic_total_temperature(): def test_isentropic_total_temperature():
from ntrfc.fluid.isentropic import isentropic_total_temperature from ntrfc.fluid.isentropic import calculate_isentropic_total_temperature
# Test input where kappa = 1.4, mach_number = 0.5, temperature = 300 # Test input where kappa = 1.4, mach_number = 0.5, temperature = 300
expected_output = 315 expected_output = 315
output = isentropic_total_temperature(1.4, 0.5, 300) output = calculate_isentropic_total_temperature(1.4, 0.5, 300)
assert abs(output - expected_output) < 1e-2 assert abs(output - expected_output) < 1e-2
import numpy as np import numpy as np
def test_p_t_is_from_mach(): def test_total_pressure_from_mach_number():
from ntrfc.fluid.isentropic import p_t_is_from_mach from ntrfc.fluid.isentropic import total_pressure_from_mach_number
# Test with some sample inputs # Test with some sample inputs
kappa = 1.4 kappa = 1.4
ma = 2 ma = 2
...@@ -12,49 +12,49 @@ def test_p_t_is_from_mach(): ...@@ -12,49 +12,49 @@ def test_p_t_is_from_mach():
expected = 782444.9066867264 expected = 782444.9066867264
# Calculate actual result # Calculate actual result
actual = p_t_is_from_mach(kappa, ma, p) actual = total_pressure_from_mach_number(kappa, ma, p)
# Check if actual result matches expected result # Check if actual result matches expected result
assert np.isclose(expected, actual) assert np.isclose(expected, actual)
def test_p_is_from_mach(): def test_static_pressure_from_mach_number():
from ntrfc.fluid.isentropic import p_is_from_mach from ntrfc.fluid.isentropic import static_pressure_from_mach_number
# Test using standard values for air at sea level # Test using standard values for air at sea level
kappa = 1.4 kappa = 1.4
mach_number = 0.8 mach_number = 0.8
total_pressure = 101325.0 # Pa total_pressure = 101325.0 # Pa
expected_static_pressure = 66471.39048022314 # Pa expected_static_pressure = 66471.39048022314 # Pa
calculated_static_pressure = p_is_from_mach(kappa, mach_number, total_pressure) calculated_static_pressure = static_pressure_from_mach_number(kappa, mach_number, total_pressure)
assert np.isclose(calculated_static_pressure, expected_static_pressure) assert np.isclose(calculated_static_pressure, expected_static_pressure)
def test_temp_t_is(): def test_total_temperature_from_mach_number():
from ntrfc.fluid.isentropic import temp_t_is from ntrfc.fluid.isentropic import total_temperature_from_mach_number
assert np.isclose(temp_t_is(1.4, 0, 300), 300) assert np.isclose(total_temperature_from_mach_number(1.4, 0, 300), 300)
assert np.isclose(temp_t_is(1.4, 1.0, 300), 360.0) assert np.isclose(total_temperature_from_mach_number(1.4, 1.0, 300), 360.0)
assert np.isclose(temp_t_is(1.4, 1.5, 300), 435) assert np.isclose(total_temperature_from_mach_number(1.4, 1.5, 300), 435)
def test_temp_is(): def test_static_temperature_from_mach_number():
from ntrfc.fluid.isentropic import temp_is from ntrfc.fluid.isentropic import static_temperature_from_mach_number
assert np.isclose(temp_is(1.4, 0, 340.952), 340.952) assert np.isclose(static_temperature_from_mach_number(1.4, 0, 340.952), 340.952)
assert np.isclose(temp_is(1.4, 1.0, 438.298), 365.24833333333333) assert np.isclose(static_temperature_from_mach_number(1.4, 1.0, 438.298), 365.24833333333333)
assert np.isclose(temp_is(1.4, 1.5, 578.947), 399.27379310344827) assert np.isclose(static_temperature_from_mach_number(1.4, 1.5, 578.947), 399.27379310344827)
def test_mach_is_x(): def test_local_isentropic_mach_number():
from ntrfc.fluid.isentropic import mach_is_x from ntrfc.fluid.isentropic import local_isentropic_mach_number
kappa = 1.4 kappa = 1.4
p = 100000.0 p = 100000.0
pt = 189292.91587378542 pt = 189292.91587378542
expected_mach = 1 expected_mach = 1
mach = mach_is_x(kappa, p, pt) mach = local_isentropic_mach_number(kappa, p, pt)
assert np.isclose(mach, expected_mach) assert np.isclose(mach, expected_mach)
def test_isentropic_mach_number(): def test_calculate_isentropic_mach_number():
from ntrfc.fluid.isentropic import isentropic_mach_number from ntrfc.fluid.isentropic import calculate_isentropic_mach_number
# Standard conditions # Standard conditions
isentropic_pressure = 101325 # Pa isentropic_pressure = 101325 # Pa
kappa = 1.4 kappa = 1.4
...@@ -66,5 +66,5 @@ def test_isentropic_mach_number(): ...@@ -66,5 +66,5 @@ def test_isentropic_mach_number():
expected_output = 0.0014693046301270448 expected_output = 0.0014693046301270448
# Call function and check output # Call function and check output
assert np.isclose(isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach_number, gas_constant, assert np.isclose(calculate_isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach_number, gas_constant,
static_temperature), expected_output) static_temperature), expected_output)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment