diff --git a/ntrfc/fluid/isentropic.py b/ntrfc/fluid/isentropic.py index c089562ca1172f9b5283e036ea0f177d741cdcfe..2b6a0ee424b594a73a188e6ffdb36ca8fabc5832 100644 --- a/ntrfc/fluid/isentropic.py +++ b/ntrfc/fluid/isentropic.py @@ -3,42 +3,42 @@ import numpy as np 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 # 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))) 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 # 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))) 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 # 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)) 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 # Source: https://www.grc.nasa.gov/www/BGH/isentrop.html T = Tt / (1 + ((kappa - 1) / 2.0) * ma ** 2) 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 y = np.sqrt(2 / (kappa - 1) * ((p_frestream / p_blade) ** ((kappa - 1) / kappa) - 1)) 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. @@ -55,8 +55,8 @@ def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, ga """ # Calculate the total pressure - total_pressure = p_t_is_from_mach(kappa, mach_number(mach, kappa, gas_constant, static_temperature), - static_pressure) + total_pressure = total_pressure_from_mach_number(kappa, mach_number(mach, kappa, gas_constant, static_temperature), + static_pressure) # Calculate the dynamic pressure dynamic_pressure = total_pressure - isentropic_pressure @@ -68,34 +68,10 @@ def isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach, ga 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, - mach_number, pressure, temperature, - sutherland_reference_temperature): +def calculate_isentropic_reynolds_number(kappa, specific_gas_constant, chord_length, sutherland_reference_viscosity, + mach_number, pressure, temperature, + sutherland_reference_temperature): """ 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 Returns: - 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) y = (kappa / specific_gas_constant) ** 0.5 * chord_length / sutherland_reference_viscosity * ( mach_number * pressure * (iso_temperature + sutherland_reference_temperature) / iso_temperature ** 2) 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. diff --git a/ntrfc/turbo/cascade_case/post.py b/ntrfc/turbo/cascade_case/post.py index 4094a490606a4a4c0f61d483490c341d60ddb4bc..49a1b44713dceae16ccdf99471f7a18f0b9b8fe2 100644 --- a/ntrfc/turbo/cascade_case/post.py +++ b/ntrfc/turbo/cascade_case/post.py @@ -3,7 +3,7 @@ import tempfile import numpy as np 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.math.vectorcalc import vecAbs, vecAngle from ntrfc.turbo.bladeloading import calc_inflow_cp @@ -107,7 +107,7 @@ def blade_loading_mais(case_instance, pressurevar="pMean", densityvar="rhoMean", for idx, pts1 in enumerate(psmeshpoints.points): ps_xc[idx] = pts1[0] / camber_length 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_cp = np.zeros(ssmeshpoints.number_of_points) @@ -115,7 +115,7 @@ def blade_loading_mais(case_instance, pressurevar="pMean", densityvar="rhoMean", for idx, pts1 in enumerate(ssmeshpoints.points): ss_xc[idx] = pts1[0] / camber_length 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.title("blade loading") diff --git a/tests/fluid/test_ntrfc_fluid.py b/tests/fluid/test_ntrfc_fluid.py index 121c51318edc97dbed1f2b6cc33c684452398bb6..8c79551290d34327bc62a132c1d9398c063378ca 100644 --- a/tests/fluid/test_ntrfc_fluid.py +++ b/tests/fluid/test_ntrfc_fluid.py @@ -29,27 +29,18 @@ def test_sutherland_viscosity(): 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(): - 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, # mach_number = 0.65, pressure = 50, temperature = 300, sutherland_reference_temperature = 110.4 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 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 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 diff --git a/tests/fluid/test_ntrfc_isentropic.py b/tests/fluid/test_ntrfc_isentropic.py index 8bf62737ad36262ee5e6d3accd89677b22a91832..4f4f6d32f290e797b21bfa32b618ca8dc85ccdc6 100644 --- a/tests/fluid/test_ntrfc_isentropic.py +++ b/tests/fluid/test_ntrfc_isentropic.py @@ -1,8 +1,8 @@ import numpy as np -def test_p_t_is_from_mach(): - from ntrfc.fluid.isentropic import p_t_is_from_mach +def test_total_pressure_from_mach_number(): + from ntrfc.fluid.isentropic import total_pressure_from_mach_number # Test with some sample inputs kappa = 1.4 ma = 2 @@ -12,49 +12,49 @@ def test_p_t_is_from_mach(): expected = 782444.9066867264 # 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 assert np.isclose(expected, actual) -def test_p_is_from_mach(): - from ntrfc.fluid.isentropic import p_is_from_mach +def test_static_pressure_from_mach_number(): + from ntrfc.fluid.isentropic import static_pressure_from_mach_number # Test using standard values for air at sea level kappa = 1.4 mach_number = 0.8 total_pressure = 101325.0 # 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) -def test_temp_t_is(): - from ntrfc.fluid.isentropic import temp_t_is - assert np.isclose(temp_t_is(1.4, 0, 300), 300) - assert np.isclose(temp_t_is(1.4, 1.0, 300), 360.0) - assert np.isclose(temp_t_is(1.4, 1.5, 300), 435) +def test_total_temperature_from_mach_number(): + from ntrfc.fluid.isentropic import total_temperature_from_mach_number + assert np.isclose(total_temperature_from_mach_number(1.4, 0, 300), 300) + assert np.isclose(total_temperature_from_mach_number(1.4, 1.0, 300), 360.0) + assert np.isclose(total_temperature_from_mach_number(1.4, 1.5, 300), 435) -def test_temp_is(): - from ntrfc.fluid.isentropic import temp_is - assert np.isclose(temp_is(1.4, 0, 340.952), 340.952) - assert np.isclose(temp_is(1.4, 1.0, 438.298), 365.24833333333333) - assert np.isclose(temp_is(1.4, 1.5, 578.947), 399.27379310344827) +def test_static_temperature_from_mach_number(): + from ntrfc.fluid.isentropic import static_temperature_from_mach_number + assert np.isclose(static_temperature_from_mach_number(1.4, 0, 340.952), 340.952) + assert np.isclose(static_temperature_from_mach_number(1.4, 1.0, 438.298), 365.24833333333333) + assert np.isclose(static_temperature_from_mach_number(1.4, 1.5, 578.947), 399.27379310344827) -def test_mach_is_x(): - from ntrfc.fluid.isentropic import mach_is_x +def test_local_isentropic_mach_number(): + from ntrfc.fluid.isentropic import local_isentropic_mach_number kappa = 1.4 p = 100000.0 pt = 189292.91587378542 expected_mach = 1 - mach = mach_is_x(kappa, p, pt) + mach = local_isentropic_mach_number(kappa, p, pt) assert np.isclose(mach, expected_mach) -def test_isentropic_mach_number(): - from ntrfc.fluid.isentropic import isentropic_mach_number +def test_calculate_isentropic_mach_number(): + from ntrfc.fluid.isentropic import calculate_isentropic_mach_number # Standard conditions isentropic_pressure = 101325 # Pa kappa = 1.4 @@ -66,5 +66,5 @@ def test_isentropic_mach_number(): expected_output = 0.0014693046301270448 # Call function and check output - assert np.isclose(isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach_number, gas_constant, - static_temperature), expected_output) + assert np.isclose(calculate_isentropic_mach_number(isentropic_pressure, kappa, static_pressure, mach_number, gas_constant, + static_temperature), expected_output)