def m_from_critical_entropy(ep, flag="sub", gamma=1.4): """ Compute the Mach number given Fanno's Critical Entropy Parameter (s*-s)/R. Parameters ---------- ep : array_like Fanno's Critical Entropy Parameter (s*-s)/R. If float, list, tuple is given as input, a conversion will be attempted. Must be (s* - s) / R >= 0. flag : string Can be either 'sub' (subsonic) or 'super' (supersonic). Default to 'sub'. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Mach Number. """ if np.any(ep < 0): raise ValueError("It must be (s* - s) / R >= 0.") # func = lambda M, r: r - Critical_Entropy_Parameter.__no_check(M, gamma) func = lambda M, r: r - np.log((1 / M) * ((1 + ((gamma - 1) / 2) * M**2) / (1 + ((gamma - 1) / 2)))**((gamma + 1) / (2 * (gamma - 1)))) return apply_bisection(ep, func, flag=flag)
def m_from_prandtl_meyer_angle(angle, gamma=1.4): """ Compute the Mach number given the Prandtl Meyer angle. Parameters ---------- angle : array_like Prandtl Meyer angle [degrees]. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- M : array_like Mach Number. """ nu_max = (np.sqrt((gamma + 1) / (gamma - 1)) - 1) * 90 assert np.all(angle >= 0) and np.all( angle <= nu_max ), "Prandtl-Meyer angle must be between 0 and {}".format(nu_max) angle = np.deg2rad(angle) func = lambda M, a: a - (np.sqrt((gamma + 1) / (gamma - 1)) * np.arctan( np.sqrt((gamma - 1) / (gamma + 1) * (M**2 - 1))) - np.arctan(np.sqrt(M**2 - 1))) return apply_bisection(angle, func, flag="sup")
def m_from_critical_total_pressure_ratio(ratio, flag="sub", gamma=1.4): """ Compute the Mach number given Fanno's Critical Total Pressure Ratio P0/P0*. Parameters ---------- ratio : array_like Fanno's Critical Total Pressure Ratio P0/P0*. If float, list, tuple is given as input, a conversion will be attempted. Must be P0/P0* > 1. flag : string Can be either 'sub' (subsonic) or 'super' (supersonic). Default to 'sub'. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Mach Number. """ if np.any(ratio < 1): raise ValueError("It must be P/P* > 1.") # func = lambda M, r: r - Critical_Total_Pressure_Ratio.__no_check(M, gamma) func = lambda M, r: r - (1 / M) * ((1 + ((gamma - 1) / 2) * M**2) / ((gamma + 1) / 2))**((gamma + 1) / (2 * (gamma - 1))) return apply_bisection(ratio, func, flag=flag)
def m_from_critical_area_ratio(ratio, flag="sub", gamma=1.4): """ Compute the Mach number given the Isentropic Critical Area Ratio A/A*. Parameters ---------- ratio : array_like Isentropic Critical Area Ratio A/A*. If float, list, tuple is given as input, a conversion will be attempted. Must be A/A* >= 1. flag : string Can be either 'sub' (subsonic) or 'sup' (supersonic). Default to 'sub'. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Mach Number. """ assert np.all(ratio >= 1), "Area ratio must be A/A* >= 1." func = lambda M, r: r - (((1 + (gamma - 1) / 2 * M**2) / ( (gamma + 1) / 2))**((gamma + 1) / (2 * (gamma - 1)))) / M # func = lambda M, r: r - Critical_Area_Ratio.__no_check(M, gamma) return apply_bisection(ratio, func, flag=flag)
def m_from_critical_entropy(ratio, flag="sub", gamma=1.4): """ Compute the Mach number given Rayleigh's Critical Entropy (s*-s)/R. Parameters ---------- ratio : array_like Rayleigh's Critical Critical Entropy (s*-s)/R. If float, list, tuple is given as input, a conversion will be attempted. Must be (s*-s)/R >= 0. flag : string Can be either 'sub' (subsonic) or 'super' (supersonic). Default to 'sub'. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Mach Number. """ assert np.all(ratio >= 0), "It must be (s*-s)/R >= 0." # func = lambda M, r: r - Critical_Entropy_Parameter.__no_check(M, gamma) func = lambda M, r: r - (-gamma / (gamma - 1) * np.log(M**2 * ( (gamma + 1) / (1 + gamma * M**2))**((gamma + 1) / gamma))) # TODO: need to adjust the extreme of the range where to apply bisection. # If I try M_From_Critical_Entropy(1000) I get: # ValueError: f(a) and f(b) must have different signs return apply_bisection(ratio, func, flag=flag)
def m_from_critical_total_pressure_ratio(ratio, flag="sub", gamma=1.4): """ Compute the Mach number given Rayleigh's Critical Total Pressure Ratio P0/P0*. Parameters ---------- ratio : array_like Rayleigh's Critical Total Pressure Ratio P0/P0*. If float, list, tuple is given as input, a conversion will be attempted. If flag='sub', it must be 1 <= P0/P0* < P0/P0*(M=0). Else, P0/P0* >= 1. flag : string Can be either 'sub' (subsonic) or 'super' (supersonic). Default to 'sub'. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Mach Number. """ if flag == "sub": upper_lim = critical_total_pressure_ratio(0, gamma) assert np.all(ratio >= 1) and np.all( ratio < upper_lim), "It must be 1 <= P0/P0* < {}".format(upper_lim) else: assert np.all(ratio >= 1), "It must be P0/P0* >= 1" # func = lambda M, r: r - Critical_Total_Pressure_Ratio.__no_check(M, gamma) func = lambda M, r: r - (1 + gamma) / (1 + gamma * M**2) * ( (1 + (gamma - 1) / 2 * M**2) / ((gamma + 1) / 2))**(gamma / (gamma - 1)) return apply_bisection(ratio, func, flag=flag)
def m1_from_total_pressure_ratio(ratio, gamma=1.4): """ Compute M1 from the total pressure ratio. Parameters ---------- ratio : array_like Total Pressure Ratio. If float, list, tuple is given as input, a conversion will be attempted. Must be 0 <= P02/P01 <= 1. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Upstream Mach number M1. """ assert np.all(ratio >= 0) and np.all(ratio <= 1), ( "The total pressure ratio must be " + "0 <= P02/P01 <= 1") func = lambda M1, r: r - ( (gamma + 1) * M1**2 / (2 + (gamma - 1) * M1**2))**(gamma / (gamma - 1)) * ( (gamma + 1) / (2 * gamma * M1**2 - gamma + 1))**(1 / (gamma - 1)) return apply_bisection(ratio, func, "sup")
def m_from_critical_friction(fp, flag="sub", gamma=1.4): """ Compute the Mach number given Fanno's Critical Friction Parameter 4fL*/D. Parameters ---------- fp : array_like Fanno's Critical Friction Parameter 4fL*/D. If float, list, tuple is given as input, a conversion will be attempted. If flag="sub", it must be fp >= 0. Else, 0 <= fp <= ((gamma + 1) * np.log((gamma + 1) / (gamma - 1)) - 2) / (2 * gamma) flag : string Can be either 'sub' (subsonic) or 'super' (supersonic). Default to 'sub'. gamma : float Specific heats ratio. Default to 1.4. Must be > 1. Returns ------- out : ndarray Mach Number. """ if flag == "sub": assert np.all(fp >= 0), 'It must be fp >= 0.' else: upper_lim = ((gamma + 1) * np.log( (gamma + 1) / (gamma - 1)) - 2) / (2 * gamma) print(upper_lim) assert np.all(fp >= 0) and np.all( fp <= upper_lim), 'It must be 0 <= fp <= {}'.format(upper_lim) # TODO: when solving the supersonic case, and ratio -> upper limit, # I get: ValueError: f(a) and f(b) must have different signs # need to be dealt with! # func = lambda M, r: r - Critical_Friction_Parameter.__no_check(M, gamma) func = lambda M, r: r - (((gamma + 1) / (2 * gamma)) * np.log( ((gamma + 1) / 2) * M**2 / (1 + ((gamma - 1) / 2) * M**2)) + (1 / gamma) * (1 / M**2 - 1)) return apply_bisection(fp, func, flag=flag)