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

add fluid methods

parent 3a576374
No related branches found
No related tags found
1 merge request!27add fluid methods
......@@ -120,3 +120,26 @@ def isentropic_total_temperature(kappa, mach_number, temperature):
isentropic_total_temperature = temperature / (1 + (kappa - 1) / 2 * mach_number ** 2) ** -1
return isentropic_total_temperature
def speed_of_sound(*, gamma, R=None, p=None, rho=None, T=None):
"""Calculate the speed of sound based on the given equation.
https://www.grc.nasa.gov/www/BGH/isentrop.html
Args:
gamma (float): The specific heat ratio.
p (float): The pressure of the gas.
rho (float): The density of the gas.
R (float): The specific gas constant.
T (float): The temperature of the gas.
Returns:
float: The speed of sound.
"""
if not T and not R:
a = np.sqrt(gamma * p / rho)
elif not rho:
a = np.sqrt(gamma * R * T)
return a
import numpy as np
from ntrfc.fluid.fluid import total_pressure, mach_number, sutherland_viscosity, ma_is, isentropic_reynolds_number, \
isentropic_total_temperature
isentropic_total_temperature, speed_of_sound
def test_total_pressure():
......@@ -50,3 +50,12 @@ def test_isentropic_total_temperature():
expected_output = 315
output = isentropic_total_temperature(1.4, 0.5, 300)
assert abs(output - expected_output) < 1e-2
def test_speed_of_sound():
assert abs(speed_of_sound(gamma=1.4, p=101325, rho=1.225) - 340.29) < 0.01
assert abs(speed_of_sound(gamma=1.3, p=101325, rho=1.225) - 327.92) < 0.01
assert abs(speed_of_sound(gamma=1.4, p=80000, rho=1.225) - 302.37) < 0.01
assert abs(speed_of_sound(gamma=1.3, p=80000, rho=1.225) - 291.37) < 0.01
assert abs(speed_of_sound(gamma=1.4, R=287.05, T=288.15) - 340.29) < 0.01
assert abs(speed_of_sound(gamma=1.3, R=287.05, T=288.15) - 327.91) < 0.01
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